summaryrefslogtreecommitdiff
path: root/tests/test_cards.py
blob: 605984bc3e5d45b068492522d62e8baaaa67c1c3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
import json
import unittest
from unittest.mock import patch, mock_open

from swiftstory.cards import Cards


class TestCards(unittest.TestCase):
    def test_get_cards_supported_language(self):
        white_cards = json.dumps([
            "White Card 1", "White Card 2",
            "White Card 3", "White Card 4",
        ])
        black_cards = json.dumps(["Black Card 1", "Black Card 2"])

        with patch("swiftstory.cards.pkg_resources.resource_stream", mock_open(read_data=white_cards)):
            self.assertIn("White Card 2", Cards.get_white_cards("en"))
        with patch("swiftstory.cards.pkg_resources.resource_stream", mock_open(read_data=black_cards)):
            self.assertIn("Black Card 1", Cards.get_black_cards("en"))

    def test_get_cards_unknown_language(self):
        with patch("swiftstory.cards.pkg_resources.resource_stream", side_effect=FileNotFoundError):
            with self.assertRaises(FileNotFoundError):
                Cards.get_white_cards("zz")
            with self.assertRaises(FileNotFoundError):
                Cards.get_black_cards("zz")