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
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