From 29a45805b6da4150eb5160d01a58a06ca30645a4 Mon Sep 17 00:00:00 2001 From: Amir Farhat Date: Tue, 11 Jun 2024 23:28:24 -0400 Subject: [PATCH 1/2] added sample for integration tests for the latest launches endpoint --- tests/test_sample.py | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 tests/test_sample.py diff --git a/tests/test_sample.py b/tests/test_sample.py new file mode 100644 index 000000000..5a18c21a0 --- /dev/null +++ b/tests/test_sample.py @@ -0,0 +1,30 @@ +import unittest +import requests + +class TestSpaceXAPI(unittest.TestCase): + + BASE_URL = "https://api.spacexdata.com/v4" + + def test_latest_launch(self): + url = f"{self.BASE_URL}/launches/latest" + response = requests.get(url) + self.assertEqual(response.status_code, 200) + data = response.json() + #checks to make sure that there is a response of a name, date, and a rocket that is used in the launch. + self.assertIn("name", data) + self.assertIn("date_utc", data) + self.assertIn("rocket", data) + + def test_all_rockets(self): + url = f"{self.BASE_URL}/rockets" + response = requests.get(url) + self.assertEqual(response.status_code, 200) + data = response.json() + self.assertIsInstance(data, list) + if data: # checks to see that there is at least one rocket in the response that is received from the API + self.assertIn("name", data[0]) + self.assertIn("active", data[0]) + self.assertIn("stages", data[0]) + +if __name__ == '__main__': + unittest.main() \ No newline at end of file From 304f2a9c963949289fa98cb43272d22094784eae Mon Sep 17 00:00:00 2001 From: Amir Farhat Date: Tue, 11 Jun 2024 23:31:04 -0400 Subject: [PATCH 2/2] added sample for integration tests for the latest launches endpoint --- tests/test_sample.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_sample.py b/tests/test_sample.py index 5a18c21a0..6d5a9e8eb 100644 --- a/tests/test_sample.py +++ b/tests/test_sample.py @@ -10,7 +10,7 @@ def test_latest_launch(self): response = requests.get(url) self.assertEqual(response.status_code, 200) data = response.json() - #checks to make sure that there is a response of a name, date, and a rocket that is used in the launch. + #checks to make sure that there is a response of a name, date, and a rocket that is used in the launch self.assertIn("name", data) self.assertIn("date_utc", data) self.assertIn("rocket", data)