Example #1
0
def test_postal(request, country_code="ie"):
    country_code = request.GET.get('country_code', country_code)
    countries = []
    for k,v in country_map.items():
        countries.append(k)
    form_class = get_postal_form_class(country_code)
    form = form_class()
        
    context = RequestContext(request, locals())    
    return render_to_response('postal/test.html', context)
Example #2
0
 def test_4_line_address(self):
     self.assertEqual(PostalAddress.objects.count(), 0)
     netherlands_form_class = get_postal_form_class("nl")
     self.assertNotEqual(netherlands_form_class, None)
     test_data = {'code': '1234AB'}
     form = netherlands_form_class(data=test_data)
     self.assertEqual(form.fields['line1'].label, "Company name")
     self.assertEqual(form.fields['line2'].label, "Street")
     self.assertEqual(form.fields['city'].label, "Town/City")
     self.assertEqual(form.fields.get('state'), None)
     self.assertEqual(form.fields['code'].label, "Zip Code")
     form.save()
     self.assertEqual(PostalAddress.objects.count(), 1)
Example #3
0
 def test_incorrect_country_code(self):
     """
     Tests that we don't throw an exception for an incorrect country code
     """
     no_country_form_class = get_postal_form_class("xx")
     self.assertNotEqual(no_country_form_class, None)
     
     form = no_country_form_class()
     
     self.assertEqual(form.fields['line1'].label, "Company name")
     self.assertEqual(form.fields['line2'].label, "Street")
     self.assertEqual(form.fields['city'].label, "City")
     self.assertEqual(form.fields['state'].label, "State")
     self.assertEqual(form.fields['code'].label, "Zip code")
Example #4
0
 def test_get_de_address(self):
     """
     Tests that we get the correct widget for Germny
     """
     self.assertEqual(PostalAddress.objects.count(), 0)
     german_form_class = get_postal_form_class("de")
     self.assertNotEqual(german_form_class, None)
     
     # only use required fields
     test_data = {'code': '12345',}
     form = german_form_class(data=test_data)
     
     self.assertEqual(form.fields['line1'].label, "Company name")
     self.assertEqual(form.fields['line2'].label, "Street")
     self.assertEqual(form.fields['city'].label, "City")
     self.assertEqual(form.fields['code'].label, "Zip Code")
     form.save()
     self.assertEqual(PostalAddress.objects.count(), 1)
Example #5
0
    def test_get_ie_address(self):
        """
        Tests that we get the correct widget for Ireland
        """
        self.assertEqual(PostalAddress.objects.count(), 0)
        irish_form_class = get_postal_form_class("ie")
        self.assertNotEqual(irish_form_class, None)

        # only use required fields
        test_data = {'line1': 'street', 'city': 'Tullamore',
                     'state': 'offaly',  }
        form = irish_form_class(data=test_data)
        
        self.assertEqual(form.fields['line1'].label, "Street")
        self.assertEqual(form.fields['line2'].label, "Area")
        self.assertEqual(form.fields['city'].label, "Town/City")
        self.assertEqual(form.fields['state'].label, "County")
        form.save()
        self.assertEqual(PostalAddress.objects.count(), 1)
Example #6
0
    def test_no_localisation(self):
        self.assertEqual(PostalAddress.objects.count(), 0)
        postal.settings.POSTAL_ADDRESS_L10N = False
        postal.settings.POSTAL_ADDRESS_LINE1 = ('a', False)
        postal.settings.POSTAL_ADDRESS_LINE2 = ('b', False)
        postal.settings.POSTAL_ADDRESS_CITY = ('c', False)
        postal.settings.POSTAL_ADDRESS_STATE = ('d', False)
        postal.settings.POSTAL_ADDRESS_CODE = ('e', False)
        reload(postal.forms)
        reload(postal.library)

        noloc_form_class = get_postal_form_class("nl")
        self.assertNotEqual(noloc_form_class, None)
        test_data = {'code': '1234AB'}
        form = noloc_form_class(data=test_data)
        
        self.assertEqual(form.fields['line1'].label, "a")
        self.assertEqual(form.fields['line2'].label, "b")
        self.assertEqual(form.fields['city'].label, "c")
        self.assertEqual(form.fields['state'].label, 'd')
        self.assertEqual(form.fields['code'].label, "e")
        form.save()
        self.assertEqual(PostalAddress.objects.count(), 1)