Skip to content

Commit ef94e38

Browse files
authored
Shanbady/consolidate static fixtures (#1684)
* testing initial migration change * testing initial migration change * moving static fixtures into data_fixtures app * restoring old management commands * fixing import * fixing imports and tests * updating dev init script to run datamigrations * restoring data migrations * adding defaults to get or create * adding defaults to get or create * adding docstring * removing duplicate backpopulate
1 parent 64fcbf8 commit ef94e38

20 files changed

+219
-158
lines changed

.devcontainer/devcontainer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,6 @@
2222
"SEE_API_CLIENT_SECRET": {}
2323
},
2424
"features": {},
25-
"postStartCommand": "while [ \"$(python manage.py showmigrations | grep \"\\[ \\]\" | wc -l)\" -ne \"0\" ]; do echo \"waiting for migrations\"; sleep 2; done && python manage.py update_offered_by && python manage.py update_platforms && python manage.py update_departments_schools && python manage.py backpopulate_resource_channels --overwrite --all && python manage.py update_course_number_departments && python manage.py backpopulate_mitxonline_data && python manage.py backpopulate_micromasters_data && python manage.py recreate_index --all",
25+
"postStartCommand": "while [ \"$(python manage.py showmigrations | grep \"\\[ \\]\" | wc -l)\" -ne \"0\" ]; do echo \"waiting for migrations\"; sleep 2; done && python manage.py update_offered_by && python manage.py update_platforms && python manage.py update_departments_schools && python manage.py update_course_number_departments && python manage.py backpopulate_mitxonline_data && python manage.py backpopulate_micromasters_data && python manage.py backpopulate_resource_channels --overwrite --all && python manage.py recreate_index --all",
2626
"forwardPorts": [8062, 8063]
2727
}

data_fixtures/migrations/0001_add_testimonial_data.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,16 @@
77
from django.core.files import File
88
from django.db import migrations
99

10+
from data_fixtures.utils import (
11+
upsert_department_data,
12+
upsert_offered_by_data,
13+
upsert_platform_data,
14+
upsert_school_data,
15+
upsert_topic_data_file,
16+
)
17+
18+
logger = logging.getLogger(__name__)
19+
1020
"""
1121
Fix an issue with PIL's logger when running in test
1222
https://github.com/camptocamp/pytest-odoo/issues/15
@@ -216,6 +226,27 @@
216226
]
217227

218228

229+
def load_initial_fixtures(apps, schema_editor):
230+
"""
231+
Load initial static fixtures required by
232+
management commands further down
233+
"""
234+
offerors = upsert_offered_by_data()
235+
departments = upsert_department_data()
236+
schools = upsert_school_data()
237+
platforms = upsert_platform_data()
238+
topics = upsert_topic_data_file()
239+
logout = (
240+
f"Updated:"
241+
f" {offerors} offerors"
242+
f" {departments} departments"
243+
f" {schools} schools"
244+
f" {platforms} platforms"
245+
f" {topics} topics"
246+
)
247+
logger.info(logout)
248+
249+
219250
def load_fixtures(apps, schema_editor):
220251
"""
221252
Load fixtures for testimonials
@@ -252,5 +283,6 @@ class Migration(migrations.Migration):
252283
dependencies = []
253284

254285
operations = [
286+
migrations.RunPython(load_initial_fixtures, migrations.RunPython.noop),
255287
migrations.RunPython(load_fixtures, migrations.RunPython.noop),
256288
]

data_fixtures/migrations/0004_upsert_initial_topic_data.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
from django.db import migrations
44

5-
from learning_resources.utils import upsert_topic_data_file
5+
from data_fixtures.utils import upsert_topic_data_file
66

77

88
def perform_topic_upsert(apps, schema_editor):

data_fixtures/migrations/0007_topic_mappings_edx_add_programming_coding_to_computer_science.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
from django.db import migrations
77

8-
from learning_resources.utils import upsert_topic_data_string
8+
from data_fixtures.utils import upsert_topic_data_string
99

1010
map_changes = """
1111
---

data_fixtures/migrations/0009_topics_update_engineering_add_manufacturing.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
from django.db import migrations
99

1010
from channels.constants import ChannelType
11-
from learning_resources.utils import upsert_topic_data_string
11+
from data_fixtures.utils import upsert_topic_data_string
1212

1313
map_changes = """
1414
---

data_fixtures/migrations/0012_topic_mappings_adjust_sustainable_business_finance_accounting.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
from django.db import migrations
99

10-
from learning_resources.utils import upsert_topic_data_string
10+
from data_fixtures.utils import upsert_topic_data_string
1111

1212
forward_map_changes = """
1313
---

0 commit comments

Comments
 (0)