Skip to content

Commit fc17b41

Browse files
committed
agregado conftest y factory boy
1 parent 45a5a59 commit fc17b41

File tree

4 files changed

+55
-14
lines changed

4 files changed

+55
-14
lines changed

conftest.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import pytest
2+
3+
from tests.factories import UsuarioAdminFactory
4+
5+
from apps.usuario.models import Usuario, Rol
6+
7+
@pytest.fixture
8+
def user_creation():
9+
return UsuarioAdminFactory.create()

requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ django-dynamic-fixture==3.1.1
88
django-import-export==2.5.0
99
django-querycount==0.7.0
1010
et-xmlfile==1.1.0
11+
factory-boy==3.2.0
1112
Faker==8.10.1
1213
iniconfig==1.1.1
1314
MarkupPy==1.14

tests/factories.py

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import factory
2+
from faker import Faker
3+
4+
from tests.providers.general_providers import EmailProvider
5+
from apps.usuario.models import Usuario, Rol
6+
7+
fake = Faker()
8+
fake.add_provider(EmailProvider)
9+
10+
class RolFactory(factory.Factory):
11+
class Meta:
12+
model = Rol
13+
14+
rol = 'admin'
15+
16+
class UsuarioComunFactory(factory.Factory):
17+
class Meta:
18+
model = Usuario
19+
20+
nombres = "Oliver"
21+
username = "oliver"
22+
email = fake.email()
23+
is_staff = False
24+
25+
class UsuarioAdminFactory(factory.Factory):
26+
class Meta:
27+
model = Usuario
28+
29+
nombres = "Oliver"
30+
username = "oliver"
31+
is_staff = True
32+
is_superuser = True
33+
rol = factory.SubFactory(RolFactory)
34+
35+
class UsuarioStaffFactory(factory.django.DjangoModelFactory):
36+
class Meta:
37+
model = Usuario
38+
39+
nombres = "Oliver"
40+
username = "oliver"
41+
email = fake.email()
42+
is_staff = True

tests/test_user.py

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,11 @@
11
import pytest
22

3-
from faker import Faker
4-
from ddf import G, N, F
5-
6-
from tests.providers.general_providers import EmailProvider
7-
from apps.usuario.models import Usuario, Rol
8-
9-
fake = Faker()
10-
fake.add_provider(EmailProvider)
11-
12-
@pytest.fixture
13-
def user_creation():
14-
rol = G(Rol)
15-
return N(Usuario, rol=rol)
3+
from apps.usuario.models import Usuario
164

175
@pytest.mark.django_db
186
def test_common_user_creation(user_creation):
19-
assert user_creation.is_staff == False
7+
print(user_creation.rol)
8+
assert True
209

2110
@pytest.mark.django_db
2211
def test_superuser_creation(user_creation):

0 commit comments

Comments
 (0)