Skip to content

Commit

Permalink
created test for when slug exists but not in the nld-data
Browse files Browse the repository at this point in the history
  • Loading branch information
lc-hd committed Oct 15, 2024
1 parent 0ae5c86 commit 131b784
Showing 1 changed file with 25 additions and 3 deletions.
28 changes: 25 additions & 3 deletions tests/functional/test_native_land_data_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,31 @@ def setUp(self):
)
self.assertTrue(logged_in, 'Login failed')

def test_slug_does_not_exist_returns_404(self):
kwargs = {}
def test_error_raised_when_slug_is_not_defined_in_get_request(self):
"""
When the get request does not contain a slug, it should raise an error.
"""
expected_message = 'Slug Variable Is Not Defined In Request'
response = self.client.get(reverse('nld-data', kwargs=kwargs))
response = self.client.get(
reverse('nld-data', {})
)
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):
"""
When the retrieve_native_land_all_slug_data returns an empty dictionary
which does not contain the slug, an error should be raised.
"""
slug = 'placeholder_slug'
expected_message = f'Unable to Retrieve Specific NLD Slug Data for {slug}'
get_variables = {
'slug': slug,
}
with patch('helpers.views.retrieve_native_land_all_slug_data') as mock_function:
mock_function.return_value = {}
response = self.client.get(
reverse('nld-data'),
data=get_variables
)
self.assertEqual(response.context['exception'], expected_message)

0 comments on commit 131b784

Please sign in to comment.