From 7b2c753409fb24e9c0781ffff79ea2abb1578e9f Mon Sep 17 00:00:00 2001 From: Christian Adell Date: Tue, 28 May 2024 08:48:43 +0200 Subject: [PATCH] docs: add context test example --- docs/user/design_testing.md | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/docs/user/design_testing.md b/docs/user/design_testing.md index d81246a..5f8569b 100644 --- a/docs/user/design_testing.md +++ b/docs/user/design_testing.md @@ -97,3 +97,25 @@ class DecommissioningTestBase(DesignTestCase): ... ``` + +### Test Context Functions + +Context test functions can also be tested to validate that the logic works as expected. + +```python +class TestEdgeSiteBlocksContext(DesignTestCase): + def test_calculate_prefix(self): + site = Site.objects.create( + name="TEST SITE", + status=Status.objects.get(name="Active"), + ) + prefix = site.prefixes.create( + prefix="192.0.2.0/24", + status=Status.objects.get(name="Active"), + ) + prefix.tags.add(Tag.objects.get(name="abc")) + prefix.save() + context = EdgeSiteBlocksContext({"site_code": "TEST SITE"}) + prefix_str = context.calculate_prefix({"parent": "abc", "offset": "0.0.0.0/28"}) + self.assertEqual("192.0.2.0/28", prefix_str) +```