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

Use proper environment db settings

parent 2295f17d
......@@ -91,6 +91,9 @@ test:
stage: test
image: gliderlabs/herokuish:latest
script:
- printenv
- alias
- set -x
- setup_test_db
- cp -R . /tmp/app
- /bin/herokuish paths
......
import os
from . import *
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql',
'NAME': 'ci',
'USER': 'postgres',
'PASSWORD': 'postgres',
'HOST': 'postgres',
'PORT': '5432',
'ENGINE': 'django.db.backends.postgresql',
'NAME': os.environ.get('POSTGRES_DB','test'),
'USER': os.environ.get('POSTGRES_USER', 'postgres'),
'PASSWORD': os.environ.get('POSTGRES_PASSWORD', 'postgres'),
'HOST': os.environ.get('POSTGRES_HOST', 'postgres'),
'PORT': os.environ.get('POSTGRES_PORT', '5432'),
},
}
......@@ -39,13 +39,14 @@ class Family(BaseName):
class Genus(BaseName):
family = models.ForeignKey(Family)
class LocaleManager(models.Manager):
"""Model Manger for available Locales"""
@staticmethod
def enabled_locales():
"""Work with enabled languages only."""
return zip(*settings.LANGUAGES)[0]
return settings.LANGUAGES
def get_queryset(self):
return super(LocaleManager, self).get_queryset().filter(
......
from django.test import TestCase
from .models import Kingdom, Phylum, Classe, Family
from .models import Kingdom, Phylum, Classe, Ordo, Family, Genus, Species, CommonName, Locale
_KINGDOM_NAME = u'Animalia'
_PHYLUM_NAME = u'Chordata'
_CLASSE_NAME = u'Aves'
_FAMILY_NAME = u'Passeriformes'
_ORDO_NAME = u'Passeriformes'
_FAMILY_NAME = u'Paridae'
_GENUS_NAME = u'Periparus'
_SPECIES_NAME = u'ater'
_COMMON_NAME = {
u'ca': u'Mallerenga Petita',
u'en': u'Coal Tit',
}
class CladesTest(TestCase):
......@@ -18,9 +25,28 @@ class CladesTest(TestCase):
(self.classe, created) = Classe.objects.get_or_create(
name=_CLASSE_NAME,
phylum=self.phylum)
(self.ordo, created) = Ordo.objects.get_or_create(
name=_ORDO_NAME,
classe=self.classe)
(self.family, created) = Family.objects.get_or_create(
name=_FAMILY_NAME,
classe=self.classe)
ordo=self.ordo)
(self.genus, created) = Genus.objects.get_or_create(
name=_GENUS_NAME,
family=self.family)
(self.species, created) = Species.objects.get_or_create(
name=_GENUS_NAME,
genus=self.genus)
self.locale = {}
self.common_name = {}
for lc, cn in _COMMON_NAME.items():
print("======================> LOCALE:", lc)
(self.locale[lc], created) = Locale.objects.get_or_create(locale=lc)
(self.common_name[lc], created) = CommonName.objects.get_or_create(
cname=cn,
locale=self.locale[lc],
species=self.species
)
class KingdomTest(CladesTest):
def test_kingdom_name(self):
......@@ -40,7 +66,36 @@ class ClasseTest(CladesTest):
classe = Classe.objects.get(name=_CLASSE_NAME)
self.assertEqual(classe.phylum, self.phylum)
class OrdoTest(CladesTest):
def test_ordo_has_classe(self):
ordo = Ordo.objects.get(name=_ORDO_NAME)
self.assertEqual(ordo.classe, self.classe)
class FamilyTest(CladesTest):
def test_family_has_classe(self):
def test_family_has_ordo(self):
family = Family.objects.get(name=_FAMILY_NAME)
self.assertEqual(family.classe, self.classe)
self.assertEqual(family.ordo, self.ordo)
class GenusTest(CladesTest):
def test_genus_has_family(self):
genus = Genus.objects.get(name=_GENUS_NAME)
self.assertEqual(genus.family, self.family)
class SpeciesTest(CladesTest):
def test_species_has_genus(self):
species = Species.objects.get(name=_SPECIES_NAME)
self.assertEqual(species.genus, self.genus)
class CommonNameTest(CladesTest):
def test_common_name_has_species(self):
common_name = CommonName.objects.get(cname=_COMMON_NAME['ca'])
self.assertEqual(common_name.species, self.species)
def test_common_name_no_local(self):
from django.conf import settings
# set default to a missing cn
settings.LANGUAGE_CODE = u'eo'
self.assertEqual(self.species,
self.species.sci_name(),
'Fallback common name is not scientific name ' % (str(self.species), self.species.sci_name() )
)
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