From bf0dac5e34dc742161b0910e39281c39b8e811f3 Mon Sep 17 00:00:00 2001 From: Benjamin Bertrand <benjamin.bertrand@esss.se> Date: Wed, 14 Mar 2018 21:34:54 +0100 Subject: [PATCH] Fix issue with NetworkFactory Some tests were hanging due to the addresses generated by factory.Faker('ipv4', network=True) Replace it by a Sequence of /24 addresses --- tests/functional/conftest.py | 1 + tests/functional/factories.py | 12 +++--------- 2 files changed, 4 insertions(+), 9 deletions(-) diff --git a/tests/functional/conftest.py b/tests/functional/conftest.py index 518b78c..05575ff 100644 --- a/tests/functional/conftest.py +++ b/tests/functional/conftest.py @@ -82,6 +82,7 @@ def session(db, request): Rollback any transaction to always leave the database clean """ + factories.NetworkFactory.reset_sequence() factories.InterfaceFactory.reset_sequence() connection = db.engine.connect() transaction = connection.begin() diff --git a/tests/functional/factories.py b/tests/functional/factories.py index febdd62..a5fc4d3 100644 --- a/tests/functional/factories.py +++ b/tests/functional/factories.py @@ -121,7 +121,7 @@ class NetworkFactory(factory.alchemy.SQLAlchemyModelFactory): vlan_name = factory.Sequence(lambda n: f'vlan{n}') vlan_id = factory.Sequence(lambda n: 1600 + n) - address = factory.Faker('ipv4', network=True) + address = factory.Sequence(lambda n: f'192.168.{n}.0/24') scope = factory.SubFactory(NetworkScopeFactory) user = factory.SubFactory(UserFactory) domain = factory.SubFactory(DomainFactory) @@ -130,19 +130,13 @@ class NetworkFactory(factory.alchemy.SQLAlchemyModelFactory): def first_ip(self): net = ipaddress.ip_network(self.address) hosts = list(net.hosts()) - try: - return str(hosts[4]) - except IndexError: - return str(hosts[0]) + return str(hosts[4]) @factory.lazy_attribute def last_ip(self): net = ipaddress.ip_network(self.address) hosts = list(net.hosts()) - try: - return str(hosts[-5]) - except IndexError: - return str(hosts[-1]) + return str(hosts[-5]) class InterfaceFactory(factory.alchemy.SQLAlchemyModelFactory): -- GitLab