Skip to content

Commit

Permalink
Finish testing models
Browse files Browse the repository at this point in the history
Co-authored-by: laispa <[email protected]>
  • Loading branch information
luisgaboardi and laispa committed May 12, 2021
1 parent 1a3e4e2 commit f0a5bbf
Showing 1 changed file with 100 additions and 2 deletions.
102 changes: 100 additions & 2 deletions dictionary/tests.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
from django.test import TestCase
from dictionary.models import WordPortuguese, PronunciationType, PhrasePortuguese
from django.test import TestCase, RequestFactory
from dictionary.models import WordPortuguese, PronunciationType, PhrasePortuguese, WordKokama, Translate, PhraseKokama
from django.apps import apps
from .apps import DictionaryConfig
from .views import authenticate, delete_word_kokama, WordListViewSet
from decouple import config


PORTUGUESE_WORD = 'portuguese word'
PRONUNCIATION_TYPE = 'both'
PORTUGUESE_PHRASE = 'portuguese phrase'
KOKAMA_WORD = 'kokama word'
KOKAMA_PHRASE = 'kokama phrase'


class WordPortugueseModelTest(TestCase):
def setUp(self):
Expand Down Expand Up @@ -45,3 +52,94 @@ def setUp(self):
def test_phrase_portuguese_str(self):
portuguese_phrase = PhrasePortuguese.objects.get(phrase_portuguese=PORTUGUESE_PHRASE)
self.assertEqual(str(portuguese_phrase), PORTUGUESE_PHRASE)


class WordKokamaModelTest(TestCase):
def setUp(self):
pronunciation = PronunciationType.objects.create(pronunciation_type=PRONUNCIATION_TYPE)
WordKokama.objects.create(
word_kokama=KOKAMA_WORD,
pronunciation_type=pronunciation
)

def test_word_kokama_str(self):
kokama_word = WordKokama.objects.get(
word_kokama=KOKAMA_WORD,
pronunciation_type=PronunciationType.objects.get(pronunciation_type=PRONUNCIATION_TYPE)
)
self.assertEqual(str(kokama_word), KOKAMA_WORD)

def test_word_kokama_length(self):
kokama_word_correct = WordKokama.objects.get(
word_kokama=KOKAMA_WORD,
pronunciation_type=PronunciationType.objects.get(pronunciation_type=PRONUNCIATION_TYPE)
)
self.assertLessEqual(len(kokama_word_correct.word_kokama), 50)

kokama_word_wrong = WordKokama.objects.create(
word_kokama='kokama word with more than max_length(fifty) characters in it',
pronunciation_type=PronunciationType.objects.get(pronunciation_type=PRONUNCIATION_TYPE)
)
self.assertGreater(len(kokama_word_wrong.word_kokama), 50)


class TranslateModelTest(TestCase):

def setUp(self):
kokama_word = WordKokama.objects.create(
word_kokama=KOKAMA_WORD,
pronunciation_type=PronunciationType.objects.create(pronunciation_type=PRONUNCIATION_TYPE)
)
portuguese_word = WordPortuguese.objects.create(word_portuguese=PORTUGUESE_WORD)
Translate.objects.create(
word_portuguese=portuguese_word,
word_kokama=kokama_word,
)

def test_translate_str(self):
kokama_word = WordKokama.objects.get(
word_kokama=KOKAMA_WORD,
pronunciation_type=PronunciationType.objects.get(pronunciation_type=PRONUNCIATION_TYPE)
)
portuguese_word = WordPortuguese.objects.get(word_portuguese=PORTUGUESE_WORD)
translate = Translate.objects.get(
word_portuguese=portuguese_word,
word_kokama=kokama_word
)

self.assertEqual(str(translate), '%s <-> %s' % (KOKAMA_WORD, PORTUGUESE_WORD))


class PhraseKokamaModelTest(TestCase):
def setUp(self):
kokama_word = WordKokama.objects.create(
word_kokama=KOKAMA_WORD,
pronunciation_type=PronunciationType.objects.create(pronunciation_type=PRONUNCIATION_TYPE)
)
portuguese_phrase = PhrasePortuguese.objects.create(phrase_portuguese=PORTUGUESE_PHRASE)
PhraseKokama.objects.create(
phrase_kokama=KOKAMA_PHRASE,
word_kokama=kokama_word,
phrase_portuguese=portuguese_phrase,
)

def test_phrase_kokama_str(self):
kokama_word = WordKokama.objects.get(
word_kokama=KOKAMA_WORD,
pronunciation_type=PronunciationType.objects.get(pronunciation_type=PRONUNCIATION_TYPE)
)
portuguese_phrase = PhrasePortuguese.objects.get(phrase_portuguese=PORTUGUESE_PHRASE)
kokama_phrase = PhraseKokama.objects.create(
phrase_kokama=KOKAMA_PHRASE,
word_kokama=kokama_word,
phrase_portuguese=portuguese_phrase,
)

self.assertEqual(str(kokama_phrase), KOKAMA_PHRASE)


class DictionaryConfigTest(TestCase):

def test_apps(self):
self.assertEqual(DictionaryConfig.name, 'dictionary')
self.assertEqual(apps.get_app_config('dictionary').name, 'dictionary')

0 comments on commit f0a5bbf

Please sign in to comment.