Skip to content

Commit

Permalink
feat: created test for when slug does not exist in all nld data
Browse files Browse the repository at this point in the history
  • Loading branch information
lc-hd committed Oct 15, 2024
1 parent 131b784 commit a5d5ff6
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion tests/functional/test_native_land_data_view.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import requests
from unittest.mock import patch

from django.urls import reverse
Expand Down Expand Up @@ -31,7 +32,7 @@ def test_error_raised_when_slug_is_not_defined_in_get_request(self):
self.assertEqual(response.status_code, 404)
self.assertEqual(response.context['exception'], expected_message)

def test_error_raised_when_slug_is_not_in_nld_data(self):
def test_error_raised_when_slug_is_not_in_all_nld_data(self):
"""
When the retrieve_native_land_all_slug_data returns an empty dictionary
which does not contain the slug, an error should be raised.
Expand All @@ -48,3 +49,21 @@ def test_error_raised_when_slug_is_not_in_nld_data(self):
data=get_variables
)
self.assertEqual(response.context['exception'], expected_message)

def test_error_raised_when_error_occurs_retrieving_all_nld_data(self):
"""
When the retrieve_native_land_all_slug_data fails
an error should be raised.
"""
slug = 'placeholder_slug'
expected_message = f'Unable to Retrieve All NLD Slug Data'
get_variables = {
'slug': slug,
}
with patch('helpers.views.retrieve_native_land_all_slug_data') as mock_function:
mock_function.side_effect = requests.exceptions.HTTPError('Some Error Occurred')
response = self.client.get(
reverse('nld-data'),
data=get_variables
)
self.assertEqual(response.context['exception'], expected_message)

0 comments on commit a5d5ff6

Please sign in to comment.