Skip to content
This repository has been archived by the owner on Sep 16, 2022. It is now read-only.

Commit

Permalink
CSCFAIRMETA-847: [ADD|FIX] tests
Browse files Browse the repository at this point in the history
- One old tests needed to be changed to match the new functionality
  • Loading branch information
tompulli committed Jan 12, 2021
1 parent 7629e17 commit 6ac1cc3
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 6 deletions.
18 changes: 13 additions & 5 deletions src/metax_api/tests/api/rest/v2/views/datasets/drafts.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ def setUp(self):
catalog_json=catalog_json,
date_created=get_tz_aware_now_without_micros(),
catalog_record_services_create='testuser,api_auth_user,metax',
catalog_record_services_edit='testuser,api_auth_user,metax'
catalog_record_services_edit='testuser,api_auth_user,metax',
catalog_record_services_read='testuser,api_auth_user,metax'
)

self.minimal_draft = {
Expand Down Expand Up @@ -380,8 +381,9 @@ def test_minimal_draft_dataset_creation(self):
response = self.client.post('/rest/v2/datasets?draft', self.minimal_draft, format="json")
self.assertEqual(response.status_code, status.HTTP_201_CREATED, response.data)

def test_no_files_or_dirs_in_draft_catalog(self):
''' Files cannot be added to datasets that are in draft catalog '''
def test_allow_files_and_dirs_in_draft_catalog(self):
''' Files can be added to datasets that are in draft catalog '''
self._use_http_authorization(method='basic', username='metax')

for type in ['files', 'directories']:
self.minimal_draft['research_dataset'][type] = [
Expand All @@ -391,8 +393,11 @@ def test_no_files_or_dirs_in_draft_catalog(self):
]

response = self.client.post('/rest/v2/datasets?draft', self.minimal_draft, format="json")
self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST, response.data)
self.assertTrue('files in draft catalog' in response.data['detail'][0], response.data)
self.assertEqual(response.status_code, status.HTTP_201_CREATED, response.data)

response = self.client.get(f'/rest/v2/datasets/{response.data["id"]}/files', format="json")
self.assertEqual(response.status_code, status.HTTP_200_OK, response.data)
self.assertTrue(response.data, response.data)

self.minimal_draft['research_dataset'].pop(type)

Expand Down Expand Up @@ -421,6 +426,9 @@ def test_prevent_update_published_dataset_to_draft_catalog(self):
response = self.client.put(f'/rest/v2/datasets/{cr["id"]}', cr, format="json")
self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST, response.data)

def test_allow_remote_resources_in_ida_for_drafts(self):
"""
When dataset is in draft state, it should be validated with """
class CatalogRecordDraftsOfPublished(CatalogRecordApiWriteCommon):

"""
Expand Down
29 changes: 28 additions & 1 deletion src/metax_api/tests/api/rest/v2/views/datasets/write.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
# :author: CSC - IT Center for Science Ltd., Espoo Finland <[email protected]>
# :license: MIT

from copy import deepcopy
from datetime import timedelta

import responses
Expand Down Expand Up @@ -43,7 +44,8 @@ def create_end_user_catalogs():
catalog_json=catalog_json,
date_created=get_tz_aware_now_without_micros(),
catalog_record_services_create='testuser,api_auth_user,metax',
catalog_record_services_edit='testuser,api_auth_user,metax'
catalog_record_services_edit='testuser,api_auth_user,metax',
catalog_record_services_read='testuser,api_auth_user,metax'
)


Expand Down Expand Up @@ -656,6 +658,31 @@ def test_catalog_record_create_with_other_schema(self):
response = self.client.post('/rest/v2/datasets', self.cr_test_data, format="json")
self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST, response.data)

def test_catalog_record_draft_is_validated_with_draft_schema(self):
"""
Ensure that non-published datasets are always validated with draft schema regardless
of the chosen datacatalog.
"""
cr = deepcopy(self.cr_test_data)
cr['data_catalog'] = 2 # ida catalog
response = self.client.post('/rest/v2/datasets?draft', cr, format="json")
self.assertEqual(response.status_code, status.HTTP_201_CREATED, response.data)

cr = response.data
cr['research_dataset']['remote_resources'] = [
{
'title': 'title',
'use_category': {'identifier': 'source'}
}
]

response = self.client.put(f'/rest/v2/datasets/{cr["id"]}', cr, format="json")
self.assertEqual(response.status_code, status.HTTP_200_OK, response.data)

# ensure that dataset is validated against correct schema when publishing
response = self.client.post(f'/rpc/v2/datasets/publish_dataset?identifier={cr["id"]}', format="json")
self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST, response.data)

def test_catalog_record_ref_data_validation_with_other_schema(self):
"""
Ensure that dataset reference data validation and population works with other
Expand Down

0 comments on commit 6ac1cc3

Please sign in to comment.