Commit c657902f authored by Nicolas Mérigot's avatar Nicolas Mérigot

Merge branch 'feature/factory' into 'master'

Feature: add model factory

See merge request !2
parents a999d46f 6c3a0da1
Pipeline #1814 passed with stage
in 27 seconds
......@@ -2,4 +2,5 @@ dist
*.egg-info
build
*.iml
env
\ No newline at end of file
env
__pycache__
import factory
from .models import JobOffer
from django.contrib.auth.models import User
from django.db.models.signals import post_save
@factory.django.mute_signals(post_save)
class JobOfferFactory(factory.django.DjangoModelFactory):
class Meta:
model = JobOffer
author = factory.Iterator(User.objects.all())
title = factory.Faker('word')
description = factory.Faker('text', max_nb_chars=250)
creationDate = factory.Faker('past_date')
closingDate = factory.Faker('future_date')
@factory.post_generation
def skills(self, create, extracted, **kwargs):
if not create:
return
if extracted:
for skill in extracted:
self.skills.add(skill)
from django.core.management.base import BaseCommand, CommandError
from djangoldp_joboffer.factories import JobOfferFactory
from djangoldp_skill.models import Skill
class Command(BaseCommand):
help = 'Mock data'
def randomSkill(self, quantity: int = 10):
query_set = Skill.objects.order_by('?')[:quantity]
return query_set
def add_arguments(self, parser):
parser.add_argument('--size', type=int, default=0, help='Number of job offer to create')
parser.add_argument('--sizeof', type=int, default=3, help='Number of skill required into each job offer created')
def handle(self, *args, **options):
for i in range(0, options['size']):
random_skill = self.randomSkill(options['sizeof']);
JobOfferFactory.create(skills=random_skill)
self.stdout.write(self.style.SUCCESS('Successful data mock install'))
......@@ -13,6 +13,10 @@ install_requires =
djangoldp~=0.5
djangoldp_skill~=0.0
[options.extras_require]
dev =
factory_boy>=2.11.0
[semantic_release]
version_source = tag
version_variable = djangoldp_joboffer/__init__.py:__version__
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment