def test_dataset_object_by_name_queries_with_name_returns_model_object( self, mocked): service = DatasetService() actual = service.dataset_object_by_name(DATABASE_NAME, DATASET_NAME) expected = mocked.query.filter.return_value.one.return_value self.assertEqual(actual, expected)
def test_create_dataset_should_create_model(self, mocked): service = DatasetService() service.create_dataset(DATASET_NAME, DATASET_URL, identifier_id=IDENTIFIER) mocked.assert_called_with(name=DATASET_NAME, file_url=DATASET_URL, identifier_id=IDENTIFIER) mocked.return_value.save.assert_called_once()
def test_delete_dataset_object_by_id(self, mocked): service = DatasetService() actual = service.delete_dataset(DATASET_ID) mocked.query.filter.assert_called_with(mocked._id == DATASET_ID) expected = mocked.query.filter.return_value.one.return_value.delete.assert_called_once( ) self.assertEqual(actual, expected)
def test_dataset_by_name_queries_model_with_name_and_return_id( self, mocked): service = DatasetService() expected_output = 1 mocked.query.with_entities.return_value.filter.return_value.one \ .return_value = [expected_output] result = service.dataset_by_name(DATASET_NAME) mocked.query.with_entities.assert_called_with(mocked._id) mocked.query.with_entities.return_value.filter.assert_called_with( mocked._name == DATASET_NAME) self.assertEqual(result, expected_output)
def test_dataset_by_id_should_query_model_with_id(self, mocked): service = DatasetService() service.dataset_by_id(DATASET_ID) mocked.query.filter.assert_called_with(mocked._id == DATASET_ID) mocked.query.filter.return_value.one.assert_called_once()
def __init__(self): self._dataset_service = DatasetService() self._column_service = DatasetColumnService() self._udf_service = UdfService() self._udf_io_service = UdfIOService()
def test_delete_dataset_object_by_id_should_raise_exception(self, mock_id): service = DatasetService() mock_id.return_value.delete.side_effect = Exception() self.assertFalse(service.delete_dataset_by_id(DATASET_ID)) mock_id.assert_called_once_with(DATASET_ID) mock_id.return_value.delete.assert_called_once()
def test_delete_dataset_object_by_id(self, mock_id): service = DatasetService() self.assertTrue(service.delete_dataset_by_id(DATASET_ID)) mock_id.assert_called_once_with(DATASET_ID) mock_id.return_value.delete.assert_called_once()