async def setUpClass(cls) -> None: # repository backed by a fresh database test_db = await mongo_factory.create() UserRepositoryTestCase._users = mongo_user_repository_factory(db=test_db) # insert dummy entries dummy = dummies.create() await UserRepositoryTestCase._users.insert(dummy)
async def test_put_user_from_json(self): dummy_data = dummies.create().__dict__ response = await self.client.put(UserView.__route__, json=dummy_data) self.assertEqual(response.status, 200) json_response = await response.json() self.assertIsNotNone(json_response) self.assertIn('inserted_id', json_response)
async def test_post_credentials_to_get_auth_token(self): dummy_data = dummies.create().__dict__ await self.client.put(UserView.__route__, json=dummy_data) response = await self.client.post(AuthView.__route__, json=dummy_data) json_response = await response.json() self.assertEqual(response.status, 200) self.assertIsNotNone(json_response) self.assertIn('token', json_response)
def test_create_user_passing_attributes_by_kwargs(self): kwargs = dummies.create().__dict__ user = User(**kwargs) self.assertEqual(user.name, kwargs['name']) self.assertEqual(user.password, kwargs['password'])
async def test_insert_user(self): user = dummies.create() repo_id = await self.users.insert(user) self.assertIsNotNone(repo_id)
async def insert_dummy(self): dummy = dummies.create() await self.users.insert(dummy) return dummy