예제 #1
0
 def test_add_valid_states(self):
     # test adding valid two letter states
     # case and spacing should not matter
     form_data = {'embargoed_countries': 'cu, Sy ,      US'}
     form = EmbargoedStateForm(data=form_data)
     self.assertTrue(form.is_valid())
     form.save()
     current_embargoes = EmbargoedState.current().embargoed_countries_list
     for country in ["CU", "SY", "US"]:
         self.assertIn(country, current_embargoes)
     # Test clearing by adding an empty list is OK too
     form_data = {'embargoed_countries': ''}
     form = EmbargoedStateForm(data=form_data)
     self.assertTrue(form.is_valid())
     form.save()
     self.assertTrue(len(EmbargoedState.current().embargoed_countries_list) == 0)
예제 #2
0
    def test_add_invalid_states(self):
        # test adding invalid codes
        # xx is not valid
        # usa is not valid
        form_data = {'embargoed_countries': 'usa, xx'}
        form = EmbargoedStateForm(data=form_data)
        self.assertFalse(form.is_valid())

        msg = 'COULD NOT PARSE COUNTRY CODE(S) FOR: {0}'.format([u'USA', u'XX'])
        msg += ' Please check the list of country codes and verify your entries.'
        self.assertEquals(msg, form._errors['embargoed_countries'][0])  # pylint: disable=protected-access

        with self.assertRaisesRegexp(ValueError, "The EmbargoedState could not be created because the data didn't validate."):
            form.save()

        self.assertFalse('USA' in EmbargoedState.current().embargoed_countries_list)
        self.assertFalse('XX' in EmbargoedState.current().embargoed_countries_list)