old_contents: # encoding: utf-8
  from __future__ import unicode_literals
  
  import i18naddress
  import pytest
  
  from saleor.userprofile import forms, models
  
  
  @pytest.fixture
  def billing_address(db):
      return models.Address.objects.create(
          first_name='John', last_name='Doe',
          company_name='Mirumee Software',
          street_address_1='Tęczowa 7',
          city='Wrocław',
          postal_code='53-601',
          country='PL')
  
  
  @pytest.mark.parametrize('country', ['CN', 'PL', 'US'])
  def test_address_form_for_country(country):
      data = {
          'first_name': 'John',
          'last_name': 'Doe',
          'country': country}
      form = forms.get_address_form(data, country_code=country)[0]
      errors = form.errors
      rules = i18naddress.get_validation_rules({'country_code': country})
      required = rules.required_fields
      if 'street_address' in required:
          assert 'street_address_1' in errors
      else:
          assert 'street_address_1' not in errors
      if 'city' in required:
          assert 'city' in errors
      else:
          assert 'city' not in errors
      if 'city_area' in required:
          assert 'city_area' in errors
      else:
          assert 'city_area' not in errors
      if 'country_area' in required:
          assert 'country_area' in errors
      else:
          assert 'country_area' not in errors
      if 'postal_code' in required:
          assert 'postal_code' in errors
      else:
          assert 'postal_code' not in errors
  
  
  def test_address_form_postal_code_validation():
      data = {
          'first_name': 'John',
          'last_name': 'Doe',
          'country': 'PL',
          'postal_code': 'XXX'}
      form = forms.get_address_form(data, country_code='PL')[0]
      errors = form.errors
      assert 'postal_code' in errors
  
new_contents: # encoding: utf-8
  from __future__ import unicode_literals
  
  import urllib
  
  import i18naddress
  import pytest
  from django.http import QueryDict
  
  from saleor.userprofile import forms, models
  
  
  @pytest.fixture
  def billing_address(db):
      return models.Address.objects.create(
          first_name='John', last_name='Doe',
          company_name='Mirumee Software',
          street_address_1='Tęczowa 7',
          city='Wrocław',
          postal_code='53-601',
          country='PL')
  
  
  @pytest.mark.parametrize('country', ['CN', 'PL', 'US'])
  def test_address_form_for_country(country):
      data = {
          'first_name': 'John',
          'last_name': 'Doe',
          'country': country}
      form = forms.get_address_form(data, country_code=country)[0]
      errors = form.errors
      rules = i18naddress.get_validation_rules({'country_code': country})
      required = rules.required_fields
      if 'street_address' in required:
          assert 'street_address_1' in errors
      else:
          assert 'street_address_1' not in errors
      if 'city' in required:
          assert 'city' in errors
      else:
          assert 'city' not in errors
      if 'city_area' in required:
          assert 'city_area' in errors
      else:
          assert 'city_area' not in errors
      if 'country_area' in required:
          assert 'country_area' in errors
      else:
          assert 'country_area' not in errors
      if 'postal_code' in required:
          assert 'postal_code' in errors
      else:
          assert 'postal_code' not in errors
  
  
  def test_address_form_postal_code_validation():
      data = {
          'first_name': 'John',
          'last_name': 'Doe',
          'country': 'PL',
          'postal_code': 'XXX'}
      form = forms.get_address_form(data, country_code='PL')[0]
      errors = form.errors
      assert 'postal_code' in errors
  
  @pytest.mark.parametrize('form_data, form_valid, expected_preview, expected_country',[
      ({'preview': True}, False, True, 'PL'),
      ({'preview': False,
        'street_address_1': 'Foo bar',
        'postal_code': '00-123',
        'city': 'Warsaw'
        }, True, False, 'PL'),
      ({'preview': True, 'country': 'US'}, False, True, 'US'),
      ({'preview': False,
        'street_address_1': 'Foo bar',
        'postal_code': '0213',
        'city': 'Warsaw'
        }, False, False, 'PL'),
  ])
  def test_get_address_form(form_data, form_valid, expected_preview, expected_country):
      data = {
          'first_name': 'John',
          'last_name': 'Doe',
          'country': 'PL'}
      data.update(form_data)
      query_dict = urllib.urlencode(data)
      form, preview = forms.get_address_form(
          data=QueryDict(query_dict), country_code=data['country'])
      assert preview is expected_preview
      assert form.is_valid() is form_valid
      assert form.i18n_country_code == expected_country
  
subject: Add more tests to i18n logic