Skip to content

Commit

Permalink
squash
Browse files Browse the repository at this point in the history
  • Loading branch information
pwnage101 committed Oct 8, 2024
1 parent 78261ab commit da06b5f
Show file tree
Hide file tree
Showing 6 changed files with 250 additions and 203 deletions.
11 changes: 7 additions & 4 deletions enterprise_catalog/apps/api/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -286,17 +286,19 @@ def _update_full_content_metadata_course(content_keys, dry_run=False):
continue

# Merge the full metadata from discovery's /api/v1/courses into the local metadata object.
metadata_record._json_metadata.update(course_metadata_dict)
metadata_record._json_metadata.update(course_metadata_dict) # pylint: disable=protected-access

# Perform more steps to normalize and move keys around
# for more consistency across content types.
normalized_metadata_input = {
'course_metadata': metadata_record.json_metadata,
}
metadata_record._json_metadata['normalized_metadata'] =\
metadata_record._json_metadata['normalized_metadata'] = ( # pylint: disable=protected-access
NormalizedContentMetadataSerializer(normalized_metadata_input).data
metadata_record._json_metadata['normalized_metadata_by_run'] = {}
)
metadata_record._json_metadata['normalized_metadata_by_run'] = {} # pylint: disable=protected-access
for run in metadata_record.json_metadata.get('course_runs', []):
# pylint: disable=protected-access
metadata_record._json_metadata['normalized_metadata_by_run'].update({
run['key']: NormalizedContentMetadataSerializer({
'course_metadata': metadata_record.json_metadata,
Expand All @@ -305,6 +307,7 @@ def _update_full_content_metadata_course(content_keys, dry_run=False):
})

if review := reviews_for_courses_dict.get(content_key):
# pylint: disable=protected-access
metadata_record._json_metadata['reviews_count'] = review.get('reviews_count')
metadata_record._json_metadata['avg_course_rating'] = review.get('avg_course_rating')

Expand Down Expand Up @@ -390,7 +393,7 @@ def _update_full_content_metadata_program(content_keys, dry_run=False):
logger.error('Could not find ContentMetadata record for content_key %s.', content_key)
continue

metadata_record._json_metadata.update(program_metadata_dict)
metadata_record._json_metadata.update(program_metadata_dict) # pylint: disable=protected-access
modified_content_metadata_records.append(metadata_record)

if dry_run:
Expand Down
15 changes: 8 additions & 7 deletions enterprise_catalog/apps/api/tests/test_tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -520,7 +520,7 @@ def test_update_full_metadata(self, mock_oauth_client, mock_partition_course_key
# the normalized metadata serializer.
metadata_4 = ContentMetadataFactory(content_type=COURSE, content_key=course_key_4)
metadata_4.catalog_queries.set([self.catalog_query])
metadata_4._json_metadata['advertised_course_run_uuid'] = None
metadata_4._json_metadata['advertised_course_run_uuid'] = None # pylint: disable=protected-access
metadata_4.save()
non_course_metadata = ContentMetadataFactory(content_type=COURSE_RUN, content_key=non_course_key)
non_course_metadata.catalog_queries.set([self.catalog_query])
Expand Down Expand Up @@ -832,6 +832,7 @@ def setUp(self):
self.course_metadata_published.catalog_queries.set([self.enterprise_catalog_query])
self.course_metadata_published.tags.set([self.tag1])
self.course_metadata_unpublished = ContentMetadataFactory(content_type=COURSE, content_key='course-2')
# pylint: disable=protected-access
self.course_metadata_unpublished._json_metadata.get('course_runs')[0].update({
'status': 'unpublished',
})
Expand Down Expand Up @@ -907,7 +908,7 @@ def test_add_metadata_to_algolia_objects_skips_metadata_records_over_max_size(se
short_description_string = "ayylmao".join(["" for x in range(50000)])
full_description_string = "foobar".join(["" for x in range(50000)])
too_big_sized_course = ContentMetadataFactory(content_type=COURSE, content_key='test-course-2')
too_big_sized_course._json_metadata.update(
too_big_sized_course._json_metadata.update( # pylint: disable=protected-access
{"short_description": short_description_string, "full_description": full_description_string}
)
too_big_sized_course.save()
Expand Down Expand Up @@ -1251,7 +1252,7 @@ def test_index_algolia_published_course_to_program(self, mock_search_client):
program_2 = ContentMetadataFactory(content_type=PROGRAM, content_key='program-2')

# Make program-2 hidden to make it "non-indexable". Later we will assert that it will not get indexed.
program_2._json_metadata.update({
program_2._json_metadata.update({ # pylint: disable=protected-access
'hidden': True,
})
program_2.save()
Expand Down Expand Up @@ -1359,7 +1360,7 @@ def test_index_algolia_unpublished_course_to_program(self, mock_search_client):
program_2.catalog_queries.set([self.enterprise_catalog_query])

# Make program-2 hidden to make it "non-indexable". Later we will assert that it will not get indexed.
program_2._json_metadata.update({
program_2._json_metadata.update({ # pylint: disable=protected-access
'hidden': True,
})
program_2.save()
Expand Down Expand Up @@ -1670,7 +1671,7 @@ def test_index_algolia_program_to_pathway(self, mock_search_client):
program_1.catalog_queries.set([self.enterprise_catalog_query])

# Make program-2 hidden to make it "non-indexable". Later we will assert that it will not get indexed.
program_2._json_metadata.update({
program_2._json_metadata.update({ # pylint: disable=protected-access
'hidden': True,
})
program_2.save()
Expand Down Expand Up @@ -1807,15 +1808,15 @@ def test_index_algolia_all_uuids(self, mock_search_client):
program_for_main_course = ContentMetadataFactory(content_type=PROGRAM, content_key='program-1')
# Make the program hidden to make it "non-indexable", but ensure that it still gets indexed due to being related
# to an indexable course.
program_for_main_course._json_metadata.update({
program_for_main_course._json_metadata.update({ # pylint: disable=protected-access
'hidden': True,
})
program_for_main_course.save()
program_for_pathway = ContentMetadataFactory(content_type=PROGRAM, content_key='program-2')
program_for_pathway.catalog_queries.set([self.enterprise_catalog_query])
# Make the program hidden to make it "non-indexable", but ensure that it still gets indexed due to being related
# to an indexable pathway.
program_for_pathway._json_metadata.update({
program_for_pathway._json_metadata.update({ # pylint: disable=protected-access
'hidden': True,
})
program_for_pathway.save()
Expand Down
2 changes: 1 addition & 1 deletion enterprise_catalog/apps/api/v1/tests/test_serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def test_product_source_formatting(self):
Test that the content metadata serializer will transform product source data within the json metadata field
from a string to a dict.
"""
self.content_metadata_item._json_metadata.update({'product_source': '2u'})
self.content_metadata_item._json_metadata.update({'product_source': '2u'}) # pylint: disable=protected-access
self.content_metadata_item.save()
serialized_data = ContentMetadataSerializer(self.content_metadata_item)
assert serialized_data.data.get('product_source') == {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Generated by Django 4.2.16 on 2024-10-08 15:53
# Generated by Django 4.2.16 on 2024-10-08 22:19

import collections
from django.conf import settings
Expand All @@ -19,6 +19,23 @@ class Migration(migrations.Migration):
]

operations = [
migrations.CreateModel(
name='RestrictedCourseMetadata',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('created', model_utils.fields.AutoCreatedField(default=django.utils.timezone.now, editable=False, verbose_name='created')),
('modified', model_utils.fields.AutoLastModifiedField(default=django.utils.timezone.now, editable=False, verbose_name='modified')),
('content_uuid', models.UUIDField(blank=True, help_text='The UUID that represents a piece of content. This value is usually a secondary identifier to content_key in the enterprise environment.', null=True, verbose_name='Content UUID')),
('content_type', models.CharField(choices=[('course', 'Course'), ('courserun', 'Course Run'), ('program', 'Program'), ('learnerpathway', 'Learner Pathway')], max_length=255)),
('parent_content_key', models.CharField(blank=True, db_index=True, help_text="The key represents this content's parent. For example for course_runs content their parent course key.", max_length=255, null=True)),
('_json_metadata', jsonfield.fields.JSONField(blank=True, db_column='json_metadata', default={}, dump_kwargs={'cls': jsonfield.encoder.JSONEncoder, 'indent': 4, 'separators': (',', ':')}, help_text="The metadata about a particular piece content as retrieved from the discovery service's search/all endpoint results, specified as a JSON object.", load_kwargs={'object_pairs_hook': collections.OrderedDict}, null=True)),
('content_key', models.CharField(help_text='The key that represents a piece of content, such as a course, course run, or program.', max_length=255)),
],
options={
'verbose_name': 'Restricted Content Metadata',
'verbose_name_plural': 'Restricted Content Metadata',
},
),
migrations.AlterField(
model_name='contentmetadata',
name='json_metadata',
Expand All @@ -44,6 +61,29 @@ class Migration(migrations.Migration):
name='content_filter',
field=jsonfield.fields.JSONField(default=dict, dump_kwargs={'cls': jsonfield.encoder.JSONEncoder, 'ensure_ascii': False, 'indent': 4, 'separators': (',', ':')}, help_text="Query parameters which will be used to filter the discovery service's search/all endpoint results, specified as a JSON object.", load_kwargs={'object_pairs_hook': collections.OrderedDict}),
),
migrations.CreateModel(
name='RestrictedRunsAllowedForRestrictedCourses',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('created', model_utils.fields.AutoCreatedField(default=django.utils.timezone.now, editable=False, verbose_name='created')),
('modified', model_utils.fields.AutoLastModifiedField(default=django.utils.timezone.now, editable=False, verbose_name='modified')),
('course', models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='restricted_runs_allowed_for_restricted_courses', to='catalog.restrictedcoursemetadata')),
('run', models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='restricted_runs_allowed_for_restricted_courses', to='catalog.contentmetadata')),
],
options={
'abstract': False,
},
),
migrations.AddField(
model_name='restrictedcoursemetadata',
name='catalog_query',
field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='restricted_content_metadata', to='catalog.catalogquery'),
),
migrations.AddField(
model_name='restrictedcoursemetadata',
name='unrestricted_parent',
field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='restricted_courses', to='catalog.contentmetadata'),
),
migrations.CreateModel(
name='HistoricalRestrictedCourseMetadata',
fields=[
Expand Down Expand Up @@ -71,25 +111,8 @@ class Migration(migrations.Migration):
},
bases=(simple_history.models.HistoricalChanges, models.Model),
),
migrations.CreateModel(
name='RestrictedCourseMetadata',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('created', model_utils.fields.AutoCreatedField(default=django.utils.timezone.now, editable=False, verbose_name='created')),
('modified', model_utils.fields.AutoLastModifiedField(default=django.utils.timezone.now, editable=False, verbose_name='modified')),
('content_uuid', models.UUIDField(blank=True, help_text='The UUID that represents a piece of content. This value is usually a secondary identifier to content_key in the enterprise environment.', null=True, verbose_name='Content UUID')),
('content_type', models.CharField(choices=[('course', 'Course'), ('courserun', 'Course Run'), ('program', 'Program'), ('learnerpathway', 'Learner Pathway')], max_length=255)),
('parent_content_key', models.CharField(blank=True, db_index=True, help_text="The key represents this content's parent. For example for course_runs content their parent course key.", max_length=255, null=True)),
('_json_metadata', jsonfield.fields.JSONField(blank=True, db_column='json_metadata', default={}, dump_kwargs={'cls': jsonfield.encoder.JSONEncoder, 'indent': 4, 'separators': (',', ':')}, help_text="The metadata about a particular piece content as retrieved from the discovery service's search/all endpoint results, specified as a JSON object.", load_kwargs={'object_pairs_hook': collections.OrderedDict}, null=True)),
('content_key', models.CharField(help_text='The key that represents a piece of content, such as a course, course run, or program.', max_length=255)),
('catalog_query', models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='restricted_content_metadata', to='catalog.catalogquery')),
('restricted_runs_allowed', models.ManyToManyField(null=True, related_name='restricted_courses_which_allow_restricted_run', to='catalog.contentmetadata')),
('unrestricted_parent', models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='restricted_courses', to='catalog.contentmetadata')),
],
options={
'verbose_name': 'Restricted Content Metadata',
'verbose_name_plural': 'Restricted Content Metadata',
'unique_together': {('content_key', 'catalog_query')},
},
migrations.AlterUniqueTogether(
name='restrictedcoursemetadata',
unique_together={('content_key', 'catalog_query')},
),
]
Loading

0 comments on commit da06b5f

Please sign in to comment.