Skip to content

Commit

Permalink
docs: add context test example
Browse files Browse the repository at this point in the history
  • Loading branch information
chadell committed May 28, 2024
1 parent d56f805 commit 7b2c753
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions docs/user/design_testing.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
```

0 comments on commit 7b2c753

Please sign in to comment.