started work on implementing the tests
This commit is contained in:
66
tests.py
66
tests.py
@@ -1,5 +1,69 @@
|
||||
# uplim/tests.py
|
||||
|
||||
from django.test import TestCase
|
||||
from django.urls import reverse
|
||||
import json
|
||||
|
||||
# Create your tests here.
|
||||
|
||||
class APIViewsTestCase(TestCase):
|
||||
def setUp(self):
|
||||
# Optionally add fixtures or test data here
|
||||
pass
|
||||
|
||||
def test_pixel_aggregate_view_valid_params(self):
|
||||
"""Test PixelAggregateView with valid parameters."""
|
||||
url = reverse("pixel-aggregate")
|
||||
response = self.client.get(url, {"pixel": "123", "survey": "1-4"})
|
||||
|
||||
self.assertEqual(response.status_code, 200)
|
||||
data = json.loads(response.content.decode())
|
||||
self.assertIn("total_counts", data)
|
||||
self.assertIn("total_exposure", data)
|
||||
self.assertIn("pixel_hpid", data)
|
||||
self.assertIn("surveys", data)
|
||||
|
||||
def test_pixel_aggregate_view_missing_params(self):
|
||||
"""Test PixelAggregateView with missing parameters."""
|
||||
url = reverse("pixel-aggregate")
|
||||
response = self.client.get(url)
|
||||
|
||||
self.assertEqual(response.status_code, 400)
|
||||
data = json.loads(response.content.decode())
|
||||
self.assertIn("detail", data)
|
||||
|
||||
def test_upper_limit_view_valid_params(self):
|
||||
"""Test UpperLimitView with valid parameters."""
|
||||
url = reverse("upper-limit")
|
||||
response = self.client.get(
|
||||
url, {"ra": "10.0", "dec": "20.0", "cl": "0.95", "survey": "1-4"}
|
||||
)
|
||||
|
||||
self.assertEqual(response.status_code, 200)
|
||||
data = json.loads(response.content.decode())
|
||||
# Add assertions based on expected structure
|
||||
self.assertIn("ClassicUpperLimit", data)
|
||||
self.assertIn("BayesianUpperLimit", data)
|
||||
# etc.
|
||||
|
||||
def test_upper_limit_view_missing_params(self):
|
||||
"""Test UpperLimitView with missing parameters."""
|
||||
url = reverse("upper-limit")
|
||||
response = self.client.get(url)
|
||||
|
||||
self.assertEqual(response.status_code, 400)
|
||||
data = json.loads(response.content.decode())
|
||||
self.assertIn("error", data)
|
||||
|
||||
def test_stacked_upper_limit_view_valid_params(self):
|
||||
"""Test StackedUpperLimitView with valid parameters."""
|
||||
url = reverse("stacked-upper-limit")
|
||||
data = {"ra": [10.0, 20.0], "dec": [15.0, 25.0], "cl": 0.95, "survey": "1-4"}
|
||||
response = self.client.put(
|
||||
url, data=json.dumps(data), content_type="application/json"
|
||||
)
|
||||
|
||||
self.assertEqual(response.status_code, 200)
|
||||
response_data = json.loads(response.content.decode())
|
||||
self.assertIn("ClassicUpperLimit", response_data)
|
||||
self.assertIn("BayesianUpperLimit", response_data)
|
||||
# Add more assertions based on expected structure
|
||||
|
Reference in New Issue
Block a user