Coverage for tests / integration / test_food_delivery_api.py: 100%
53 statements
« prev ^ index » next coverage.py v7.13.4, created at 2026-03-20 10:09 -0400
« prev ^ index » next coverage.py v7.13.4, created at 2026-03-20 10:09 -0400
1import unittest
2from graphqler import __main__
3from graphqler import config
4from tests.integration.utils.stats import get_percent_query_mutation_success
5from tests.integration.utils.run_api import run_node_project, wait_for_server
6import os
7import shutil
9class TestFoodDeliveryAPI(unittest.TestCase):
10 PORT = 4000
11 URL = f"http://localhost:{PORT}/graphql"
12 PATH = "ci-test-food-delivery-api/"
13 API_PATH = "tests/test-apis/food-delivery-api"
14 CONFIG_PATH = "tests/test-apis/test_configs/food_delivery_api_config.toml"
15 process = None
16 process_pid = None
18 @classmethod
19 def setUpClass(cls):
20 # Start the GrapQL server
21 node_cmd = shutil.which("node")
22 cls.process = run_node_project(cls.API_PATH, [f"{node_cmd} dbinitializer.js"], str(cls.PORT))
23 cls.process_pid = cls.process.pid
25 # Parse the config
26 config = __main__.parse_config(cls.CONFIG_PATH)
27 __main__.set_config(config)
29 # Wait for the server to to respond
30 wait_for_server(cls.URL, timeout=30)
32 @classmethod
33 def tearDownClass(cls):
34 if cls.process and cls.process.pid == cls.process_pid:
35 cls.process.kill()
36 cls.process.wait()
37 if os.path.exists(cls.PATH):
38 shutil.rmtree(cls.PATH)
40 def test_run_compile_mode_generates_valid_introspection_file(self):
41 __main__.run_compile_mode(self.PATH, self.URL)
42 introspection_path = os.path.join(self.PATH, config.INTROSPECTION_RESULT_FILE_NAME)
43 self.assertTrue(os.path.exists(introspection_path))
44 self.assertGreater(os.path.getsize(introspection_path), 0)
46 def test_run_fuzz_mode_generates_valid_stats_file(self):
47 __main__.run_compile_mode(self.PATH, self.URL)
48 __main__.run_fuzz_mode(self.PATH, self.URL)
49 stats_path = os.path.join(self.PATH, config.STATS_FILE_NAME)
50 self.assertTrue(os.path.exists(stats_path))
51 self.assertGreater(os.path.getsize(stats_path), 0)
53 def test_run_single_mode_generates_valid_stats_file(self):
54 __main__.run_compile_mode(self.PATH, self.URL)
55 __main__.run_single_mode(self.PATH, self.URL, "Query")
56 stats_path = os.path.join(self.PATH, config.STATS_FILE_NAME)
57 self.assertTrue(os.path.exists(stats_path))
58 self.assertGreater(os.path.getsize(stats_path), 0)
60 def test_run_fuzz_mode_has_success_over_seventy_percent(self):
61 __main__.run_compile_mode(self.PATH, self.URL)
62 __main__.run_fuzz_mode(self.PATH, self.URL)
63 stats_path = os.path.join(self.PATH, config.STATS_FILE_NAME)
64 percentage = get_percent_query_mutation_success(stats_path)
65 self.assertTrue(percentage >= 70)