def test_init(self):
     pddb = product_details.ProductDetails(
         storage_class='product_details.storage.PDDatabaseStorage')
     ok_(isinstance(pddb._storage, storage.PDDatabaseStorage))
     pdfs = product_details.ProductDetails(
         storage_class='product_details.storage.PDFileStorage')
     ok_(isinstance(pdfs._storage, storage.PDFileStorage))
Esempio n. 2
0
def test_init():
    with patch.object(product_details, 'get_django_cache') as cache_mock:
        pd = product_details.ProductDetails()
    eq_(pd.json_dir, settings_fallback('PROD_DETAILS_DIR'))
    eq_(pd.cache_timeout, settings_fallback('PROD_DETAILS_CACHE_TIMEOUT'))
    cache_mock.assert_called_with(settings_fallback('PROD_DETAILS_CACHE_NAME'))

    with patch.object(product_details, 'get_django_cache') as cache_mock:
        pd = product_details.ProductDetails(json_dir='walter',
                                            cache_name='donny',
                                            cache_timeout=2)

    eq_(pd.json_dir, 'walter')
    eq_(pd.cache_timeout, 2)
    cache_mock.assert_called_with('donny')
Esempio n. 3
0
def test_regions():
    """Make sure regions still work"""
    pd = product_details.ProductDetails()
    good_data = {'dude': 'abide'}
    pd._get_json_data = Mock(return_value=good_data)
    eq_(pd.get_regions('de'), good_data)
    pd._get_json_data.assert_called_with('regions/de')
Esempio n. 4
0
def test_no_cache_missing_files(open_mock):
    """The fact that a file doesn't exist should not be cached."""
    open_mock.side_effect = IOError
    pd = product_details.ProductDetails()
    pd.clear_cache()
    ok_(isinstance(pd.the_dude, defaultdict))
    ok_(isinstance(pd.the_dude, defaultdict))
    eq_(open_mock.call_count, 2)
Esempio n. 5
0
def test_no_cache_corrupt_files(load_mock, open_mock):
    """The fact that a file doesn't parse correctly should not be cached."""
    load_mock.side_effect = ValueError
    pd = product_details.ProductDetails()
    pd.clear_cache()
    ok_(isinstance(pd.the_dude, defaultdict))
    ok_(isinstance(pd.the_dude, defaultdict))
    load_mock.assert_called_with(open_mock.return_value.__enter__.return_value)
    eq_(load_mock.call_count, 2)
Esempio n. 6
0
def test_cache_delete():
    pd = product_details.ProductDetails()
    pd.clear_cache()
    good_data = {'dude': 'abiding'}
    pd._get_json_file_data = Mock(return_value=good_data)
    eq_(pd.the_dude, good_data)
    eq_(pd.the_dude, good_data)
    pd.delete_cache('the_dude')
    eq_(pd.the_dude, good_data)
    eq_(pd.the_dude, good_data)
    pd._get_json_file_data.assert_called_with('the_dude')
    eq_(pd._get_json_file_data.call_count, 2)
Esempio n. 7
0
def test_cache():
    pd = product_details.ProductDetails()
    pd.clear_cache()
    good_data = {'dude': 'abiding'}
    pd._get_json_file_data = Mock(return_value=good_data)
    eq_(pd.the_dude, good_data)
    eq_(pd.the_dude, good_data)
    pd._get_json_file_data.assert_called_once_with('the_dude')

    # make sure the cache returns what was put in
    more_good_data = {'walter': 'finishing his coffee'}
    pd._get_json_file_data = Mock(return_value=more_good_data)
    eq_(pd.dammit_walter, more_good_data)
    eq_(pd.dammit_walter, more_good_data)
    pd._get_json_file_data.assert_called_once_with('dammit_walter')