def test_change_scopes_app_does_not_exist(self): user_ = User.objects.create(email="*****@*****.**", cn="test", given_name="Test Test") request = self.factory.post('/api/updatescopes/', { "app_id": 100000000000001, "scopes": "{}" }) request.session = {'user_id': user_.id} response = update_scopes(request) content = json.loads(response.content.decode()) self.assertEqual(response.status_code, 400) self.assertEqual(content["message"], "App does not exist.")
def test_change_scopes_no_scope_data(self): user_ = User.objects.create(email="*****@*****.**", cn="test", given_name="Test Test") app_ = App.objects.create(user=user_, name="An App") request = self.factory.post('/api/updatescopes/', { "app_id": app_.id, }) request.session = {'user_id': user_.id} response = update_scopes(request) content = json.loads(response.content.decode()) self.assertEqual(response.status_code, 400) self.assertEqual(content["message"], "No scopes data attached.")
def test_change_scopes_not_in_session(self): user_ = User.objects.create(email="*****@*****.**", cn="test", given_name="Test Test") app_ = App.objects.create(user=user_, name="An App") request = self.factory.post('/api/updatescopes/', { "app_id": app_.id, }) response = update_scopes(request) content = json.loads(response.content.decode()) self.assertEqual(response.status_code, 400) self.assertEqual(content["message"], "User ID not set in session. Please log in again.")
def test_change_scopes_success(self): user_ = User.objects.create(email="*****@*****.**", cn="test", given_name="Test Test") app_ = App.objects.create(user=user_, name="An App") request = self.factory.post( '/api/updatescopes/', { "app_id": app_.id, "scopes": '[{"checked":true, "name":"timetable"}, \ {"checked":false, "name":"student_number"}]' }) request.session = {'user_id': user_.id} self.assertEqual(app_.scope.scope_number, 0) response = update_scopes(request) content = json.loads(response.content.decode()) self.assertEqual(response.status_code, 200) self.assertEqual(content["message"], "Scope successfully changed.") app_ = App.objects.filter(id=app_.id, user=user_.id)[0] self.assertEqual(app_.scope.scope_number, 2)