Commit d48df337 authored by Evili del Rio's avatar Evili del Rio

Cleanup code. 100% coverage

parent a386d291
......@@ -2,5 +2,6 @@
omit =
# omit anything in a .env directory anywhere
*/.env*/*
*/env*/*
/usr/*
*/site-packages/*
......@@ -13,13 +13,13 @@ class BasicUrlsTest(unittest.TestCase):
resp = self.visit_view('health')
self.assertEqual(200, resp.status_code, "No health page")
def test_login(self):
resp = self.visit_view('login')
self.assertEqual(200, resp.status_code, "No login page")
# def test_login(self):
# resp = self.visit_view('login')
# self.assertEqual(200, resp.status_code, "No login page")
# def test_logout(self):
# resp = self.visit_view('logout')
# self.assertEqual(200, resp.status_code, "No logout page")
# resp = self.visit_view('logout')
# self.assertEqual(200, resp.status_code, "No logout page")
# def test_password_change(self):
# resp = self.visit_view('password_change')
......@@ -32,7 +32,7 @@ class BasicUrlsTest(unittest.TestCase):
# def test_password_reset(self):
# resp = self.visit_view('password_reset')
# self.assertEqual(200, resp.status_code, "No password reset page")
# def test_password_reset_done(self):
# resp = self.visit_view('password_reset_done')
# self.assertEqual(200, resp.status_code, "No password reset-done page")
......
......@@ -96,23 +96,17 @@ class Species(BaseName):
"""
cn = self.sci_name()
try:
loc = get_language()
except:
loc = settings.LANGUAGE_CODE
loc = get_language()
try:
lang = Locale.objects.get(locale=loc)
except:
loc = loc.replace('-', '_').split('_')[0]
try:
loc = loc.replace('-', '_').split('_')[0]
lang = Locale.objects.get(locale=loc)
except:
pass
lang, created = Locale.objects.get_or_create(locale='en')
try:
lang = Locale.objects.get(locale=loc)
except:
lang, created = Locale.objects.get_or_create(locale='en')
try:
cn = self.commonname_set.get(locale=lang).cname
except:
......@@ -120,8 +114,6 @@ class Species(BaseName):
return cn
def __unicode__(self):
return self.__str__()
class Meta:
ordering = ['genus', 'name']
......@@ -138,7 +130,7 @@ class CommonName(models.Model):
species = models.ForeignKey(Species, on_delete=models.PROTECT)
locale = models.ForeignKey(Locale, on_delete=models.PROTECT)
def __unicode__(self):
def __str__(self):
return u'{0} ({1})'.format(self.cname, self.species.sci_name())
class Meta:
......
from django.test import TransactionTestCase
from django.utils import translation
from .models import Kingdom, Phylum, Classe, Ordo, Family, Genus, Species, CommonName, Locale
......@@ -111,3 +112,41 @@ class CommonNameTest(CladesTest):
'Fallback common name "%s" is not scientific name "%s"' % (
cn, sn)
)
def test_common_name_no_variant(self):
from django.conf import settings
cat_ad = u'ca_AD'
settings.LANGUAGE_CODE = cat_ad
from django.utils import translation
translation.activate(cat_ad)
cn = str(self.species)
cat_name = self.common_name['ca'].cname
self.assertEqual(cn, cat_name,
'%s should be named %s' % (cn, cat_name))
def test_common_name_unknown_locale(self):
from django.conf import settings
# set default to a missing cn
esperanto_st = u'eo'
settings.LANGUAGE_CODE = esperanto_st
from django.utils import translation
translation.activate(esperanto_st)
cn = str(self.species)
translation.activate(u'en')
en = str(self.species)
self.assertEqual(
cn,
en,
'Fallback common name "%s" is not english name "%s"' % (
cn, en)
)
def test_common_name_string(self):
st_cn = str(CommonName.objects.get(species=self.species, locale=Locale.objects.get(locale='ca')))
ca_cn = '%s (%s)' % (self.common_name['ca'].cname, self.species.sci_name())
self.assertEquals(st_cn, ca_cn, 'Common name string should be "%s", not "%s"' % (st_cn, ca_cn))
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment