Skip to content

Commit

Permalink
Merge pull request #793 from openedx/asheehan-edx/exec-ed-inclusion-d…
Browse files Browse the repository at this point in the history
…b-drop

fix: dropping include exec ed flag bool and making filter hashes unique
  • Loading branch information
alex-sheehan-edx authored Mar 6, 2024
2 parents 7dc5122 + fc7a2f5 commit df66deb
Show file tree
Hide file tree
Showing 4 changed files with 98 additions and 57 deletions.
36 changes: 18 additions & 18 deletions enterprise_catalog/apps/api/v1/tests/test_serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,24 +102,24 @@ def test_no_uuid_new_filter_creates_new_query(self):
result = find_and_modify_catalog_query(new_filter)
self.assertEqual(result.content_filter, new_filter)

# def test_validation_error_raised_on_duplication(self):
# dupe_filter = {'key': ['summerxbreeze']}
# uuid_to_update = uuid4()
# CatalogQuery.objects.create(
# content_filter=dupe_filter,
# uuid=uuid4()
# )
# CatalogQuery.objects.create(
# content_filter={'key': ['tempfilter']},
# uuid=uuid_to_update
# )
# with transaction.atomic():
# self.assertRaises(
# serializers.ValidationError,
# find_and_modify_catalog_query,
# dupe_filter,
# uuid_to_update
# )
def test_validation_error_raised_on_duplication(self):
dupe_filter = {'key': ['summerxbreeze']}
uuid_to_update = uuid4()
CatalogQuery.objects.create(
content_filter=dupe_filter,
uuid=uuid4()
)
CatalogQuery.objects.create(
content_filter={'key': ['tempfilter']},
uuid=uuid_to_update
)
with transaction.atomic():
self.assertRaises(
serializers.ValidationError,
find_and_modify_catalog_query,
dupe_filter,
uuid_to_update
)

def test_old_uuid_new_title_saves_existing_query_with_title(self):
new_title = 'testing'
Expand Down
78 changes: 39 additions & 39 deletions enterprise_catalog/apps/api/v1/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -350,45 +350,45 @@ def test_put_unauthorized_incorrect_jwt_context(self):
response = self.client.put(url, self.new_catalog_data)
self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN)

# def test_put_integrity_error_regression(self):
# """
# Verify updating an enterprise catalog with a
# catalog query that has a content filter identical to an existing
# one causes an integrity error.

# The expected error is in serializers.py find_and_modify_catalog_query
# """
# catalog_query_1 = CatalogQueryFactory(
# title='catalog_query_1',
# content_filter={"a": "b"},
# )
# EnterpriseCatalogFactory(
# enterprise_uuid=self.enterprise_uuid,
# enterprise_name=self.enterprise_name,
# catalog_query=catalog_query_1,
# )
# catalog_query_2 = CatalogQueryFactory(
# title='catalog_query_2',
# content_filter={"c": "d"},
# )
# enterprise_catalog_2 = EnterpriseCatalogFactory(
# enterprise_uuid=self.enterprise_uuid,
# enterprise_name=self.enterprise_name,
# catalog_query=catalog_query_2,
# )
# put_data = {
# 'uuid': enterprise_catalog_2.uuid,
# 'title': enterprise_catalog_2.title,
# 'enterprise_customer': enterprise_catalog_2.enterprise_uuid,
# 'enterprise_customer_name': enterprise_catalog_2.enterprise_name,
# 'enabled_course_modes': enterprise_catalog_2.enabled_course_modes,
# 'publish_audit_enrollment_urls': enterprise_catalog_2.publish_audit_enrollment_urls,
# 'content_filter': {"a": "b"},
# }

# url = reverse('api:v1:enterprise-catalog-detail', kwargs={'uuid': enterprise_catalog_2.uuid})
# response = self.client.put(url, data=put_data)
# self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
def test_put_integrity_error_regression(self):
"""
Verify updating an enterprise catalog with a
catalog query that has a content filter identical to an existing
one causes an integrity error.
The expected error is in serializers.py find_and_modify_catalog_query
"""
catalog_query_1 = CatalogQueryFactory(
title='catalog_query_1',
content_filter={"a": "b"},
)
EnterpriseCatalogFactory(
enterprise_uuid=self.enterprise_uuid,
enterprise_name=self.enterprise_name,
catalog_query=catalog_query_1,
)
catalog_query_2 = CatalogQueryFactory(
title='catalog_query_2',
content_filter={"c": "d"},
)
enterprise_catalog_2 = EnterpriseCatalogFactory(
enterprise_uuid=self.enterprise_uuid,
enterprise_name=self.enterprise_name,
catalog_query=catalog_query_2,
)
put_data = {
'uuid': enterprise_catalog_2.uuid,
'title': enterprise_catalog_2.title,
'enterprise_customer': enterprise_catalog_2.enterprise_uuid,
'enterprise_customer_name': enterprise_catalog_2.enterprise_name,
'enabled_course_modes': enterprise_catalog_2.enabled_course_modes,
'publish_audit_enrollment_urls': enterprise_catalog_2.publish_audit_enrollment_urls,
'content_filter': {"a": "b"},
}

url = reverse('api:v1:enterprise-catalog-detail', kwargs={'uuid': enterprise_catalog_2.uuid})
response = self.client.put(url, data=put_data)
self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)

@ddt.data(
(False),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# Generated by Django 4.2.9 on 2024-03-05 20:52

from django.db import connection, migrations, models


class Migration(migrations.Migration):

dependencies = [
('catalog', '0038_alter_catalogquery_unique_together_and_more'),
]
db_engine = connection.settings_dict['ENGINE']
if 'sqlite3' in db_engine:
operations = [
migrations.AlterUniqueTogether(
name='catalogquery',
unique_together=set(),
),
migrations.AlterField(
model_name='catalogquery',
name='content_filter_hash',
field=models.CharField(editable=False, max_length=32, null=True, unique=True),
),
migrations.RemoveField(
model_name='catalogquery',
name='include_exec_ed_2u_courses',
),
]
else:
operations = [
migrations.AlterField(
model_name='catalogquery',
name='content_filter_hash',
field=models.CharField(editable=False, max_length=32, null=True, unique=True),
),
migrations.RemoveField(
model_name='catalogquery',
name='include_exec_ed_2u_courses',
),
]

1 change: 1 addition & 0 deletions enterprise_catalog/apps/catalog/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ class CatalogQuery(TimeStampedModel):
null=True,
max_length=32,
editable=False,
unique=True,
)

uuid = models.UUIDField(
Expand Down

0 comments on commit df66deb

Please sign in to comment.