def test_cards_guess_and_set_category(admin): """ Should guess and set the word category """ card = Card() card.word = 'word' card.created_by = admin card.save() assert card.category == 'word' card = Card() card.word = 'come up with' card.created_by = admin card.save() assert card.category == 'phrasal_verb' card = Card() card.word = 'get over' card.created_by = admin card.save() assert card.category == 'phrasal_verb' card = Card() card.word = 'to put it mildly' card.created_by = admin card.save() assert card.category == 'phrase'
def test_cards_get_random_words(admin): """ Test the select_random_words method """ with pytest.raises(ValueError) as error: Card.objects.select_random_words() assert error == 'the user and words fields are empty at the same time' words = Card.objects.select_random_words(admin) assert len(words) == 2 random_words = Card.objects.get_random_words(admin) words = Card.objects.select_random_words(words=random_words, additional='additional') assert len(words) == 2 for i in range(10): card = Card() card.word = 'word' + str(i) card.complete = 122 card.created_by = admin card.deck_id = 1 card.save() words = Card.objects.select_random_words(admin, additional='additional') words_next = Card.objects.select_random_words(admin, additional='additional') assert len(words) == 4 assert words != words_next assert 'additional' in words
def test_cards_default_deck(admin): """ Should set the default deck for user """ card = Card() card.word = 'word' card.created_by = admin card.save() assert card.deck_id == 1
def test_cards_limit_complete_deck(admin): """ The card complete field can't be less then zero """ card = Card() card.word = 'word' card.complete = 122 card.created_by = admin card.deck_id = 1 card.save() assert card.complete == 100 card.complete = -23 card.save() assert card.complete == 0