diff --git a/CHANGELOG.md b/CHANGELOG.md index 3a94f624..2f13fc62 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ # Change Log +## [0.8.2] - 2018-01-24 + +### Bugfixes + +- Fixed an issue where editing and deleting user logins would use incorrect IDs. + ## [0.8.1] - 2018-01-23 ### General diff --git a/canvasapi/__init__.py b/canvasapi/__init__.py index b17888a4..a86739d7 100644 --- a/canvasapi/__init__.py +++ b/canvasapi/__init__.py @@ -6,4 +6,4 @@ __all__ = ["Canvas"] -__version__ = '0.8.1' +__version__ = '0.8.2' diff --git a/canvasapi/login.py b/canvasapi/login.py index 68944a20..48988963 100644 --- a/canvasapi/login.py +++ b/canvasapi/login.py @@ -23,7 +23,7 @@ def delete(self): """ response = self._requester.request( 'DELETE', - 'users/{}/logins/{}'.format(self.id, self.unique_id) + 'users/{}/logins/{}'.format(self.user_id, self.id) ) return Login(self._requester, response.json()) @@ -38,7 +38,7 @@ def edit(self, **kwargs): """ response = self._requester.request( 'PUT', - 'accounts/{}/logins/{}'.format(self.id, self.unique_id), + 'accounts/{}/logins/{}'.format(self.account_id, self.id), _kwargs=combine_kwargs(**kwargs) ) return Login(self._requester, response.json()) diff --git a/tests/fixtures/account.json b/tests/fixtures/account.json index 8ee40129..bf80693b 100644 --- a/tests/fixtures/account.json +++ b/tests/fixtures/account.json @@ -739,15 +739,6 @@ ], "status_code": 200 }, - "create_user_login": { - "method": "POST", - "endpoint": "accounts/1/logins", - "data": { - "id": 123, - "unique_id": 112233 - }, - "status_code": 200 - }, "get_department_level_participation_data_with_given_term": { "method": "GET", "endpoint": "accounts/1/analytics/terms/1/activity", diff --git a/tests/fixtures/login.json b/tests/fixtures/login.json index b0959f4a..3e572bd8 100644 --- a/tests/fixtures/login.json +++ b/tests/fixtures/login.json @@ -3,8 +3,10 @@ "method": "POST", "endpoint": "accounts/1/logins", "data": { - "id": 123, - "unique_id": 112233 + "account_id": 1, + "id": 101, + "unique_id": "belieber@example.com", + "user_id": 1 }, "status_code": 200 }, @@ -14,30 +16,27 @@ "data": [ { "account_id": 1, - "id": 2, - "sis_user_id": null, + "id": 101, "unique_id": "belieber@example.com", - "user_id": 2, - "authentication_provider_id": 1, - "authentication_provider_type": "facebook" + "user_id": 1 } ], "headers": { - "Link": "; rel=\"next\"" + "Link": "; rel=\"next\"" }, "status_code": 200 }, "list_user_logins_2": { "method": "GET", - "endpoint": "accounts/1/logins/?page=2&per_page=2", + "endpoint": "accounts/1/logins/?page=2&per_page=1", "data": [ { - "account_id": 2, - "id": 3, + "account_id": 1, + "id": 102, "sis_user_id": null, - "unique_id": "belieber@example.com", - "user_id": 3, - "authentication_provider_id": 2, + "unique_id": "facebook@example.com", + "user_id": 1, + "authentication_provider_id": 1, "authentication_provider_type": "facebook" } ], @@ -45,19 +44,23 @@ }, "edit_user_login": { "method": "PUT", - "endpoint": "accounts/123/logins/112233", + "endpoint": "accounts/1/logins/101", "data": { - "id": 123, - "unique_id": 112233 + "account_id": 1, + "id": 101, + "unique_id": "newemail@example.com", + "user_id": 1 }, "status_code": 200 }, "delete_user_login": { "method": "DELETE", - "endpoint": "users/123/logins/112233", + "endpoint": "users/1/logins/101", "data": { - "id": 123, - "unique_id": 112233 + "account_id": 1, + "id": 101, + "unique_id": "belieber@example.com", + "user_id": 1 } } } diff --git a/tests/test_account.py b/tests/test_account.py index cb82092b..cdcd25f4 100644 --- a/tests/test_account.py +++ b/tests/test_account.py @@ -450,15 +450,20 @@ def test_list_user_logins(self, m): # create_user_login() def test_create_user_login(self, m): - register_uris({'account': ['create_user_login']}, m) + register_uris({'login': ['create_user_login']}, m) - response = self.account.create_user_login(user={'id': 123}, login={'unique_id': 112233}) + unique_id = 'belieber@example.com' + + response = self.account.create_user_login( + user={'id': 1}, + login={'unique_id': unique_id} + ) self.assertIsInstance(response, Login) self.assertTrue(hasattr(response, 'id')) self.assertTrue(hasattr(response, 'unique_id')) - self.assertEqual(response.id, 123) - self.assertEqual(response.unique_id, 112233) + self.assertEqual(response.id, 101) + self.assertEqual(response.unique_id, unique_id) def test_create_user_login_fail_on_user_id(self, m): with self.assertRaises(RequiredFieldMissing): @@ -466,7 +471,7 @@ def test_create_user_login_fail_on_user_id(self, m): def test_create_user_login_fail_on_login_unique_id(self, m): with self.assertRaises(RequiredFieldMissing): - self.account.create_user_login(user={'id': 123}, login={}) + self.account.create_user_login(user={'id': 1}, login={}) # get_department_level_participation_data_with_given_term() def test_get_department_level_participation_data_with_given_term(self, m): diff --git a/tests/test_login.py b/tests/test_login.py index 8d2c0587..6b910003 100644 --- a/tests/test_login.py +++ b/tests/test_login.py @@ -17,13 +17,14 @@ def setUp(self): with requests_mock.Mocker() as m: register_uris({ - 'account': ['get_by_id', 'create_user_login'] + 'account': ['get_by_id'], + 'login': ['create_user_login'] }, m) self.account = self.canvas.get_account(1) self.login = self.account.create_user_login( - user={"id": 123}, - login={"unique_id": 112233} + user={'id': 1}, + login={'unique_id': 'belieber@example.com'} ) # delete() @@ -34,16 +35,16 @@ def test_delete_user_login(self, m): self.assertIsInstance(deleted_user_login, Login) self.assertTrue(hasattr(deleted_user_login, 'unique_id')) - self.assertEqual(deleted_user_login.unique_id, 112233) + self.assertEqual(deleted_user_login.unique_id, 'belieber@example.com') # edit() def test_edit_user_login(self, m): register_uris({'login': ['edit_user_login']}, m) - unique_id = 112233 + unique_id = 'newemail@example.com' edited_user_login = self.login.edit( - user={"id": 123}, - login={"unique_id": unique_id}, + user={'id': 1}, + login={'unique_id': unique_id}, ) self.assertIsInstance(edited_user_login, Login)