def test_list(self): user = factory.make_User() handler = TokenHandler(user, {}, None) create_auth_token(user) expected_tokens = [ self.dehydrate_token(token) for token in get_auth_tokens(user) ] self.assertItemsEqual(expected_tokens, handler.list({}))
def test_create_no_name(self): user = factory.make_User() handler = TokenHandler(user, {}, None) new_token = handler.create({}) self.assertThat(new_token, KeysEqual("id", "key", "secret", "consumer")) event = Event.objects.get(type__level=AUDIT) self.assertIsNotNone(event) self.assertEqual(event.description, "Created token.")
def test_update(self): user = factory.make_User() handler = TokenHandler(user, {}, None) name = factory.make_name("name") token = create_auth_token(user, name) new_name = factory.make_name("name") updated_token = handler.update({"id": token.id, "name": new_name}) self.assertThat(updated_token, KeysEqual("id", "key", "secret", "consumer")) self.assertEqual(new_name, updated_token["consumer"]["name"]) event = Event.objects.get(type__level=AUDIT) self.assertIsNotNone(event) self.assertEqual(event.description, "Modified consumer name of token.")
def test_delete(self): user = factory.make_User() token = create_auth_token(user) handler = TokenHandler(user, {}, None) handler.delete({"id": token.id}) self.assertIsNone(get_one(get_auth_tokens(user).filter(id=token.id)))
def test_get_doesnt_work_if_not_owned(self): user = factory.make_User() handler = TokenHandler(user, {}, None) not_owned_token = create_auth_token(factory.make_User()) self.assertRaises(HandlerDoesNotExistError, handler.get, {"id": not_owned_token.id})
def test_get(self): user = factory.make_User() handler = TokenHandler(user, {}, None) token = create_auth_token(user) self.assertEqual(self.dehydrate_token(token), handler.get({"id": token.id}))