|
15 | 15 | from django_concurrent_tests.helpers import make_concurrent_calls |
16 | 16 | from le_utils.constants import content_kinds |
17 | 17 | from le_utils.constants import roles |
| 18 | +from le_utils.constants.labels.accessibility_categories import ACCESSIBILITYCATEGORIESLIST |
18 | 19 |
|
19 | 20 | from contentcuration import models |
20 | 21 | from contentcuration.tests import testdata |
@@ -615,6 +616,64 @@ def test_update_contentnode_extra_fields(self): |
615 | 616 | models.ContentNode.objects.get(id=contentnode.id).extra_fields["randomize"], randomize |
616 | 617 | ) |
617 | 618 |
|
| 619 | + def test_update_contentnode_remove_from_extra_fields(self): |
| 620 | + user = testdata.user() |
| 621 | + metadata = self.contentnode_db_metadata |
| 622 | + metadata["extra_fields"] = { |
| 623 | + "m": 5, |
| 624 | + } |
| 625 | + contentnode = models.ContentNode.objects.create(**metadata) |
| 626 | + self.client.force_authenticate(user=user) |
| 627 | + # Remove extra_fields.m |
| 628 | + response = self.client.post( |
| 629 | + self.sync_url, |
| 630 | + [generate_update_event(contentnode.id, CONTENTNODE, {"extra_fields.m": None})], |
| 631 | + format="json", |
| 632 | + ) |
| 633 | + self.assertEqual(response.status_code, 200, response.content) |
| 634 | + with self.assertRaises(KeyError): |
| 635 | + models.ContentNode.objects.get(id=contentnode.id).extra_fields["m"] |
| 636 | + |
| 637 | + def test_update_contentnode_add_multiple_metadata_labels(self): |
| 638 | + user = testdata.user() |
| 639 | + |
| 640 | + contentnode = models.ContentNode.objects.create(**self.contentnode_db_metadata) |
| 641 | + self.client.force_authenticate(user=user) |
| 642 | + # Add metadata label to accessibility_labels |
| 643 | + response = self.client.post( |
| 644 | + self.sync_url, |
| 645 | + [generate_update_event(contentnode.id, CONTENTNODE, {"accessibility_labels.{}".format(ACCESSIBILITYCATEGORIESLIST[0]): True})], |
| 646 | + format="json", |
| 647 | + ) |
| 648 | + self.assertEqual(response.status_code, 200, response.content) |
| 649 | + self.assertTrue(models.ContentNode.objects.get(id=contentnode.id).accessibility_labels[ACCESSIBILITYCATEGORIESLIST[0]]) |
| 650 | + |
| 651 | + response = self.client.post( |
| 652 | + self.sync_url, |
| 653 | + [generate_update_event(contentnode.id, CONTENTNODE, {"accessibility_labels.{}".format(ACCESSIBILITYCATEGORIESLIST[1]): True})], |
| 654 | + format="json", |
| 655 | + ) |
| 656 | + self.assertEqual(response.status_code, 200, response.content) |
| 657 | + self.assertTrue(models.ContentNode.objects.get(id=contentnode.id).accessibility_labels[ACCESSIBILITYCATEGORIESLIST[0]]) |
| 658 | + self.assertTrue(models.ContentNode.objects.get(id=contentnode.id).accessibility_labels[ACCESSIBILITYCATEGORIESLIST[1]]) |
| 659 | + |
| 660 | + def test_update_contentnode_remove_metadata_label(self): |
| 661 | + user = testdata.user() |
| 662 | + metadata = self.contentnode_db_metadata |
| 663 | + metadata["accessibility_labels"] = {ACCESSIBILITYCATEGORIESLIST[0]: True} |
| 664 | + |
| 665 | + contentnode = models.ContentNode.objects.create(**self.contentnode_db_metadata) |
| 666 | + self.client.force_authenticate(user=user) |
| 667 | + # Add metadata label to accessibility_labels |
| 668 | + response = self.client.post( |
| 669 | + self.sync_url, |
| 670 | + [generate_update_event(contentnode.id, CONTENTNODE, {"accessibility_labels.{}".format(ACCESSIBILITYCATEGORIESLIST[0]): None})], |
| 671 | + format="json", |
| 672 | + ) |
| 673 | + self.assertEqual(response.status_code, 200, response.content) |
| 674 | + with self.assertRaises(KeyError): |
| 675 | + models.ContentNode.objects.get(id=contentnode.id).accessibility_labels[ACCESSIBILITYCATEGORIESLIST[0]] |
| 676 | + |
618 | 677 | def test_update_contentnode_tags(self): |
619 | 678 | user = testdata.user() |
620 | 679 | contentnode = models.ContentNode.objects.create(**self.contentnode_db_metadata) |
|
0 commit comments