import pytest
from mock import Mock

from saleor.core.utils import (
    Country, get_country_by_ip, get_currency_for_country)


@pytest.mark.parametrize('ip_data, expected_country', [
    ({'country': {'iso_code': 'PL'}}, Country('PL')),
    ({'country': {'iso_code': 'UNKNOWN'}}, None),
    (None, None),
    ({}, None),
    ({'country': {}}, None)])
def test_get_country_by_ip(ip_data, expected_country, monkeypatch):
    monkeypatch.setattr(
        'saleor.core.utils.georeader.get',
        Mock(return_value=ip_data))
    country = get_country_by_ip('127.0.0.1')
    assert country == expected_country


@pytest.mark.parametrize('country, expected_currency', [
    (Country('PL'), 'PLN'),
    (Country('US'), 'USD'),
    (Country('GB'), 'GBP')])
def test_get_currency_for_country(country, expected_currency, monkeypatch):
    currency = get_currency_for_country(country)
    assert currency == expected_currency

@@ -118,17 +118,78 @@
 _country
-)
+, create_superuser)%0Afrom saleor.userprofile.models import User
 %0A%0A%0A@pyte
@@ -973,8 +973,720 @@
 urrency%0A
+%0A%0Adef test_create_superuser(db, client):%0A    credentials = %7B'email': 'admin@example.com', 'password': 'admin'%7D%0A    # Test admin creation%0A    assert User.objects.all().count() == 0%0A    create_superuser(credentials)%0A    assert User.objects.all().count() == 1%0A    admin = User.objects.all().first()%0A    assert admin.is_superuser%0A    # Test duplicating%0A    create_superuser(credentials)%0A    assert User.objects.all().count() == 1%0A    # Test logging in%0A    response = client.post('/account/login/',%0A                           %7B'login': credentials%5B'email'%5D,%0A                            'password': credentials%5B'password'%5D%7D,%0A                           follow=True)%0A    assert response.context%5B'request'%5D.user == admin%0A

Add populatedb admin creation test