Skip to content
Snippets Groups Projects
Commit f433b9d2 authored by Benjamin Bertrand's avatar Benjamin Bertrand
Browse files

Fix failing tests

Factory boy doesn't reset the sequence between tests.
We use a sequence to generate unique IP addresses in the InterfaceFactory.
When the sequence number gets too high, the IP is not in the network
range anymore.

To fix the issue, we reset the sequence number when initializing a new
session.
parent 72752481
No related branches found
No related tags found
No related merge requests found
...@@ -82,6 +82,7 @@ def session(db, request): ...@@ -82,6 +82,7 @@ def session(db, request):
Rollback any transaction to always leave the database clean Rollback any transaction to always leave the database clean
""" """
factories.InterfaceFactory.reset_sequence()
connection = db.engine.connect() connection = db.engine.connect()
transaction = connection.begin() transaction = connection.begin()
session = common.Session session = common.Session
......
...@@ -139,7 +139,10 @@ class NetworkFactory(factory.alchemy.SQLAlchemyModelFactory): ...@@ -139,7 +139,10 @@ class NetworkFactory(factory.alchemy.SQLAlchemyModelFactory):
def last_ip(self): def last_ip(self):
net = ipaddress.ip_network(self.address) net = ipaddress.ip_network(self.address)
hosts = list(net.hosts()) hosts = list(net.hosts())
return str(hosts[-5]) try:
return str(hosts[-5])
except IndexError:
return str(hosts[-1])
class InterfaceFactory(factory.alchemy.SQLAlchemyModelFactory): class InterfaceFactory(factory.alchemy.SQLAlchemyModelFactory):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment