Пример #1
0
class StyleDB:
    def __init__(self):
        self.cache = StyleCache('src/abv/inventory_api/beer_styles.csv')
        self.brew_db = BreweryDBQueries()

    def get_style(self, beer_name):
        beer_name = beer_name.title()
        if self.cache.look_up(beer_name) is not None:
            return self.cache.cache_dict[beer_name]
        try:
            style = self.brew_db.get_beer_style(beer_name)
            self.cache.add(beer_name, style)
            return style
        # pylint: disable=broad-except
        except Exception:
            return 'Unknown'
Пример #2
0
def test_add_beer():
    temp_file = tempfile.NamedTemporaryFile(dir='tests/sample_csv_files',
                                            prefix='b')
    test_cache = StyleCache(temp_file.name)
    test_cache.add("Rude Elf Reserve", "Belgian")
    assert test_cache.look_up("Rude Elf Reserve") == "Belgian"
Пример #3
0
def test_invalid_beer_lookup():
    test_cache = StyleCache("tests/sample_csv_files/beer_and_style.csv")
    assert test_cache.look_up("Rude Elf Reserve") is None
Пример #4
0
def test_can_read_and_lookup():
    test_cache = StyleCache("tests/sample_csv_files/beer_and_style.csv")
    assert test_cache.look_up("Guinness") == "Stout"
    assert test_cache.look_up("Pabst Blue Ribbon") == "Lager"
    assert test_cache.look_up("Fat Tire") == "Belgian Ale"