Пример #1
0
 def test_company(self):
     contact = Contact.objects.create()
     data = {
         'email': '*****@*****.**',
         'first_name': 'Test',
         'last_name': 'Company',
         'phone': '123-111-4411',
         'street1': "56 Cool Lane",
         'city': "Niftyville",
         'state': "IA",
         'postal_code': "12344",
         'country': 231,
         'ship_addressee': "Test Company",
         'ship_street1': "56 Industry Way",
         'ship_city': "Niftytown",
         'ship_state': "IA",
         'ship_postal_code': "12366",
         'ship_country': 231,
         'organization': 'Testers Anonymous',
     }
     shop = Config.objects.get_current()
     form = ContactInfoForm(data=data, shop=shop, contact=contact)
     #print "ERR: %s" % form.errors
     self.assertEqual(True, form.is_valid())
     contactid = form.save(contact=contact)
     self.assertEqual(contact.id, contactid)
     self.assert_(contact.organization)
     self.assertEqual(contact.organization.name, 'Testers Anonymous')
Пример #2
0
 def test_company(self):
     contact = Contact.objects.create()
     data = {
         "email": "*****@*****.**",
         "first_name": "Test",
         "last_name": "Company",
         "phone": "123-111-4411",
         "street1": "56 Cool Lane",
         "city": "Niftyville",
         "state": "IA",
         "postal_code": "12344",
         "country": 231,
         "ship_street1": "56 Industry Way",
         "ship_city": "Niftytown",
         "ship_state": "IA",
         "ship_postal_code": "12366",
         "ship_country": 231,
         "company": "Testers Anonymous",
     }
     shop = Config.objects.get_current()
     form = ContactInfoForm(data=data, shop=shop, contact=contact)
     print "ERR: %s" % form.errors
     self.assertEqual(True, form.is_valid())
     contactid = form.save(contact)
     self.assertEqual(contact.id, contactid)
     self.assert_(contact.organization)
     self.assertEqual(contact.organization.name, "Testers Anonymous")
Пример #3
0
def ajax_get_state(request, **kwargs):
    formdata = request.REQUEST.copy()

    try:
        if "country" in formdata:
            country_field = 'country'
        elif "ship_country" in formdata:
            country_field = 'ship_country'
        else:
            raise AjaxGetStateException("No country specified")

        form = ContactInfoForm(data=formdata)
        country_data = formdata.get(country_field)
        try:
            country_obj = form.fields[country_field].clean(country_data)
        except:
            raise AjaxGetStateException("Invalid country specified")

        areas = area_choices_for_country(country_obj, ugettext)

        context = RequestContext(request, {
            'areas': areas,
        })
        return render_to_response('contact/_state_choices.html',
                                  context_instance=context)
    except AjaxGetStateException, e:
        log.error("ajax_get_state aborting: %s" % e.message)
Пример #4
0
Файл: tests.py Проект: 34/T
 def test_company(self):
     contact = Contact.objects.create()
     data = {
         'email': '*****@*****.**', 'first_name': 'Test', 'last_name': 'Company','phone':'123-111-4411',
         'street1': "56 Cool Lane", 'city': "Niftyville", 'state': "IA", 'postal_code': "12344", 'country': 231,
         'ship_addressee': "Test Company", 'ship_street1': "56 Industry Way", 'ship_city': "Niftytown", 'ship_state': "IA", 'ship_postal_code': "12366", 'ship_country': 231,
         'organization' : 'Testers Anonymous',
         }
     shop = Config.objects.get_current()
     form = ContactInfoForm(data=data, shop=shop, contact=contact)
     #print "ERR: %s" % form.errors
     self.assertEqual(True, form.is_valid())
     contactid = form.save(contact=contact)
     self.assertEqual(contact.id, contactid)
     self.assert_(contact.organization)
     self.assertEqual(contact.organization.name, 'Testers Anonymous')
Пример #5
0
 def test_missing_first_and_last_name_should_not_raise_exception(self):
     shop = Config.objects.get_current()
     form = ContactInfoForm(shop=shop,
                            contact=None,
                            data={'phone': '800-111-9900'})
     self.assertEqual(False, form.is_valid())
Пример #6
0
    def test_country_specific_validation(self):
        shop = Config.objects.get_current()

        # US

        # a valid one
        contact = Contact.objects.create()
        data = {
            'email': '*****@*****.**',
            'first_name': 'Test',
            'last_name': 'McTestalot',
            'phone': '123-111-4411',
            'ship_addressee': 'Test McTestalot',
            'street1': "56 Cool Lane",
            'city': "Niftyville",
            'state': "IA",
            'postal_code': "12344",
            'country': 231,
            'ship_street1': "56 Industry Way",
            'ship_city': "Niftytown",
            'ship_state': "IA",
            'ship_postal_code': "12366",
            'ship_country': 231
        }
        form = ContactInfoForm(data=data, shop=shop, contact=contact)
        self.assertEqual(True, form.is_valid())

        # bad state
        data = {
            'email': '*****@*****.**',
            'first_name': 'Test',
            'last_name': 'McTestalot',
            'phone': '123-111-4411',
            'street1': "56 Cool Lane",
            'city': "Niftyville",
            'state': "ON",
            'postal_code': "12344",
            'country': 231,
            'ship_street1': "56 Industry Way",
            'ship_city': "Niftytown",
            'ship_state': "ON",
            'ship_postal_code': "12366",
            'ship_country': 231
        }
        form = ContactInfoForm(data=data, shop=shop, contact=contact)
        self.assertEqual(False, form.is_valid())

        # Canada
        CA = Country.objects.get(iso2_code__iexact="CA")

        # a valid one
        data = {
            'email': '*****@*****.**',
            'first_name': 'Test',
            'last_name': 'McTestalot',
            'phone': '123-111-4411',
            'ship_addressee': 'Test McTestalot',
            'street1': "301 Front Street West",
            'city': "Toronto",
            'state': "ON",
            'postal_code': "M5V 2T6",
            'country': 39,
            'ship_street1': "301 Front Street West",
            'ship_city': "Toronto",
            'ship_state': "ON",
            'ship_postal_code': "M5V 2T6",
            'ship_country': 39
        }
        form = ContactInfoForm(data=data, shop=shop, contact=contact)
        self.assertEqual(True, form.is_valid())

        # bad province
        data = {
            'email': '*****@*****.**',
            'first_name': 'Test',
            'last_name': 'McTestalot',
            'phone': '123-111-4411',
            'street1': "301 Front Street West",
            'city': "Toronto",
            'state': "NY",
            'postal_code': "M5V 2T6",
            'country': 39,
            'ship_street1': "301 Front Street West",
            'ship_city': "Toronto",
            'ship_state': "NY",
            'ship_postal_code': "M5V 2T6",
            'ship_country': 39
        }
        form = ContactInfoForm(data=data, shop=shop, contact=contact)
        self.assertEqual(False, form.is_valid())

        # bad postal code
        data = {
            'email': '*****@*****.**',
            'first_name': 'Test',
            'last_name': 'McTestalot',
            'phone': '123-111-4411',
            'street1': "301 Front Street West",
            'city': "Toronto",
            'state': "ON",
            'postal_code': "M5V 2TA",
            'country': 39,
            'ship_street1': "301 Front Street West",
            'ship_city': "Toronto",
            'ship_state': "ON",
            'ship_postal_code': "M5V 2TA",
            'ship_country': 39
        }
        form = ContactInfoForm(data=data, shop=shop, contact=contact)
        self.assertEqual(False, form.is_valid())

        # Australia
        AU = Country.objects.get(iso2_code__iexact="AU")

        # a valid one
        data = {
            'email': '*****@*****.**',
            'first_name': 'Test',
            'last_name': 'McTestalot',
            'phone': '123-111-4411',
            'ship_addressee': 'Test McTestalot',
            'street1': "Macquarie Street",
            'city': "Sydney",
            'state': "NSW",
            'postal_code': "2000",
            'country': 14,
            'ship_street1': "Macquarie Street",
            'ship_city': "Sydney",
            'ship_state': "NSW",
            'ship_postal_code': "2000",
            'ship_country': 14
        }
        form = ContactInfoForm(data=data, shop=shop, contact=contact)
        self.assertEqual(True, form.is_valid())

        # bad state
        data = {
            'email': '*****@*****.**',
            'first_name': 'Test',
            'last_name': 'McTestalot',
            'phone': '123-111-4411',
            'ship_addressee': 'Test McTestalot',
            'street1': "Macquarie Street",
            'city': "Sydney",
            'state': "NY",
            'postal_code': "2000",
            'country': 14,
            'ship_street1': "Macquarie Street",
            'ship_city': "Sydney",
            'ship_state': "NY",
            'ship_postal_code': "2000",
            'ship_country': 14
        }
        form = ContactInfoForm(data=data, shop=shop, contact=contact)
        self.assertEqual(False, form.is_valid())

        # bad postal code
        data = {
            'email': '*****@*****.**',
            'first_name': 'Test',
            'last_name': 'McTestalot',
            'phone': '123-111-4411',
            'ship_addressee': 'Test McTestalot',
            'street1': "Macquarie Street",
            'city': "Sydney",
            'state': "NSW",
            'postal_code': "200A",
            'country': 14,
            'ship_street1': "Macquarie Street",
            'ship_city': "Sydney",
            'ship_state': "NSW",
            'ship_postal_code': "200A",
            'ship_country': 14
        }
        form = ContactInfoForm(data=data, shop=shop, contact=contact)
        self.assertEqual(False, form.is_valid())
Пример #7
0
 def test_missing_first_and_last_name_should_not_raise_exception(self):
     shop = Config.objects.get_current()
     form = ContactInfoForm(shop=shop, contact=None, data={"phone": "800-111-9900"})
     self.assertEqual(False, form.is_valid())
Пример #8
0
    def test_country_specific_validation(self):
        shop = Config.objects.get_current()

        # US

        # a valid one
        contact = Contact.objects.create()
        data = {
            "email": "*****@*****.**",
            "first_name": "Test",
            "last_name": "McTestalot",
            "phone": "123-111-4411",
            "street1": "56 Cool Lane",
            "city": "Niftyville",
            "state": "IA",
            "postal_code": "12344",
            "country": 231,
            "ship_street1": "56 Industry Way",
            "ship_city": "Niftytown",
            "ship_state": "IA",
            "ship_postal_code": "12366",
            "ship_country": 231,
        }
        form = ContactInfoForm(data=data, shop=shop, contact=contact)
        self.assertEqual(True, form.is_valid())

        # bad state
        data = {
            "email": "*****@*****.**",
            "first_name": "Test",
            "last_name": "McTestalot",
            "phone": "123-111-4411",
            "street1": "56 Cool Lane",
            "city": "Niftyville",
            "state": "ON",
            "postal_code": "12344",
            "country": 231,
            "ship_street1": "56 Industry Way",
            "ship_city": "Niftytown",
            "ship_state": "ON",
            "ship_postal_code": "12366",
            "ship_country": 231,
        }
        form = ContactInfoForm(data=data, shop=shop, contact=contact)
        self.assertEqual(False, form.is_valid())

        # Canada
        CA = Country.objects.get(iso2_code__iexact="CA")

        # a valid one
        data = {
            "email": "*****@*****.**",
            "first_name": "Test",
            "last_name": "McTestalot",
            "phone": "123-111-4411",
            "street1": "301 Front Street West",
            "city": "Toronto",
            "state": "ON",
            "postal_code": "M5V 2T6",
            "country": 39,
            "ship_street1": "301 Front Street West",
            "ship_city": "Toronto",
            "ship_state": "ON",
            "ship_postal_code": "M5V 2T6",
            "ship_country": 39,
        }
        form = ContactInfoForm(data=data, shop=shop, contact=contact)
        self.assertEqual(True, form.is_valid())

        # bad province
        data = {
            "email": "*****@*****.**",
            "first_name": "Test",
            "last_name": "McTestalot",
            "phone": "123-111-4411",
            "street1": "301 Front Street West",
            "city": "Toronto",
            "state": "NY",
            "postal_code": "M5V 2T6",
            "country": 39,
            "ship_street1": "301 Front Street West",
            "ship_city": "Toronto",
            "ship_state": "NY",
            "ship_postal_code": "M5V 2T6",
            "ship_country": 39,
        }
        form = ContactInfoForm(data=data, shop=shop, contact=contact)
        self.assertEqual(False, form.is_valid())

        # bad postal code
        data = {
            "email": "*****@*****.**",
            "first_name": "Test",
            "last_name": "McTestalot",
            "phone": "123-111-4411",
            "street1": "301 Front Street West",
            "city": "Toronto",
            "state": "ON",
            "postal_code": "M5V 2TA",
            "country": 39,
            "ship_street1": "301 Front Street West",
            "ship_city": "Toronto",
            "ship_state": "ON",
            "ship_postal_code": "M5V 2TA",
            "ship_country": 39,
        }
        form = ContactInfoForm(data=data, shop=shop, contact=contact)
        self.assertEqual(False, form.is_valid())

        # Australia
        AU = Country.objects.get(iso2_code__iexact="AU")

        # a valid one
        data = {
            "email": "*****@*****.**",
            "first_name": "Test",
            "last_name": "McTestalot",
            "phone": "123-111-4411",
            "street1": "Macquarie Street",
            "city": "Sydney",
            "state": "NSW",
            "postal_code": "2000",
            "country": 14,
            "ship_street1": "Macquarie Street",
            "ship_city": "Sydney",
            "ship_state": "NSW",
            "ship_postal_code": "2000",
            "ship_country": 14,
        }
        form = ContactInfoForm(data=data, shop=shop, contact=contact)
        self.assertEqual(True, form.is_valid())

        # bad state
        data = {
            "email": "*****@*****.**",
            "first_name": "Test",
            "last_name": "McTestalot",
            "phone": "123-111-4411",
            "street1": "Macquarie Street",
            "city": "Sydney",
            "state": "NY",
            "postal_code": "2000",
            "country": 14,
            "ship_street1": "Macquarie Street",
            "ship_city": "Sydney",
            "ship_state": "NY",
            "ship_postal_code": "2000",
            "ship_country": 14,
        }
        form = ContactInfoForm(data=data, shop=shop, contact=contact)
        self.assertEqual(False, form.is_valid())

        # bad postal code
        data = {
            "email": "*****@*****.**",
            "first_name": "Test",
            "last_name": "McTestalot",
            "phone": "123-111-4411",
            "street1": "Macquarie Street",
            "city": "Sydney",
            "state": "NSW",
            "postal_code": "200A",
            "country": 14,
            "ship_street1": "Macquarie Street",
            "ship_city": "Sydney",
            "ship_state": "NSW",
            "ship_postal_code": "200A",
            "ship_country": 14,
        }
        form = ContactInfoForm(data=data, shop=shop, contact=contact)
        self.assertEqual(False, form.is_valid())
Пример #9
0
Файл: tests.py Проект: 34/T
    def test_country_specific_validation(self):
        shop = Config.objects.get_current()

        # US

        # a valid one
        contact = Contact.objects.create()
        data = {
            'email': '*****@*****.**', 'first_name': 'Test', 'last_name': 'McTestalot','phone':'123-111-4411',
            'ship_addressee' : 'Test McTestalot', 'street1': "56 Cool Lane", 'city': "Niftyville", 'state': "IA", 'postal_code': "12344", 'country': 231,
            'ship_street1': "56 Industry Way", 'ship_city': "Niftytown", 'ship_state': "IA", 'ship_postal_code': "12366", 'ship_country': 231
            }
        form = ContactInfoForm(data=data, shop=shop, contact=contact)
        self.assertEqual(True, form.is_valid())

        # bad state
        data = {
            'email': '*****@*****.**', 'first_name': 'Test', 'last_name': 'McTestalot','phone':'123-111-4411',

            'street1': "56 Cool Lane", 'city': "Niftyville", 'state': "ON", 'postal_code': "12344", 'country': 231,
            'ship_street1': "56 Industry Way", 'ship_city': "Niftytown", 'ship_state': "ON", 'ship_postal_code': "12366", 'ship_country': 231
            }
        form = ContactInfoForm(data=data, shop=shop, contact=contact)
        self.assertEqual(False, form.is_valid())

        # Canada
        CA = Country.objects.get(iso2_code__iexact="CA")

        # a valid one
        data = {
            'email': '*****@*****.**', 'first_name': 'Test', 'last_name': 'McTestalot','phone':'123-111-4411',
            'ship_addressee' : 'Test McTestalot',
            'street1': "301 Front Street West", 'city': "Toronto", 'state': "ON", 'postal_code': "M5V 2T6", 'country': 39,
            'ship_street1': "301 Front Street West", 'ship_city': "Toronto", 'ship_state': "ON", 'ship_postal_code': "M5V 2T6", 'ship_country': 39
            }
        form = ContactInfoForm(data=data, shop=shop, contact=contact)
        self.assertEqual(True, form.is_valid())

        # bad province
        data = {
            'email': '*****@*****.**', 'first_name': 'Test', 'last_name': 'McTestalot','phone':'123-111-4411',

            'street1': "301 Front Street West", 'city': "Toronto", 'state': "NY", 'postal_code': "M5V 2T6", 'country': 39,
            'ship_street1': "301 Front Street West", 'ship_city': "Toronto", 'ship_state': "NY", 'ship_postal_code': "M5V 2T6", 'ship_country': 39
            }
        form = ContactInfoForm(data=data, shop=shop, contact=contact)
        self.assertEqual(False, form.is_valid())

        # bad postal code
        data = {
            'email': '*****@*****.**', 'first_name': 'Test', 'last_name': 'McTestalot','phone':'123-111-4411',

            'street1': "301 Front Street West", 'city': "Toronto", 'state': "ON", 'postal_code': "M5V 2TA", 'country': 39,
            'ship_street1': "301 Front Street West", 'ship_city': "Toronto", 'ship_state': "ON", 'ship_postal_code': "M5V 2TA", 'ship_country': 39
            }
        form = ContactInfoForm(data=data, shop=shop, contact=contact)
        self.assertEqual(False, form.is_valid())

        # Australia
        AU = Country.objects.get(iso2_code__iexact="AU")

        # a valid one
        data = {
            'email': '*****@*****.**', 'first_name': 'Test', 'last_name': 'McTestalot','phone':'123-111-4411',
            'ship_addressee' : 'Test McTestalot',
            'street1': "Macquarie Street", 'city': "Sydney", 'state': "NSW", 'postal_code': "2000", 'country': 14,
            'ship_street1': "Macquarie Street", 'ship_city': "Sydney", 'ship_state': "NSW", 'ship_postal_code': "2000", 'ship_country': 14
            }
        form = ContactInfoForm(data=data, shop=shop, contact=contact)
        self.assertEqual(True, form.is_valid())

        # bad state
        data = {
            'email': '*****@*****.**', 'first_name': 'Test', 'last_name': 'McTestalot','phone':'123-111-4411',
            'ship_addressee' : 'Test McTestalot',
            'street1': "Macquarie Street", 'city': "Sydney", 'state': "NY", 'postal_code': "2000", 'country': 14,
            'ship_street1': "Macquarie Street", 'ship_city': "Sydney", 'ship_state': "NY", 'ship_postal_code': "2000", 'ship_country': 14
            }
        form = ContactInfoForm(data=data, shop=shop, contact=contact)
        self.assertEqual(False, form.is_valid())

        # bad postal code
        data = {
            'email': '*****@*****.**', 'first_name': 'Test', 'last_name': 'McTestalot','phone':'123-111-4411',
            'ship_addressee' : 'Test McTestalot',
            'street1': "Macquarie Street", 'city': "Sydney", 'state': "NSW", 'postal_code': "200A", 'country': 14,
            'ship_street1': "Macquarie Street", 'ship_city': "Sydney", 'ship_state': "NSW", 'ship_postal_code': "200A", 'ship_country': 14
            }
        form = ContactInfoForm(data=data, shop=shop, contact=contact)
        self.assertEqual(False, form.is_valid())