1 import pytest

2

3 from meshadmin.server.networks.services import create_network

4

5

6@pytest.fixture

7 def create_test_password() -> str:

8 return "123test"

9

10

11@pytest.fixture

12 def create_user(django_user_model, create_test_password):

13 def _make_user(

14 username="testuser", email="test@example.com", password=create_test_password

15 ):

16 return django_user_model.objects.create_user(

17 username=username, email=email, password=password

18 )

19

20 return _make_user

21

22

23@pytest.fixture

24 def auth_client(client, create_user, create_test_password):

25 def _make_auth_client(username="testuser"):

26 user = create_user(username=username)

27 client.login(username=user.username, password=create_test_password)

28 return client, user

29

30 return _make_auth_client

31

32

33@pytest.fixture

34 def test_network(create_user):

35 def _create_network(name="test_network", cidr="100.100.64.0/24", user=None):

36 if user is None:

37 user = create_user()

38 return create_network(name, cidr, user=user)

39

40 return _create_network