Пример #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_two_against_db():
    styles = StyleDB()
    styles.cache = StyleCache('tests/sample_csv_files/beer_and_style.csv')
    styles.brew_db = mock_brewery_db.MockDB()
    assert styles.get_style('xyz') == "Unknown"
    assert styles.get_style('xyz') == "Unknown"
    assert styles.brew_db.count == 2
Пример #3
0
def test_unknown_from_db_then_cache():
    styles = StyleDB()
    styles.cache = StyleCache('tests/sample_csv_files/beer_and_style.csv')
    styles.brew_db = mock_brewery_db.MockDB()
    assert styles.get_style('Duck Tails') == 'Unknown'
    assert styles.get_style('Duck Tails') == 'Unknown'
    assert styles.brew_db.count == 0
Пример #4
0
def test_db_has_style_and_then_cache():
    styles = StyleDB()
    styles.cache = StyleCache('tests/sample_csv_files/beer_and_style.csv')
    styles.brew_db = mock_brewery_db.MockDB()
    assert styles.get_style('Guinness') == 'Stout'
    assert styles.get_style('Guinness') == 'Stout'
    assert styles.brew_db.count == 0
Пример #5
0
def test_blank_file():
    test_cache = StyleCache("beer_data/empty.csv")
    print(test_cache.cache_dict)
    assert test_cache.cache_dict == {}
Пример #6
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"
Пример #7
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
Пример #8
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"
Пример #9
0
 def __init__(self):
     self.cache = StyleCache('src/abv/inventory_api/beer_styles.csv')
     self.brew_db = BreweryDBQueries()
Пример #10
0
def test_cache_has_beer():
    styles = StyleDB()
    styles.cache = StyleCache('tests/sample_csv_files/beer_and_style.csv')
    styles.brew_db = mock_brewery_db.MockDB()
    assert styles.get_style('Nitro') == 'Stout'
    assert styles.brew_db.count == 0