diff --git a/owncloud/owncloud.py b/owncloud/owncloud.py index 3c92f43..4a02e29 100644 --- a/owncloud/owncloud.py +++ b/owncloud/owncloud.py @@ -218,12 +218,16 @@ def login(self, user_id, password): self.__session.verify = self.__verify_certs self.__session.auth = (user_id, password) # TODO: use another path to prevent that the server renders the file list page - res = self.__session.get(self.url + 'index.php') + res = self.__session.get(self.url + 'status.php') if res.status_code == 200: - if self.__single_session: - # Keep the same session, no need to re-auth every call - self.__session.auth = None - return + res = self.__make_ocs_request( + 'GET', + self.OCS_SERVICE_CLOUD, + 'capabilities' + ) + if res.status_code == 200: + return + raise HTTPResponseError(res) self.__session.close() self.__session = None raise HTTPResponseError(res) diff --git a/owncloud/test/test.py b/owncloud/test/test.py index 1affd33..8f4350b 100644 --- a/owncloud/test/test.py +++ b/owncloud/test/test.py @@ -911,6 +911,19 @@ def test_get_config(self): """Test get_config() function""" self.assertIsNotNone(self.client.get_config()) + def tearDown(self): + self.client.logout() + +class TestLogin(unittest.TestCase): + def setUp(self): + self.client = owncloud.Client(Config['owncloud_url']) + + def test_login(self): + with self.assertRaises(owncloud.HTTPResponseError) as e: + self.client.login("iGuessThisUserNameDoesNotExistInTheSystem","iGuessThisUserNameDoesNotExistInTheSystem") + self.assertEquals(e.exception.status_code, 401) + self.client.login(Config['owncloud_login'], Config['owncloud_password']) + def tearDown(self): self.client.logout()