mirror of
https://github.com/HackSoftware/Django-Styleguide.git
synced 2025-02-06 22:50:53 +03:00
Add example code for CourseFactory
This commit is contained in:
parent
e03a0c0910
commit
8455c7d1d0
30
README.md
30
README.md
|
@ -205,6 +205,36 @@ There's a lot going on in this test:
|
||||||
* We assert that a validation error is going to be raised if we call `full_clean`.
|
* We assert that a validation error is going to be raised if we call `full_clean`.
|
||||||
* We are not hitting the database at all, since there's no need for that.
|
* We are not hitting the database at all, since there's no need for that.
|
||||||
|
|
||||||
|
Here's how `CourseFactory` looks like:
|
||||||
|
|
||||||
|
```python
|
||||||
|
class CourseFactory(factory.DjangoModelFactory):
|
||||||
|
name = factory.Sequence(lambda n: f'{n}{faker.word()}')
|
||||||
|
start_date = factory.LazyAttribute(
|
||||||
|
lambda _: get_now()
|
||||||
|
)
|
||||||
|
end_date = factory.LazyAttribute(
|
||||||
|
lambda _: get_now() + timedelta(days=30)
|
||||||
|
)
|
||||||
|
|
||||||
|
slug_url = factory.Sequence(lambda n: f'{n}{faker.slug()}')
|
||||||
|
|
||||||
|
repository = factory.LazyAttribute(lambda _: faker.url())
|
||||||
|
video_channel = factory.LazyAttribute(lambda _: faker.url())
|
||||||
|
facebook_group = factory.LazyAttribute(lambda _: faker.url())
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
model = Course
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def _build(cls, model_class, *args, **kwargs):
|
||||||
|
return kwargs
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def _create(cls, model_class, *args, **kwargs):
|
||||||
|
return create_course(**kwargs)
|
||||||
|
```
|
||||||
|
|
||||||
## Services
|
## Services
|
||||||
|
|
||||||
A service is a simple function that:
|
A service is a simple function that:
|
||||||
|
|
Loading…
Reference in New Issue
Block a user