From e03cbecebc1989cf8d609cf5601f6c4d0d64d17c Mon Sep 17 00:00:00 2001 From: tyrin Date: Fri, 3 Oct 2025 11:03:00 +0300 Subject: [PATCH] started work on implementing the tests --- tests.py | 66 +++++++++++++++++++++++++++++++++++++++++++++++++++++++- views.py | 2 +- 2 files changed, 66 insertions(+), 2 deletions(-) diff --git a/tests.py b/tests.py index 9c8fd37..7f37f56 100644 --- a/tests.py +++ b/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 diff --git a/views.py b/views.py index 437b193..9c76959 100644 --- a/views.py +++ b/views.py @@ -825,7 +825,7 @@ class StackedUpperLimitView(APIView): error_message = str(e) - N = Nnpix = Bcounts = Bnpix = B = t = S = CR = BR = 0.0 + N = Nnpix = Bcounts = Bnpix = B = t = S = CR = BR = NBR = 0.0 Flux = 0.0 classic_count_ul = classic_count_ll = classic_count_UL = 0.0 classic_rate_ul = classic_rate_ll = classic_rate_UL = 0.0