Skip to content

Commit

Permalink
Fixing more tests
Browse files Browse the repository at this point in the history
Signed-off-by: Kristen Armes <[email protected]>
  • Loading branch information
kristenarmes committed Mar 2, 2024
1 parent 847f745 commit eda4217
Show file tree
Hide file tree
Showing 13 changed files with 52 additions and 46 deletions.
10 changes: 5 additions & 5 deletions frontend/tests/unit/api/preview/test_v0.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def test_no_client_class(self) -> None:

local_app.config['PREVIEW_CLIENT'] = None
with local_app.test_client() as test:
response = test.post('/api/preview/v0/', content_type='application/json')
response = test.post('/api/preview/v0/', json={})
self.assertEqual(response.status_code, HTTPStatus.NOT_IMPLEMENTED)

@unittest.mock.patch(PREVIEW_CLIENT_CLASS + '.get_preview_data')
Expand All @@ -51,7 +51,7 @@ def test_good_client_response(self, mock_get_preview_data: unittest.mock.Mock) -
mock_get_preview_data.return_value = Response(response=response,
status=HTTPStatus.OK)
with local_app.test_client() as test:
post_response = test.post('/api/preview/v0/', content_type='application/json')
post_response = test.post('/api/preview/v0/', json={})
self.assertEqual(post_response.status_code, HTTPStatus.OK)
self.assertEqual(post_response.json, expected_response_json)

Expand All @@ -69,7 +69,7 @@ def test_bad_client_response(self, mock_get_preview_data: unittest.mock.Mock) ->
mock_get_preview_data.return_value = Response(response=response,
status=HTTPStatus.OK)
with local_app.test_client() as test:
post_response = test.post('/api/preview/v0/', content_type='application/json')
post_response = test.post('/api/preview/v0/', json={})
self.assertEqual(post_response.status_code,
HTTPStatus.INTERNAL_SERVER_ERROR)
self.assertEqual(post_response.json, expected_response_json)
Expand All @@ -90,7 +90,7 @@ def test_good_client_response_feature(self, mock_get_preview_data: unittest.mock
mock_get_preview_data.return_value = Response(response=response,
status=HTTPStatus.OK)
with local_app.test_client() as test:
post_response = test.post('/api/preview/v0/feature_preview', content_type='application/json')
post_response = test.post('/api/preview/v0/feature_preview', json={})
self.assertEqual(post_response.status_code, HTTPStatus.OK)
self.assertEqual(post_response.json, expected_response_json)

Expand All @@ -108,7 +108,7 @@ def test_bad_client_response_feature(self, mock_get_preview_data: unittest.mock.
mock_get_preview_data.return_value = Response(response=response,
status=HTTPStatus.OK)
with local_app.test_client() as test:
post_response = test.post('/api/preview/v0/feature_preview', content_type='application/json')
post_response = test.post('/api/preview/v0/feature_preview', json={})
self.assertEqual(post_response.status_code,
HTTPStatus.INTERNAL_SERVER_ERROR)
self.assertEqual(post_response.json, expected_response_json)
9 changes: 6 additions & 3 deletions metadata/tests/unit/api/column/test_column_badge_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,23 +28,26 @@ def tearDown(self) -> None:
def test_block_bad_badge_name(self) -> None:
self.app.config['WHITELIST_BADGES'] = []
response = self.app.test_client().put(f'/table/{TABLE_NAME}/column/{COLUMN_NAME}'
f'/badge/{BADGE_NAME}?category=table_status')
f'/badge/{BADGE_NAME}?category=table_status',
json={})

self.assertEqual(response.status_code, HTTPStatus.NOT_FOUND)

def test_block_badge_missing_category(self) -> None:
self.app.config['WHITELIST_BADGES'] = [Badge(badge_name='alpha',
category='table_status')]
response = self.app.test_client().put(f'/table/{TABLE_NAME}/column/{COLUMN_NAME}'
f'/badge/{BADGE_NAME}')
f'/badge/{BADGE_NAME}',
json={})

self.assertEqual(response.status_code, HTTPStatus.BAD_REQUEST)

def test_badge_with_category(self) -> None:
self.app.config['WHITELIST_BADGES'] = [Badge(badge_name='alpha',
category='table_status')]
response = self.app.test_client().put(f'/table/{TABLE_NAME}/column/{COLUMN_NAME}'
f'/badge/{BADGE_NAME}?category=table_status')
f'/badge/{BADGE_NAME}?category=table_status',
json={})

self.assertEqual(response.status_code, HTTPStatus.OK)

Expand Down
9 changes: 6 additions & 3 deletions metadata/tests/unit/api/dashboard/test_dashboard_badge_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,21 +26,24 @@ def tearDown(self) -> None:

def test_block_bad_badge_name(self) -> None:
self.app.config['WHITELIST_BADGES'] = []
response = self.app.test_client().put(f'/dashboard/{DASHBOARD_NAME}/badge/{BADGE_NAME}?category=table_status')
response = self.app.test_client().put(f'/dashboard/{DASHBOARD_NAME}/badge/{BADGE_NAME}?category=table_status',
json={})

self.assertEqual(response.status_code, HTTPStatus.NOT_FOUND)

def test_block_badge_missing_category(self) -> None:
self.app.config['WHITELIST_BADGES'] = [Badge(badge_name='alpha',
category='table_status')]
response = self.app.test_client().put(f'/dashboard/{DASHBOARD_NAME}/badge/{BADGE_NAME}')
response = self.app.test_client().put(f'/dashboard/{DASHBOARD_NAME}/badge/{BADGE_NAME}',
json={})

self.assertEqual(response.status_code, HTTPStatus.BAD_REQUEST)

def test_badge_with_category(self) -> None:
self.app.config['WHITELIST_BADGES'] = [Badge(badge_name='alpha',
category='table_status')]
response = self.app.test_client().put(f'/dashboard/{DASHBOARD_NAME}/badge/{BADGE_NAME}?category=table_status')
response = self.app.test_client().put(f'/dashboard/{DASHBOARD_NAME}/badge/{BADGE_NAME}?category=table_status',
json={})

self.assertEqual(response.status_code, HTTPStatus.OK)

Expand Down
8 changes: 4 additions & 4 deletions metadata/tests/unit/api/dashboard/test_dashboard_tag_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
class TestDashboardTagAPI(DashboardTestCase):

def test_should_update_tag(self) -> None:
response = self.app.test_client().put(f'/dashboard/{ID}/tag/{TAG}')
response = self.app.test_client().put(f'/dashboard/{ID}/tag/{TAG}', json={})

self.assertEqual(response.status_code, HTTPStatus.OK)
self.mock_proxy.add_tag.assert_called_with(id=ID,
Expand All @@ -26,12 +26,12 @@ def test_should_update_tag(self) -> None:
def test_should_fail_to_update_tag_when_table_not_found(self) -> None:
self.mock_proxy.add_tag.side_effect = NotFoundException(message='foo')

response = self.app.test_client().put(f'/dashboard/{ID}/tag/{TAG}')
response = self.app.test_client().put(f'/dashboard/{ID}/tag/{TAG}', json={})

self.assertEqual(response.status_code, HTTPStatus.NOT_FOUND)

def test_should_delete_tag(self) -> None:
response = self.app.test_client().delete(f'/dashboard/{ID}/tag/{TAG}')
response = self.app.test_client().delete(f'/dashboard/{ID}/tag/{TAG}', json={})

self.assertEqual(response.status_code, HTTPStatus.OK)
self.mock_proxy.delete_tag.assert_called_with(id=ID,
Expand All @@ -42,6 +42,6 @@ def test_should_delete_tag(self) -> None:
def test_should_fail_to_delete_tag_when_table_not_found(self) -> None:
self.mock_proxy.delete_tag.side_effect = NotFoundException(message='foo')

response = self.app.test_client().delete(f'/dashboard/{ID}/tag/{TAG}')
response = self.app.test_client().delete(f'/dashboard/{ID}/tag/{TAG}', json={})

self.assertEqual(response.status_code, HTTPStatus.NOT_FOUND)
6 changes: 3 additions & 3 deletions metadata/tests/unit/api/feature/test_feature_badge_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,21 +26,21 @@ def tearDown(self) -> None:

def test_block_bad_badge_name(self) -> None:
self.app.config['WHITELIST_BADGES'] = []
response = self.app.test_client().put(f'/feature/{FEATURE_NAME}/badge/{BADGE_NAME}?category=data')
response = self.app.test_client().put(f'/feature/{FEATURE_NAME}/badge/{BADGE_NAME}?category=data', json={})

self.assertEqual(response.status_code, HTTPStatus.NOT_FOUND)

def test_block_badge_missing_category(self) -> None:
self.app.config['WHITELIST_BADGES'] = [Badge(badge_name='pii',
category='data')]
response = self.app.test_client().put(f'/feature/{FEATURE_NAME}/badge/{BADGE_NAME}')
response = self.app.test_client().put(f'/feature/{FEATURE_NAME}/badge/{BADGE_NAME}', json={})

self.assertEqual(response.status_code, HTTPStatus.BAD_REQUEST)

def test_badge_with_category(self) -> None:
self.app.config['WHITELIST_BADGES'] = [Badge(badge_name='pii',
category='data')]
response = self.app.test_client().put(f'/feature/{FEATURE_NAME}/badge/{BADGE_NAME}?category=data')
response = self.app.test_client().put(f'/feature/{FEATURE_NAME}/badge/{BADGE_NAME}?category=data', json={})

self.assertEqual(response.status_code, HTTPStatus.OK)

Expand Down
4 changes: 2 additions & 2 deletions metadata/tests/unit/api/feature/test_feature_lineage_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def tearDown(self) -> None:

def test_should_return_response(self) -> None:
self.mock_proxy.get_lineage.return_value = LINEAGE_RESPONSE
response = self.app.test_client().get(f'/feature/{FEATURE_URI}/lineage')
response = self.app.test_client().get(f'/feature/{FEATURE_URI}/lineage', json={})

self.mock_proxy.get_lineage.assert_called_with(id=FEATURE_URI,
resource_type=ResourceType.Feature,
Expand All @@ -64,6 +64,6 @@ def test_should_return_response(self) -> None:
def test_should_fail_when_feature_doesnt_exist(self) -> None:
self.mock_proxy.get_lineage.side_effect = NotFoundException(message='feature not found')

response = self.app.test_client().get(f'/feature/{FEATURE_URI}/lineage')
response = self.app.test_client().get(f'/feature/{FEATURE_URI}/lineage', json={})

self.assertEqual(response.status_code, HTTPStatus.NOT_FOUND)
8 changes: 4 additions & 4 deletions metadata/tests/unit/api/feature/test_feature_tag_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
class TestFeatureTagAPI(FeatureTestCase):

def test_should_update_tag(self) -> None:
response = self.app.test_client().put(f'/feature/{FEATURE_URI}/tag/{TAG}')
response = self.app.test_client().put(f'/feature/{FEATURE_URI}/tag/{TAG}', json={})

self.assertEqual(response.status_code, HTTPStatus.OK)
self.mock_proxy.add_tag.assert_called_with(id=FEATURE_URI,
Expand All @@ -26,12 +26,12 @@ def test_should_update_tag(self) -> None:
def test_should_fail_to_update_tag_when_feature_not_found(self) -> None:
self.mock_proxy.add_tag.side_effect = NotFoundException(message='cannot find feature')

response = self.app.test_client().put(f'/feature/{FEATURE_URI}/tag/{TAG}')
response = self.app.test_client().put(f'/feature/{FEATURE_URI}/tag/{TAG}', json={})

self.assertEqual(response.status_code, HTTPStatus.NOT_FOUND)

def test_should_delete_tag(self) -> None:
response = self.app.test_client().delete(f'/feature/{FEATURE_URI}/tag/{TAG}')
response = self.app.test_client().delete(f'/feature/{FEATURE_URI}/tag/{TAG}', json={})

self.assertEqual(response.status_code, HTTPStatus.OK)
self.mock_proxy.delete_tag.assert_called_with(id=FEATURE_URI,
Expand All @@ -42,6 +42,6 @@ def test_should_delete_tag(self) -> None:
def test_should_fail_to_delete_tag_when_feature_not_found(self) -> None:
self.mock_proxy.delete_tag.side_effect = NotFoundException(message='cannot find feature')

response = self.app.test_client().delete(f'/feature/{FEATURE_URI}/tag/{TAG}')
response = self.app.test_client().delete(f'/feature/{FEATURE_URI}/tag/{TAG}', json={})

self.assertEqual(response.status_code, HTTPStatus.NOT_FOUND)
6 changes: 3 additions & 3 deletions metadata/tests/unit/api/table/test_table_badge_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,21 +26,21 @@ def tearDown(self) -> None:

def test_block_bad_badge_name(self) -> None:
self.app.config['WHITELIST_BADGES'] = []
response = self.app.test_client().put(f'/table/{TABLE_NAME}/badge/{BADGE_NAME}?category=table_status')
response = self.app.test_client().put(f'/table/{TABLE_NAME}/badge/{BADGE_NAME}?category=table_status', json={})

self.assertEqual(response.status_code, HTTPStatus.NOT_FOUND)

def test_block_badge_missing_category(self) -> None:
self.app.config['WHITELIST_BADGES'] = [Badge(badge_name='alpha',
category='table_status')]
response = self.app.test_client().put(f'/table/{TABLE_NAME}/badge/{BADGE_NAME}')
response = self.app.test_client().put(f'/table/{TABLE_NAME}/badge/{BADGE_NAME}', json={})

self.assertEqual(response.status_code, HTTPStatus.BAD_REQUEST)

def test_badge_with_category(self) -> None:
self.app.config['WHITELIST_BADGES'] = [Badge(badge_name='alpha',
category='table_status')]
response = self.app.test_client().put(f'/table/{TABLE_NAME}/badge/{BADGE_NAME}?category=table_status')
response = self.app.test_client().put(f'/table/{TABLE_NAME}/badge/{BADGE_NAME}?category=table_status', json={})

self.assertEqual(response.status_code, HTTPStatus.OK)

Expand Down
4 changes: 2 additions & 2 deletions metadata/tests/unit/api/table/test_table_lineage_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def tearDown(self) -> None:

def test_should_return_response(self) -> None:
self.mock_proxy.get_lineage.return_value = LINEAGE_RESPONSE
response = self.app.test_client().get(f'/table/{TABLE_URI}/lineage')
response = self.app.test_client().get(f'/table/{TABLE_URI}/lineage', json={})
self.assertEqual(response.json, API_RESPONSE)
self.assertEqual(response.status_code, HTTPStatus.OK)
self.mock_proxy.get_lineage.assert_called_with(id=TABLE_URI,
Expand All @@ -85,6 +85,6 @@ def test_should_return_response(self) -> None:
def test_should_fail_when_table_doesnt_exist(self) -> None:
self.mock_proxy.get_lineage.side_effect = NotFoundException(message='table not found')

response = self.app.test_client().get(f'/table/{TABLE_URI}/lineage')
response = self.app.test_client().get(f'/table/{TABLE_URI}/lineage', json={})

self.assertEqual(response.status_code, HTTPStatus.NOT_FOUND)
8 changes: 4 additions & 4 deletions metadata/tests/unit/api/table/test_table_tag_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
class TestTableTagAPI(TableTestCase):

def test_should_update_tag(self) -> None:
response = self.app.test_client().put(f'/table/{TABLE_URI}/tag/{TAG}')
response = self.app.test_client().put(f'/table/{TABLE_URI}/tag/{TAG}', json={})

self.assertEqual(response.status_code, HTTPStatus.OK)
self.mock_proxy.add_tag.assert_called_with(id=TABLE_URI,
Expand All @@ -26,12 +26,12 @@ def test_should_update_tag(self) -> None:
def test_should_fail_to_update_tag_when_table_not_found(self) -> None:
self.mock_proxy.add_tag.side_effect = NotFoundException(message='cannot find table')

response = self.app.test_client().put(f'/table/{TABLE_URI}/tag/{TAG}')
response = self.app.test_client().put(f'/table/{TABLE_URI}/tag/{TAG}', json={})

self.assertEqual(response.status_code, HTTPStatus.NOT_FOUND)

def test_should_delete_tag(self) -> None:
response = self.app.test_client().delete(f'/table/{TABLE_URI}/tag/{TAG}')
response = self.app.test_client().delete(f'/table/{TABLE_URI}/tag/{TAG}', json={})

self.assertEqual(response.status_code, HTTPStatus.OK)
self.mock_proxy.delete_tag.assert_called_with(id=TABLE_URI,
Expand All @@ -42,6 +42,6 @@ def test_should_delete_tag(self) -> None:
def test_should_fail_to_delete_tag_when_table_not_found(self) -> None:
self.mock_proxy.delete_tag.side_effect = NotFoundException(message='cannot find table')

response = self.app.test_client().delete(f'/table/{TABLE_URI}/tag/{TAG}')
response = self.app.test_client().delete(f'/table/{TABLE_URI}/tag/{TAG}', json={})

self.assertEqual(response.status_code, HTTPStatus.NOT_FOUND)
8 changes: 4 additions & 4 deletions search/tests/unit/api/dashboard/test_search_dashboard_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def test_should_get_result_for_search(self) -> None:
result = mock_proxy_results()
self.mock_proxy.fetch_dashboard_search_results.return_value = SearchResult(total_results=1, results=[result])

response = self.app.test_client().get('/search_dashboard?query_term=searchterm')
response = self.app.test_client().get('/search_dashboard?query_term=searchterm', json={})
expected_response = {
"total_results": 1,
"results": [mock_json_response()]
Expand All @@ -43,7 +43,7 @@ def test_should_give_empty_result_when_there_are_no_results_from_proxy(self) ->
self.mock_proxy.fetch_dashboard_search_results.return_value = \
SearchResult(total_results=0, results=[])

response = self.app.test_client().get('/search_dashboard?query_term=searchterm')
response = self.app.test_client().get('/search_dashboard?query_term=searchterm', json={})

expected_response = {
"total_results": 0,
Expand All @@ -52,13 +52,13 @@ def test_should_give_empty_result_when_there_are_no_results_from_proxy(self) ->
self.assertEqual(response.json, expected_response)

def test_should_fail_without_query_term(self) -> None:
response = self.app.test_client().get('/search_dashboard')
response = self.app.test_client().get('/search_dashboard', json={})

self.assertEqual(response.status_code, HTTPStatus.BAD_REQUEST)

def test_should_fail_when_proxy_fails(self) -> None:
self.mock_proxy.fetch_dashboard_search_results.side_effect = RuntimeError('search failed')

response = self.app.test_client().get('/search_dashboard?query_term=searchterm')
response = self.app.test_client().get('/search_dashboard?query_term=searchterm', json={})

self.assertEqual(response.status_code, HTTPStatus.INTERNAL_SERVER_ERROR)
8 changes: 4 additions & 4 deletions search/tests/unit/api/feature/test_search_feature_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def test_should_get_result_for_search(self) -> None:
self.mock_proxy.fetch_feature_search_results.return_value = \
SearchFeatureResult(total_results=1, results=[result])

response = self.app.test_client().get('/search_feature?query_term=searchterm')
response = self.app.test_client().get('/search_feature?query_term=searchterm', json={})

expected_response = {
"total_results": 1,
Expand All @@ -47,7 +47,7 @@ def test_should_give_empty_result_when_there_are_no_results_from_proxy(self) ->
self.mock_proxy.fetch_feature_search_results.return_value = \
SearchFeatureResult(total_results=0, results=[])

response = self.app.test_client().get('/search_feature?query_term=searchterm')
response = self.app.test_client().get('/search_feature?query_term=searchterm', json={})

expected_response = {
"total_results": 0,
Expand All @@ -56,11 +56,11 @@ def test_should_give_empty_result_when_there_are_no_results_from_proxy(self) ->
self.assertEqual(response.json, expected_response)

def test_should_fail_without_query_term(self) -> None:
response = self.app.test_client().get('/search_feature')
response = self.app.test_client().get('/search_feature', json={})
self.assertEqual(response.status_code, HTTPStatus.BAD_REQUEST)

def test_should_fail_when_proxy_fails(self) -> None:
self.mock_proxy.fetch_feature_search_results.side_effect = RuntimeError('search failed')

response = self.app.test_client().get('/search_feature?query_term=searchterm')
response = self.app.test_client().get('/search_feature?query_term=searchterm', json={})
self.assertEqual(response.status_code, HTTPStatus.INTERNAL_SERVER_ERROR)
Loading

0 comments on commit eda4217

Please sign in to comment.