Use real test data where available and mix with generated testdata where missing

This commit is contained in:
Pawel Kowalski 2018-08-08 16:00:05 +02:00
parent 739d89f37e
commit c6afb6ce91
1 changed files with 17 additions and 5 deletions

View File

@ -1,4 +1,5 @@
import os
import random
import shutil
import wagtail_factories
@ -106,6 +107,9 @@ class Command(BaseCommand):
if not os.path.exists(path):
os.makedirs(path)
def filter_data(self, input_data, filter_keyword):
return {k: v for (k, v) in input_data.items() if not (k == filter_keyword)}
def handle(self, *args, **options):
with connection.cursor() as cursor:
cursor.execute("DROP SCHEMA IF EXISTS public CASCADE;")
@ -130,9 +134,17 @@ class Command(BaseCommand):
for i in range(0, 4):
UserFactory(username='user{}'.format(i))
book = BookFactory.create(parent=site.root_page)
for idx_topic in range(0, 11):
topic = TopicFactory.create(parent=book)
for book_idx, book_data in enumerate(data):
book = BookFactory.create(parent=site.root_page, **self.filter_data(book_data, 'topics'))
for idc_module in range(0, 5):
module = ModuleFactory.create(parent=topic)
default_topics = [{} for i in range(0, random.randint(5, 8))]
topics_data = book_data.get('topics', default_topics)
for topic_idx, topic_data in enumerate(topics_data):
topic = TopicFactory.create(parent=book, **self.filter_data(topic_data, 'modules'))
default_modules = [{} for i in range(0, random.randint(3, 6))]
modules_data = topic_data.get('modules', default_modules)
for module_idx, module_data in enumerate(modules_data):
module = ModuleFactory.create(parent=topic, **module_data)