Skip to content

Commit

Permalink
tests: add tests for errors in xml upload
Browse files Browse the repository at this point in the history
  • Loading branch information
MyPyDavid committed Feb 8, 2024
1 parent 1ea58fa commit 55379af
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 deletions.
21 changes: 16 additions & 5 deletions rdmo/management/tests/test_viewset_upload.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@
'list': 'v1-management:upload-list'
}

xml_error_files = [
('file-does-not-exist.xml', 'may not be blank'),
('xml/error.xml', 'syntax error'),
('xml/error-version.xml', 'RDMO XML Version: 99'),
]

@pytest.mark.parametrize('username,password', users)
def test_list(db, client, username, password):
Expand Down Expand Up @@ -110,13 +115,19 @@ def test_create_empty(db, client, username, password):


@pytest.mark.parametrize('username,password', users)
def test_create_error(db, client, username, password):
@pytest.mark.parametrize('xml_file_path, error_message', xml_error_files)
def test_create_error(db, client, username, password, xml_file_path, error_message):
client.login(username=username, password=password)

xml_file = Path(settings.BASE_DIR) / 'xml' / 'error.xml'

xml_file = Path(settings.BASE_DIR).joinpath(xml_file_path)
url = reverse(urlnames['list'])
with open(xml_file, encoding='utf8') as f:
response = client.post(url, {'file': f})
try:
with open(xml_file, encoding='utf8') as f:
response = client.post(url, {'file': f})
except FileNotFoundError:
response = client.post(url)

assert response.status_code == status_map['create_error'][username], response.json()
if response.status_code == 400:
response_msg = ",".join(response.json()['file'])
assert error_message in response_msg
3 changes: 3 additions & 0 deletions testing/xml/error-version.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<?xml version="1.0" encoding="UTF-8"?>
<rdmo xmlns:dc="http://purl.org/dc/elements/1.1/" created="2023-04-20T09:39:10.351808+02:00" version="99.9.9">
</rdmo>

0 comments on commit 55379af

Please sign in to comment.