Esempio n. 1
0
 async def test_deleting_user_passes(self):
     """Test user is deleted correctly."""
     operator = UserOperator(self.client)
     operator.db_service.exists.return_value = True
     operator.db_service.delete.return_value = True
     await operator.delete_user(self.user_id)
     operator.db_service.delete.assert_called_with("user", "current")
Esempio n. 2
0
 async def test_user_objects_remove_fails(self):
     """Test remove objects method for users fails."""
     operator = UserOperator(self.client)
     operator.db_service.exists.return_value = True
     operator.db_service.remove.side_effect = ConnectionFailure
     with self.assertRaises(HTTPBadRequest):
         await operator.remove_objects(self.user_generated_id, "study", ["id"])
Esempio n. 3
0
 async def test_check_user_exists_fails(self):
     """Test user exists fails."""
     operator = UserOperator(self.client)
     operator.db_service.exists.return_value = False
     with self.assertRaises(HTTPNotFound):
         await operator._check_user_exists(self.user_id)
         operator.db_service.exists.assert_called_once()
Esempio n. 4
0
 async def test_create_user_fails(self):
     """Test create user fails."""
     data = "eppn", "name"
     operator = UserOperator(self.client)
     operator.db_service.exists_user_by_external_id.side_effect = ConnectionFailure
     with self.assertRaises(HTTPBadRequest):
         await operator.create_user(data)
Esempio n. 5
0
 async def test_deleting_user_fails_on_delete(self):
     """Test user fails on delete operation."""
     operator = UserOperator(self.client)
     operator.db_service.exists.return_value = True
     operator.db_service.delete.return_value = False
     with self.assertRaises(HTTPBadRequest):
         await operator.delete_user(self.user_id)
         operator.db_service.delete.assert_called_with("user", "current")
Esempio n. 6
0
 async def test_create_user_works_existing_userId(self):
     """Test create method for existing user."""
     operator = UserOperator(self.client)
     data = "eppn", "name"
     operator.db_service.exists_user_by_external_id.return_value = self.user_generated_id
     user = await operator.create_user(data)
     operator.db_service.create.assert_not_called()
     self.assertEqual(user, self.user_generated_id)
Esempio n. 7
0
 async def test_user_objects_append_passes(self):
     """Test append objects method for users works."""
     operator = UserOperator(self.client)
     operator.db_service.exists.return_value = True
     operator.db_service.append.return_value = self.test_user
     await operator.assign_objects(self.user_generated_id, "study", [])
     operator.db_service.exists.assert_called_once()
     operator.db_service.append.assert_called_once()
     self.assertEqual(len(operator.db_service.append.mock_calls), 1)
Esempio n. 8
0
 async def test_user_update_fails_with_bad_patch(self):
     """Test user update raises error with improper JSON Patch."""
     patch = [{"op": "replace", "path": "/nothing"}]
     operator = UserOperator(self.client)
     operator.db_service.exists.return_value = True
     operator.db_service.patch.return_value = False
     with self.assertRaises(HTTPBadRequest):
         await operator.update_user(self.test_user, patch)
         operator.db_service.exists.assert_called_once()
Esempio n. 9
0
 async def test_create_user_on_create_fails(self):
     """Test create method fails on db create."""
     operator = UserOperator(self.client)
     data = "externalId", "name"
     operator.db_service.exists_user_by_external_id.return_value = None
     operator.db_service.create.return_value = False
     with self.assertRaises(HTTPBadRequest):
         await operator.create_user(data)
         operator.db_service.create.assert_called_once()
Esempio n. 10
0
 async def test_reading_user_works(self):
     """Test user object is read from db correctly."""
     operator = UserOperator(self.client)
     operator.db_service.exists.return_value = True
     operator.db_service.read.return_value = self.test_user
     read_data = await operator.read_user(self.user_id)
     operator.db_service.exists.assert_called_once()
     operator.db_service.read.assert_called_once_with("user", self.user_id)
     self.assertEqual(read_data, self.test_user)
Esempio n. 11
0
 async def test_check_user_doc_no_data(self):
     """Test check user doc returns no data."""
     operator = UserOperator(self.client)
     operator.db_service.query.return_value = AsyncIterator([])
     result = await operator.check_user_has_doc("folders", self.user_generated_id, self.folder_id)
     operator.db_service.query.assert_called_once_with(
         "user", {"folders": {"$elemMatch": {"$eq": self.folder_id}}, "userId": self.user_generated_id}
     )
     self.assertFalse(result)
Esempio n. 12
0
 async def test_check_user_doc_multiple_folders_fails(self):
     """Test check user doc returns multiple unique folders."""
     operator = UserOperator(self.client)
     operator.db_service.query.return_value = AsyncIterator(["1", "2"])
     with self.assertRaises(HTTPUnprocessableEntity):
         await operator.check_user_has_doc("folders", self.user_generated_id, self.folder_id)
         operator.db_service.query.assert_called_once_with(
             "user", {"folders": {"$elemMatch": {"$eq": self.folder_id}}, "userId": self.user_generated_id}
         )
Esempio n. 13
0
 async def test_user_objects_append_on_result_fails(self):
     """Test append objects method for users fails on db response validation."""
     operator = UserOperator(self.client)
     operator.db_service.exists.return_value = True
     operator.db_service.append.return_value = False
     with self.assertRaises(HTTPBadRequest):
         await operator.assign_objects(self.user_generated_id, "study", [])
         operator.db_service.exists.assert_called_once()
         operator.db_service.append.assert_called_once()
Esempio n. 14
0
 async def test_create_user_works_and_returns_userId(self):
     """Test create method for users work."""
     operator = UserOperator(self.client)
     data = "externalId", "name"
     operator.db_service.exists_user_by_external_id.return_value = None
     operator.db_service.create.return_value = True
     user = await operator.create_user(data)
     operator.db_service.create.assert_called_once()
     self.assertEqual(user, self.user_generated_id)
Esempio n. 15
0
 async def test_user_update_passes_and_returns_id(self):
     """Test update method for users works."""
     patch = [{"op": "add", "path": "/name", "value": "test2"}]
     operator = UserOperator(self.client)
     operator.db_service.exists.return_value = True
     operator.db_service.patch.return_value = True
     user = await operator.update_user(self.test_user, patch)
     operator.db_service.exists.assert_called_once()
     operator.db_service.patch.assert_called_once()
     self.assertEqual(user["userId"], self.user_generated_id)
Esempio n. 16
0
 async def test_check_user_doc_fails(self):
     """Test check user doc fails."""
     operator = UserOperator(self.client)
     operator.db_service.query.side_effect = ConnectionFailure
     with self.assertRaises(HTTPBadRequest):
         await operator.check_user_has_doc("folders", self.user_generated_id, self.folder_id)
Esempio n. 17
0
 async def test_user_objects_assing_fails(self):
     """Test append objects method for users fails."""
     operator = UserOperator(self.client)
     operator.db_service.exists.side_effect = ConnectionFailure
     with self.assertRaises(HTTPBadRequest):
         await operator.assign_objects(self.user_generated_id, "study", [])
Esempio n. 18
0
 async def test_deleting_user_fails(self):
     """Test user delete fails."""
     operator = UserOperator(self.client)
     operator.db_service.exists.side_effect = ConnectionFailure
     with self.assertRaises(HTTPBadRequest):
         await operator.delete_user(self.user_id)