Skip to content

Commit

Permalink
Test 64% of dictionary views
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 f0a5bbf commit 57cc54b
Showing 1 changed file with 61 additions and 0 deletions.
61 changes: 61 additions & 0 deletions dictionary/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,3 +143,64 @@ class DictionaryConfigTest(TestCase):
def test_apps(self):
self.assertEqual(DictionaryConfig.name, 'dictionary')
self.assertEqual(apps.get_app_config('dictionary').name, 'dictionary')


# Views

class AuthenticateTest(TestCase):

def test_authenticate(self):
user_ip_correct = config('ALLOWED_IP_LIST')[0]
result = authenticate(user_ip_correct)
self.assertTrue(result)

user_ip_wrong = 'wrong_ip'
result = authenticate(user_ip_wrong)
self.assertFalse(result)


class DeleteWordKokama(TestCase):

def setUp(self):
# Create WordKokama
pronunciation = PronunciationType.objects.create(pronunciation_type=PRONUNCIATION_TYPE)
kokama_word = WordKokama.objects.create(
word_kokama=KOKAMA_WORD,
pronunciation_type=pronunciation
)
# Create PhrasePortuguese
portuguese_phrase = PhrasePortuguese.objects.create(phrase_portuguese=PORTUGUESE_PHRASE)
# Create PhraseKokama
PhraseKokama.objects.create(
phrase_kokama=KOKAMA_PHRASE,
word_kokama=kokama_word,
phrase_portuguese=portuguese_phrase,
)
# Create WordPortuguese
portuguese_word = WordPortuguese.objects.create(word_portuguese=PORTUGUESE_WORD)
# Create Translate
Translate.objects.create(
word_portuguese=portuguese_word,
word_kokama=kokama_word,
)
kokama_word.translations.add(portuguese_word)

def test_delete_word_kokama(self):
kokama_word = WordKokama.objects.get(word_kokama=KOKAMA_WORD)
delete_word_kokama(kokama_word)
self.assertFalse(WordKokama.objects.filter(word_kokama=str(kokama_word)).exists())


class WordListViewSetTest(TestCase):

def setUp(self):
self.factory = RequestFactory()
self.request_wrong = self.factory.delete('/1/')
self.request_correct = self.factory.delete('/1/', REMOTE_ADDR=config('ALLOWED_IP_LIST'))

def test_destroy(self):
response = WordListViewSet.destroy(WordListViewSet, self.request_wrong)
self.assertEqual(response.status_code, 403)

response = WordListViewSet.destroy(WordListViewSet, self.request_correct)
self.assertEqual(response.status_code, 500)

0 comments on commit 57cc54b

Please sign in to comment.