Use real test data where available and mix with generated testdata where missing
This commit is contained in:
parent
739d89f37e
commit
c6afb6ce91
|
|
@ -1,4 +1,5 @@
|
||||||
import os
|
import os
|
||||||
|
import random
|
||||||
import shutil
|
import shutil
|
||||||
|
|
||||||
import wagtail_factories
|
import wagtail_factories
|
||||||
|
|
@ -106,6 +107,9 @@ class Command(BaseCommand):
|
||||||
if not os.path.exists(path):
|
if not os.path.exists(path):
|
||||||
os.makedirs(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):
|
def handle(self, *args, **options):
|
||||||
with connection.cursor() as cursor:
|
with connection.cursor() as cursor:
|
||||||
cursor.execute("DROP SCHEMA IF EXISTS public CASCADE;")
|
cursor.execute("DROP SCHEMA IF EXISTS public CASCADE;")
|
||||||
|
|
@ -130,9 +134,17 @@ class Command(BaseCommand):
|
||||||
for i in range(0, 4):
|
for i in range(0, 4):
|
||||||
UserFactory(username='user{}'.format(i))
|
UserFactory(username='user{}'.format(i))
|
||||||
|
|
||||||
book = BookFactory.create(parent=site.root_page)
|
for book_idx, book_data in enumerate(data):
|
||||||
for idx_topic in range(0, 11):
|
book = BookFactory.create(parent=site.root_page, **self.filter_data(book_data, 'topics'))
|
||||||
topic = TopicFactory.create(parent=book)
|
|
||||||
|
|
||||||
for idc_module in range(0, 5):
|
default_topics = [{} for i in range(0, random.randint(5, 8))]
|
||||||
module = ModuleFactory.create(parent=topic)
|
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)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue