forked from LinkedInLearning/django-esst-2894047
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
LinkedInLearning#1 added noteFactory
- Loading branch information
Showing
2 changed files
with
15 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,23 @@ | ||
import factory | ||
from django.contrib.auth.models import User | ||
from notes.models import Notes | ||
from factory import fuzzy | ||
from django.contrib.auth.hashers import make_password | ||
|
||
|
||
class UserFactory(factory.django.DjangoModelFactory): | ||
class Meta: | ||
model = User | ||
|
||
username= factory.Sequence(lambda n: f"user_{n:04}") #user_0000 | ||
email=factory.LazyAttribute(lambda user: f"{user.username}@example.com") | ||
#encrypt the password in the database | ||
password=factory.LazyAttribute(lambda p: make_password('password')) | ||
password=factory.LazyAttribute(lambda p: make_password('password')) | ||
|
||
class NoteFactory(factory.django.DjangoModelFactory): | ||
class Meta: | ||
model = Notes | ||
title=fuzzy.FuzzyText(length =20) | ||
text =fuzzy.FuzzyText(length =200) | ||
#create a brand new user for you id u do not have one while creating the note | ||
user = factory.SubFactory(UserFactory) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters