示例#1
0
 def test_invalid_catalog_value(self):
     """
     Test that when we pass an empty string to the form, it gets saved to the database
     as a null value, rather than being ignored or raising an error.
     """
     self.catalog_api.get_all_catalogs.return_value = [{
         "id": 99,
         "name": "My Catalog"
     }, {
         "id":
         1,
         "name":
         "Other catalog!"
     }]
     customer = EnterpriseCustomerFactory(catalog=99, )
     form = EnterpriseCustomerAdminForm(
         {
             'catalog': 5,
             'enforce_data_sharing_consent':
             customer.enforce_data_sharing_consent,
             'site': customer.site.id,
             'name': customer.name,
             'active': customer.active
         },
         instance=customer,
     )
     assert not form.is_valid()
    def test_with_mocked_get_edx_data(self):
        self.catalog_api.get_all_catalogs.return_value = [
            {
                "id": self.catalog_id,
                "name": "My Catalog"
            },
            {
                "id": 1,
                "name": "Other catalog!"
            }
        ]

        customer = EnterpriseCustomerFactory(
            catalog=99,
        )
        form = EnterpriseCustomerAdminForm(
            {
                'catalog': '',
                'enforce_data_sharing_consent': customer.enforce_data_sharing_consent,
                'site': customer.site.id,
                'name': customer.name,
                'active': customer.active
            },
            instance=customer,
        )
        assert isinstance(form.fields['catalog'], forms.ChoiceField)
        assert form.fields['catalog'].choices == BLANK_CHOICE_DASH + [
            (self.catalog_id, 'My Catalog'),
            (1, 'Other catalog!'),
        ]
示例#3
0
 def _make_bound_form(identity_provider):
     """
     Builds bound EnterpriseCustomerAdminForm.
     """
     form_data = {
         "name": "New EnterpriseCustomer",
         "identity_provider": identity_provider,
         "catalog": 1,
         "site": 1,
         "enforce_data_sharing_consent": "optional",
     }
     return EnterpriseCustomerAdminForm(form_data)
    def test_new_enterprise_customer(self):
        """
        Test that a new blank form can be created and is not valid.
        """
        self.catalog_api.get_all_catalogs.return_value = [
            {
                "id": self.catalog_id,
                "name": "My Catalog"
            },
            {
                "id": 1,
                "name": "Other catalog!"
            }
        ]

        form = EnterpriseCustomerAdminForm()
        assert isinstance(form.fields['catalog'], forms.ChoiceField)
        assert form.fields['catalog'].choices == BLANK_CHOICE_DASH + [
            (self.catalog_id, 'My Catalog'),
            (1, 'Other catalog!'),
        ]
        assert not form.is_valid()
示例#5
0
 def test_with_mocked_get_edx_data(self):
     self.catalog_api.get_all_catalogs.return_value = [{
         "id": self.catalog_id,
         "name": "My Catalog"
     }, {
         "id":
         1,
         "name":
         "Other catalog!"
     }]
     form = EnterpriseCustomerAdminForm()
     assert isinstance(form.fields['catalog'], forms.ChoiceField)
     assert form.fields['catalog'].choices == BLANK_CHOICE_DASH + [
         (self.catalog_id, 'My Catalog'),
         (1, 'Other catalog!'),
     ]