Skip to content

Commit

Permalink
Added User factory and tests
Browse files Browse the repository at this point in the history
  • Loading branch information
katporks committed Nov 23, 2023
1 parent 72e73c1 commit df0112d
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 4 deletions.
3 changes: 2 additions & 1 deletion pytest.ini
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
[pytest]
DJANGO_SETTINGS_MODULE = hot_osm.settings.dev
python_files = test_*.py
python_files = test_*.py test.py
addopts = --reuse-db
16 changes: 16 additions & 0 deletions users/factory.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import factory
from pytest_factoryboy import register


class UserFactory(factory.django.DjangoModelFactory):
username = factory.Sequence(lambda n: "user%d" % n)
first_name = factory.Sequence(lambda n: "first_name%d" % n)
last_name = factory.Sequence(lambda n: "last_name%d" % n)
email = factory.Sequence(lambda n: "email%[email protected]" % n)
password = factory.PostGenerationMethodCall("set_password", "password")

class Meta:
model = "users.User"


register(UserFactory)
29 changes: 29 additions & 0 deletions users/test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import pytest
from django.contrib.auth import get_user_model

from .factory import UserFactory

User = get_user_model()


@pytest.mark.django_db
class TestUser:
def test_user_factory():
user = UserFactory()
assert isinstance(user, User)

def test_user_model():
user1 = UserFactory()
user2 = UserFactory()

assert user1.username == "user1"
assert user1.first_name == "first_name1"
assert user1.last_name == "last_name1"
assert user1.email == "[email protected]"
assert user1.check_password("password")

assert user2.username == "user2"
assert user2.first_name == "first_name2"
assert user2.last_name == "last_name2"
assert user2.email == "[email protected]"
assert user2.check_password("password")
3 changes: 0 additions & 3 deletions users/tests.py

This file was deleted.

0 comments on commit df0112d

Please sign in to comment.