Skip to content

Commit

Permalink
Merge pull request #123 from RockefellerArchiveCenter/development
Browse files Browse the repository at this point in the history
Updates test coverage. Merge development in base.
  • Loading branch information
p-galligan authored Apr 27, 2021
2 parents 1d0c93e + 20ed3c8 commit 2fe08e7
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 3 deletions.
20 changes: 20 additions & 0 deletions fixtures/instances_error.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
[{
"lock_version": 0,
"created_by": "admin",
"last_modified_by": "admin",
"create_time": "2020-07-28T14:16:54Z",
"system_mtime": "2020-07-28T14:16:54Z",
"user_mtime": "2020-07-28T14:16:54Z",
"instance_type": "mixed materials",
"jsonmodel_type": "instance",
"is_representative": false,
"sub_container": {
"lock_version": 0,
"created_by": "admin",
"last_modified_by": "admin",
"create_time": "2020-07-28T14:16:54Z",
"system_mtime": "2020-07-28T14:16:54Z",
"user_mtime": "2020-07-28T14:16:54Z",
"jsonmodel_type": "sub_container"
}
}]
25 changes: 22 additions & 3 deletions process_request/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
get_instance_data, get_locations, get_parent_title,
get_preferred_format, get_resource_creators,
get_rights_info, get_rights_status, get_rights_text,
get_size, prepare_values)
get_size, indicator_to_integer, prepare_values)
from .models import User
from .routines import AeonRequester, Mailer, Processor
from .test_helpers import json_from_fixture, random_list, random_string
Expand Down Expand Up @@ -197,6 +197,10 @@ def test_get_size(self):
instance = json_from_fixture(fixture)
self.assertEqual(get_size(instance), size)

instance = json_from_fixture("instances_error.json")
with self.assertRaises(Exception, msg="Error parsing instances"):
get_size(instance)

def test_get_title(self):
for fixture, expected in [
({"title": "foo"}, "foo"),
Expand All @@ -206,6 +210,11 @@ def test_get_title(self):
result = get_parent_title(fixture)
self.assertEqual(result, expected)

def test_indicator_to_integer(self):
for indicator, expected_parsed in [("23ab", 23), ("C", 2)]:
parsed = indicator_to_integer(indicator)
self.assertEqual(parsed, expected_parsed)

# Test is commented out as the code is currently not used, and this allows us to shed a few configs
# def test_aeon_client(self):
# baseurl = random_string(20)
Expand Down Expand Up @@ -267,6 +276,16 @@ def test_get_data(self):
self.assertTrue(isinstance(get_as_data, list))
self.assertEqual(len(get_as_data), 1)

@aspace_vcr.use_cassette("aspace_request.json")
@patch("asnake.client.web_client.ASnakeClient.get")
def test_invalid_get_data(self, mock_as_get):
error_message = random_string(15)
mock_as_get.return_value.status_code = 404
mock_as_get.return_value.text = ''
mock_as_get.return_value.json.return_value = {"error": error_message}
with self.assertRaises(Exception, msg=error_message):
Processor().get_data(["/repositories/2/archival_objects/1134638"], "https://dimes.rockarch.org")

@patch("process_request.routines.Processor.get_data")
def test_send_aeon_requests(self, mock_get_data):
mock_get_data.return_value = [json_from_fixture("as_data.json")]
Expand All @@ -280,8 +299,8 @@ def test_send_aeon_requests(self, mock_get_data):
self.assertTrue(isinstance(delivered, dict))

request_type = "foo"
with self.assertRaises(Exception, msg="Unknown request type '{}', expected either 'readingroom' or 'duplication'".format(request_type)):
AeonRequester().get_request_data(request_type, **data)
with self.assertRaises(ValueError, msg="Unknown request type '{}', expected either 'readingroom' or 'duplication'".format(request_type)):
AeonRequester().get_request_data(request_type, "https://dimes.rockarch.org", **data)


class TestViews(TestCase):
Expand Down

0 comments on commit 2fe08e7

Please sign in to comment.