-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add most factories and a POC test for model creation
Refs #330
- Loading branch information
1 parent
aa592f6
commit 7601bd2
Showing
2 changed files
with
92 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
from factory import Sequence, SubFactory, Faker | ||
|
||
from pycroft.model.nat import NATDomain, OutsideIPAddress | ||
from pycroft.model.nat import InsideNetwork, Translation, Forwarding, \ | ||
DHCPHostReservation | ||
from .base import BaseFactory | ||
|
||
|
||
class NatDomainFactory(BaseFactory): | ||
class Meta: | ||
model = NATDomain | ||
|
||
name = Sequence(lambda n: f"NAT Domain {n + 1}") | ||
|
||
|
||
class OutsideIpAddressFactory(BaseFactory): | ||
class Meta: | ||
model = OutsideIPAddress | ||
|
||
nat_domain = SubFactory(NatDomainFactory) | ||
ip_address = Faker('ipv4', network=False) | ||
owner = None | ||
|
||
|
||
class InsideNetworkFactory(BaseFactory): | ||
# TODO this should be filled with all available inside networks | ||
class Meta: | ||
model = InsideNetwork | ||
|
||
nat_domain = SubFactory(NatDomainFactory) | ||
ip_network = Faker('ipv4', network=True) | ||
gateway = Faker('ipv4', network=False) | ||
|
||
|
||
class TranslationFactory(BaseFactory): | ||
class Meta: | ||
model = Translation | ||
|
||
pass | ||
|
||
|
||
class ForwardingFactory(BaseFactory): | ||
class Meta: | ||
model = Forwarding | ||
|
||
pass | ||
|
||
|
||
class DhcpHostReservationFactory(BaseFactory): | ||
class Meta: | ||
model = DHCPHostReservation | ||
|
||
pass | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
from typing import List | ||
|
||
from pycroft.model.nat import NATDomain | ||
from tests import FactoryDataTestBase | ||
from tests.factories import ConfigFactory, UserFactory | ||
from tests.factories.nat import NatDomainFactory, OutsideIpAddressFactory | ||
|
||
|
||
class NatTestBase(FactoryDataTestBase): | ||
def create_factories(self): | ||
ConfigFactory.create() | ||
self.nat_domain = NatDomainFactory() | ||
|
||
|
||
class TrivialNatModelTestCase(NatTestBase): | ||
def create_factories(self): | ||
super().create_factories() | ||
|
||
def test_one_natdomain(self): | ||
doms: List[NATDomain] = NATDomain.q.all() | ||
self.assertEqual(len(doms), 1) | ||
dom = doms[0] | ||
self.assertEqual(dom.name, self.nat_domain.name) | ||
|
||
|
||
class SimpleNatModelTestCase(NatTestBase): | ||
def create_factories(self): | ||
super().create_factories() | ||
self.user = UserFactory.create() | ||
self.outside_ip = OutsideIpAddressFactory(owner=self.user, | ||
nat_domain=self.nat_domain) | ||
# TODO later check that this doesn't work because every outside_ip needs a translation | ||
# TODO add a pool of inside networks | ||
|
||
def test_forwardings_correct(self): | ||
domain: NATDomain = NATDomain.q.one() | ||
self.assertEqual(domain.name, self.nat_domain.name) |