Skip to content

Commit

Permalink
patch: modify test (#1076)
Browse files Browse the repository at this point in the history
* patch: modify test

* patch: update view to return 404 as json
  • Loading branch information
tinashechiraya authored Sep 3, 2024
1 parent 52975aa commit fa97e2a
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 13 deletions.
10 changes: 4 additions & 6 deletions django_project/monitor/observation_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
from rest_framework.viewsets import GenericViewSet
from tensorflow import keras
from django.contrib.auth.models import User
from rest_framework.response import Response
from rest_framework import status


Expand Down Expand Up @@ -60,11 +59,10 @@ def get_observations_by_site(request, site_id, format=None):
observations = Observations.objects.filter(site=site)
serializer = ObservationsAllFieldsSerializer(observations, many=True)

return JsonResponse(
{'status': 'success', 'observations': serializer.data}
)
except Sites.DoesNotExist:
raise Http404("Site does not exist")
return JsonResponse({'status': 'success', 'observations': serializer.data})

except Sites.DoesNotExist as e:
return JsonResponse({'status': 'error', 'message': 'Site does not exist'}, status=404)


# Use environment variables for Minio configuration
Expand Down
11 changes: 4 additions & 7 deletions django_project/monitor/tests/test_observations.py
Original file line number Diff line number Diff line change
Expand Up @@ -440,13 +440,10 @@ def test_observations_by_site_id(self):
self.assertEqual(response['Content-Type'], 'application/json')

def test_observations_by_nonexistent_site_id(self):
self.client.login(email='test@gmail.com', password='testuserpassword')

url = reverse('observations-by-site', kwargs={'site_id': 999})

# Check if the Sites.DoesNotExist exception is raised
with self.assertRaises(Sites.DoesNotExist):
self.client.get(url)
self.client.login(email='test@gmail.com', password='testuserpassword')
url = reverse('observations-by-site', kwargs={'site_id': 999})
response = self.client.get(url)
self.assertEqual(response.status_code, 404)

def test_expert_auto_validated_observation(self):
"""
Expand Down

0 comments on commit fa97e2a

Please sign in to comment.