From 966ea01c714e851adc1b4affdafd4eff1cdcdf65 Mon Sep 17 00:00:00 2001 From: Skia Date: Tue, 7 Mar 2023 21:15:35 +0100 Subject: [PATCH] galaxy: add a full galaxy state test --- .gitignore | 1 + galaxy/ref_galaxy_state.json | 1 + galaxy/tests.py | 19 +++++++++++++++++++ 3 files changed, 21 insertions(+) create mode 100644 galaxy/ref_galaxy_state.json diff --git a/.gitignore b/.gitignore index c6c093e6..f0ee47d9 100644 --- a/.gitignore +++ b/.gitignore @@ -11,6 +11,7 @@ dist/ env/ doc/html data/ +galaxy/test_galaxy_state.json /static/ sith/settings_custom.py sith/search_indexes/ diff --git a/galaxy/ref_galaxy_state.json b/galaxy/ref_galaxy_state.json new file mode 100644 index 00000000..e418318f --- /dev/null +++ b/galaxy/ref_galaxy_state.json @@ -0,0 +1 @@ +{"nodes": [{"id": 11, "name": "Com Unity", "mass": 1}, {"id": 0, "name": "Bibou ", "mass": 9}, {"id": 1, "name": "S' Kia", "mass": 10}, {"id": 3, "name": "Subscribed User", "mass": 8}, {"id": 6, "name": "Compte Able", "mass": 8}, {"id": 8, "name": "Richard Batsbak", "mass": 10}, {"id": 9, "name": "S Li", "mass": 8}, {"id": 10, "name": "Kro Phil'", "mass": 2}], "links": [{"source": 10, "target": 1, "value": 12}, {"source": 1, "target": 10, "value": 12}, {"source": 10, "target": 8, "value": 14}, {"source": 8, "target": 10, "value": 14}, {"source": 10, "target": 9, "value": 74}, {"source": 9, "target": 10, "value": 74}, {"source": 9, "target": 1, "value": 3}, {"source": 1, "target": 9, "value": 3}, {"source": 8, "target": 1, "value": 14}, {"source": 1, "target": 8, "value": 14}, {"source": 8, "target": 3, "value": 3}, {"source": 3, "target": 8, "value": 3}, {"source": 8, "target": 6, "value": 3}, {"source": 6, "target": 8, "value": 3}, {"source": 1, "target": 0, "value": 1}, {"source": 0, "target": 1, "value": 1}]} \ No newline at end of file diff --git a/galaxy/tests.py b/galaxy/tests.py index d5957a16..6a7b7e3e 100644 --- a/galaxy/tests.py +++ b/galaxy/tests.py @@ -22,6 +22,10 @@ # # +import json + +from pathlib import Path + from django.test import TestCase from django.core.management import call_command @@ -143,3 +147,18 @@ class GalaxyTest(TestCase): self.client.login(username="root", password="plop") response = self.client.get("/galaxy/2/") self.assertEquals(response.status_code, 404) + + def test_full_galaxy_state(self): + Galaxy.rule() + Galaxy.make_state() + state = Galaxy.objects.first().state + + galaxy_dir = Path(__file__).parent + + # Dump computed state, either for easier debugging, or to copy as new reference if changes are legit + (galaxy_dir / "test_galaxy_state.json").write_text(json.dumps(state)) + + self.assertEqual( + state, + json.loads((galaxy_dir / "ref_galaxy_state.json").read_text()), + )