More tests for country
This commit is contained in:
@@ -5,8 +5,11 @@ from sqlalchemy_utils import i18n
|
|||||||
|
|
||||||
|
|
||||||
class Country(object):
|
class Country(object):
|
||||||
def __init__(self, code):
|
def __init__(self, code_or_country):
|
||||||
self.code = code
|
if isinstance(code_or_country, Country):
|
||||||
|
self.code = code_or_country.code
|
||||||
|
else:
|
||||||
|
self.code = code_or_country
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def name(self):
|
def name(self):
|
||||||
@@ -15,6 +18,8 @@ class Country(object):
|
|||||||
def __eq__(self, other):
|
def __eq__(self, other):
|
||||||
if isinstance(other, Country):
|
if isinstance(other, Country):
|
||||||
return self.code == other.code
|
return self.code == other.code
|
||||||
|
elif isinstance(other, six.string_types):
|
||||||
|
return self.code == other
|
||||||
else:
|
else:
|
||||||
return NotImplemented
|
return NotImplemented
|
||||||
|
|
||||||
|
@@ -13,6 +13,16 @@ def get_locale():
|
|||||||
i18n.get_locale = get_locale
|
i18n.get_locale = get_locale
|
||||||
|
|
||||||
|
|
||||||
|
class TestCountry(object):
|
||||||
|
def test_init(self):
|
||||||
|
assert Country(u'fi') == Country(Country(u'fi'))
|
||||||
|
|
||||||
|
def test_equality_operator(self):
|
||||||
|
assert Country(u'fi') == u'fi'
|
||||||
|
assert u'fi' == Country(u'fi')
|
||||||
|
assert Country(u'fi') == Country(u'fi')
|
||||||
|
|
||||||
|
|
||||||
class TestCountryType(TestCase):
|
class TestCountryType(TestCase):
|
||||||
def create_models(self):
|
def create_models(self):
|
||||||
class User(self.Base):
|
class User(self.Base):
|
||||||
|
Reference in New Issue
Block a user