26
26
from course_discovery .apps .course_metadata .models import (
27
27
AbstractLocationRestrictionModel , AdditionalMetadata , CertificateInfo , Course , CourseEditor , CourseEntitlement ,
28
28
CourseLocationRestriction , CourseRun , CourseRunType , CourseType , Fact , GeoLocation , ProductMeta , ProductValue ,
29
- RestrictedCourseRun , Seat , Source
29
+ RestrictedCourseRun , Seat , Source , TaxiForm
30
30
)
31
31
from course_discovery .apps .course_metadata .signals import (
32
32
additional_metadata_facts_changed , connect_course_data_modified_timestamp_signal_handlers ,
@@ -1306,6 +1306,7 @@ def test_update_with_additional_metadata_if_type_2U(self, type_slug):
1306
1306
'product_meta' : None ,
1307
1307
'external_course_marketing_type' : None ,
1308
1308
'display_on_org_page' : True ,
1309
+ 'taxi_form' : None ,
1309
1310
}
1310
1311
url = reverse ('api:v1:course-detail' , kwargs = {'key' : course .uuid })
1311
1312
course_data = {
@@ -1418,6 +1419,7 @@ def test_update_facts_with_additional_metadata(self): # pylint: disable=too-man
1418
1419
'product_meta' : None ,
1419
1420
'external_course_marketing_type' : None ,
1420
1421
'display_on_org_page' : True ,
1422
+ 'taxi_form' : None ,
1421
1423
}
1422
1424
additional_metadata_1 = {
1423
1425
** additional_metadata ,
@@ -1583,6 +1585,7 @@ def test_update_product_meta_with_additional_metadata(self):
1583
1585
'product_meta' : product_meta ,
1584
1586
'external_course_marketing_type' : None ,
1585
1587
'display_on_org_page' : True ,
1588
+ 'taxi_form' : None ,
1586
1589
}
1587
1590
1588
1591
url = reverse ('api:v1:course-detail' , kwargs = {'key' : course .uuid })
@@ -1596,7 +1599,6 @@ def test_update_product_meta_with_additional_metadata(self):
1596
1599
assert ProductMeta .objects .count () == 2
1597
1600
1598
1601
course = Course .everything .get (uuid = course .uuid , draft = True )
1599
-
1600
1602
self .assertDictEqual (self .serialize_course (course )['additional_metadata' ], additional_metadata )
1601
1603
self .assertDictEqual (self .serialize_course (course )['additional_metadata' ]['product_meta' ], product_meta )
1602
1604
assert previous_data_modified_timestamp < course .data_modified_timestamp
@@ -1609,7 +1611,7 @@ def test_update_product_meta_with_additional_metadata(self):
1609
1611
response = self .client .patch (
1610
1612
url , {'additional_metadata' : {'product_meta' : product_meta }}, format = 'json'
1611
1613
)
1612
- additional_metadata ['product_meta' ] = product_meta
1614
+ assert additional_metadata ['product_meta' ] = = product_meta
1613
1615
assert response .status_code == 200
1614
1616
course = Course .everything .get (uuid = course .uuid , draft = True )
1615
1617
@@ -1632,6 +1634,152 @@ def test_update_product_meta_with_additional_metadata(self):
1632
1634
pre_save .disconnect (data_modified_timestamp_update , ProductMeta )
1633
1635
m2m_changed .disconnect (product_meta_taggable_changed , ProductMeta .keywords .through )
1634
1636
1637
+ @responses .activate
1638
+ def test_update_taxi_form_with_additional_metadata (self ):
1639
+ """ Verify that the taxi_form is updated when additional_metadata is updated. """
1640
+ pre_save .connect (data_modified_timestamp_update , TaxiForm )
1641
+ current = datetime .datetime .now (pytz .UTC )
1642
+ EE_type_2U = CourseTypeFactory (slug = CourseType .EXECUTIVE_EDUCATION_2U )
1643
+ course = CourseFactory (additional_metadata = None , type = EE_type_2U )
1644
+ previous_data_modified_timestamp = course .data_modified_timestamp
1645
+
1646
+ taxi_form = {
1647
+ "form_id" : "12344" ,
1648
+ "grouping" : "test-grouping" ,
1649
+ "title" : course .title ,
1650
+ "subtitle" : "hey you" ,
1651
+ "post_submit_url" : "http://www.edx.org" ,
1652
+ }
1653
+
1654
+ additional_metadata = {
1655
+ 'external_url' : 'https://example.com/456' ,
1656
+ 'external_identifier' : '456' ,
1657
+ 'lead_capture_form_url' : 'https://example.com/lead-capture' ,
1658
+ 'organic_url' : 'https://example.com/organic' ,
1659
+ 'facts' : [{'heading' : 'Fact1 heading' , 'blurb' : '<p>Fact1 blurb</p>' }],
1660
+ 'certificate_info' : {
1661
+ 'heading' : 'Certificate heading' ,
1662
+ 'blurb' : '<p>Certificate blurb</p>' ,
1663
+ },
1664
+ 'start_date' : serialize_datetime (current ),
1665
+ 'end_date' : serialize_datetime (current + datetime .timedelta (days = 10 )),
1666
+ 'registration_deadline' : serialize_datetime (current ),
1667
+ 'variant_id' : str (uuid4 ()),
1668
+ 'course_term_override' : 'Example Program' ,
1669
+ 'product_status' : 'published' ,
1670
+ 'product_meta' : None ,
1671
+ 'external_course_marketing_type' : None ,
1672
+ 'display_on_org_page' : True ,
1673
+ 'taxi_form' : taxi_form ,
1674
+ }
1675
+
1676
+ url = reverse ('api:v1:course-detail' , kwargs = {'key' : course .uuid })
1677
+ response = self .client .patch (url , {'additional_metadata' : additional_metadata }, format = 'json' )
1678
+ assert response .status_code == 200
1679
+
1680
+ assert TaxiForm .objects .get (form_id = taxi_form ['form_id' ]) is not None
1681
+
1682
+ course = Course .everything .get (uuid = course .uuid , draft = True )
1683
+ self .assertDictEqual (self .serialize_course (course )['additional_metadata' ], additional_metadata )
1684
+ self .assertDictEqual (self .serialize_course (course )['additional_metadata' ]['taxi_form' ], taxi_form )
1685
+ assert previous_data_modified_timestamp < course .data_modified_timestamp
1686
+
1687
+ previous_data_modified_timestamp = course .data_modified_timestamp
1688
+ taxi_form ['title' ] = 'New title'
1689
+ response = self .client .patch (
1690
+ url , {'additional_metadata' : {'taxi_form' : taxi_form }}, format = 'json'
1691
+ )
1692
+ additional_metadata ['taxi_form' ] = taxi_form
1693
+
1694
+ assert response .status_code == 200
1695
+ course = Course .everything .get (uuid = course .uuid , draft = True )
1696
+
1697
+ self .assertDictEqual (self .serialize_course (course )['additional_metadata' ], additional_metadata )
1698
+ self .assertDictEqual (self .serialize_course (course )['additional_metadata' ]['taxi_form' ], taxi_form )
1699
+ course .refresh_from_db (fields = ('data_modified_timestamp' ,))
1700
+
1701
+ # If there is no taxi form change, the timestamp won't be updated.
1702
+ previous_data_modified_timestamp = course .data_modified_timestamp
1703
+ response = self .client .patch (
1704
+ url , {'additional_metadata' : {'taxi_form' : taxi_form }}, format = 'json'
1705
+ )
1706
+ additional_metadata ['taxi_form' ] = taxi_form
1707
+ assert response .status_code == 200
1708
+ course = Course .everything .get (uuid = course .uuid , draft = True )
1709
+ assert previous_data_modified_timestamp == course .data_modified_timestamp
1710
+
1711
+ pre_save .disconnect (data_modified_timestamp_update , TaxiForm )
1712
+
1713
+ @responses .activate
1714
+ def test_update_additional_metadata__taxi_form_removal (self ):
1715
+ """ Verify that the taxi_form removed when additional_metadata is updated. """
1716
+ pre_save .connect (data_modified_timestamp_update , TaxiForm )
1717
+ current = datetime .datetime .now (pytz .UTC )
1718
+ EE_type_2U = CourseTypeFactory (slug = CourseType .EXECUTIVE_EDUCATION_2U )
1719
+ course = CourseFactory (additional_metadata = None , type = EE_type_2U )
1720
+ previous_data_modified_timestamp = course .data_modified_timestamp
1721
+
1722
+ taxi_form = {
1723
+ "form_id" : "12344" ,
1724
+ "grouping" : "test-grouping" ,
1725
+ "title" : course .title ,
1726
+ "subtitle" : "hey you" ,
1727
+ "post_submit_url" : "http://www.edx.org" ,
1728
+ }
1729
+
1730
+ additional_metadata = {
1731
+ 'external_url' : 'https://example.com/456' ,
1732
+ 'external_identifier' : '456' ,
1733
+ 'lead_capture_form_url' : 'https://example.com/lead-capture' ,
1734
+ 'organic_url' : 'https://example.com/organic' ,
1735
+ 'facts' : [{'heading' : 'Fact1 heading' , 'blurb' : '<p>Fact1 blurb</p>' }],
1736
+ 'certificate_info' : {
1737
+ 'heading' : 'Certificate heading' ,
1738
+ 'blurb' : '<p>Certificate blurb</p>' ,
1739
+ },
1740
+ 'start_date' : serialize_datetime (current ),
1741
+ 'end_date' : serialize_datetime (current + datetime .timedelta (days = 10 )),
1742
+ 'registration_deadline' : serialize_datetime (current ),
1743
+ 'variant_id' : str (uuid4 ()),
1744
+ 'course_term_override' : 'Example Program' ,
1745
+ 'product_status' : 'published' ,
1746
+ 'product_meta' : None ,
1747
+ 'external_course_marketing_type' : None ,
1748
+ 'display_on_org_page' : True ,
1749
+ 'taxi_form' : taxi_form ,
1750
+ }
1751
+
1752
+ url = reverse ('api:v1:course-detail' , kwargs = {'key' : course .uuid })
1753
+ response = self .client .patch (url , {'additional_metadata' : additional_metadata }, format = 'json' )
1754
+ assert response .status_code == 200
1755
+ assert TaxiForm .objects .get (form_id = taxi_form ['form_id' ]) is not None
1756
+
1757
+ course = Course .everything .get (uuid = course .uuid , draft = True )
1758
+ self .assertDictEqual (self .serialize_course (course )['additional_metadata' ], additional_metadata )
1759
+ self .assertDictEqual (self .serialize_course (course )['additional_metadata' ]['taxi_form' ], taxi_form )
1760
+ assert previous_data_modified_timestamp < course .data_modified_timestamp
1761
+
1762
+ previous_data_modified_timestamp = course .data_modified_timestamp
1763
+ taxi_form = {
1764
+ "form_id" : "" ,
1765
+ "grouping" : "" ,
1766
+ "title" : "" ,
1767
+ "subtitle" : "" ,
1768
+ "post_submit_url" : "" ,
1769
+ }
1770
+ additional_metadata ['taxi_form' ] = taxi_form
1771
+
1772
+ response = self .client .patch (
1773
+ url , {'additional_metadata' : {'taxi_form' : taxi_form }}, format = 'json'
1774
+ )
1775
+
1776
+ assert response .status_code == 200
1777
+ course = Course .everything .get (uuid = course .uuid , draft = True )
1778
+
1779
+ self .assertDictEqual (self .serialize_course (course )['additional_metadata' ], additional_metadata )
1780
+ assert self .serialize_course (course )['additional_metadata' ]['taxi_form' ] == taxi_form
1781
+ pre_save .disconnect (data_modified_timestamp_update , TaxiForm )
1782
+
1635
1783
@responses .activate
1636
1784
def test_update_success_with_course_type_verified (self ):
1637
1785
verified_mode = SeatTypeFactory .verified ()
0 commit comments