Files
@ c19d359c2e7d
Branch filter:
Location: rattail-project/rattail/tests/vendors/test_handler.py
c19d359c2e7d
4.1 KiB
text/x-python
bump: version 0.18.11 → 0.18.12
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 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 | # -*- coding: utf-8; -*-
from unittest import TestCase
import pytest
from rattail.vendors import handler as mod
from rattail.vendors.catalogs import CatalogParserNotFound
from rattail.config import make_config
from rattail.db import Session
class TestVendorHandler(TestCase):
def setUp(self):
self.config = self.make_config()
self.app = self.config.get_app()
self.handler = self.make_handler()
def make_config(self):
return make_config([], extend=False)
def make_handler(self):
return mod.VendorHandler(self.config)
def test_choice_uses_dropdown(self):
# do not use dropdown by default
result = self.handler.choice_uses_dropdown()
self.assertFalse(result)
# but do use dropdown if so configured
self.config.setdefault('rattail', 'vendors.choice_uses_dropdown',
'true')
result = self.handler.choice_uses_dropdown()
self.assertTrue(result)
def test_get_vendor(self):
try:
import sqlalchemy as sa
except ImportError:
pytest.skip("test is not relevant without sqlalchemy")
engine = sa.create_engine('sqlite://')
model = self.app.model
model.Base.metadata.create_all(bind=engine)
session = Session(bind=engine)
app = self.config.get_app()
# no vendor if none exist yet!
result = self.handler.get_vendor(session, 'acme')
self.assertIsNone(result)
# let's make the vendor and make sure uuid fetch works
uuid = app.make_uuid()
acme = model.Vendor(uuid=uuid, name="Acme")
session.add(acme)
result = self.handler.get_vendor(session, uuid)
self.assertIs(result, acme)
# if we search by key it still does not work
result = self.handler.get_vendor(session, 'acme')
self.assertIsNone(result)
# but we can configure the key reference, then it will
setting = model.Setting(name='rattail.vendor.acme', value=uuid)
session.add(setting)
result = self.handler.get_vendor(session, 'acme')
self.assertIs(result, acme)
def test_get_all_catalog_parsers(self):
# some are always installed; make sure they come back
Parsers = self.handler.get_all_catalog_parsers()
self.assertTrue(len(Parsers))
def test_get_supported_catalog_parsers(self):
# by default all parsers are considered supported, so these
# calls should effectively yield the same result
all_parsers = self.handler.get_all_catalog_parsers()
supported = self.handler.get_supported_catalog_parsers()
self.assertEqual(len(all_parsers), len(supported))
# now pretend only one is supported, using legacy setting
self.config.setdefault('tailbone', 'batch.vendorcatalog.supported_parsers',
'rattail.contrib.generic')
supported = self.handler.get_supported_catalog_parsers()
self.assertEqual(len(supported), 1)
Parser = supported[0]
self.assertEqual(Parser.key, 'rattail.contrib.generic')
# now pretend two are supported, using preferred setting
self.config.setdefault('rattail', 'vendors.supported_catalog_parsers',
'rattail.contrib.generic, rattail.contrib.kehe')
supported = self.handler.get_supported_catalog_parsers()
self.assertEqual(len(supported), 2)
keys = [Parser.key for Parser in supported]
self.assertEqual(keys, ['rattail.contrib.generic', 'rattail.contrib.kehe'])
def test_get_catalog_parser(self):
# generic parser comes back fine
parser = self.handler.get_catalog_parser('rattail.contrib.generic')
self.assertIsNotNone(parser)
self.assertEqual(parser.key, 'rattail.contrib.generic')
# unknown key returns nothing
parser = self.handler.get_catalog_parser('this_should_not_exist')
self.assertIsNone(parser)
# and can raise an error if we require
self.assertRaises(CatalogParserNotFound, self.handler.get_catalog_parser,
'this_should_not_exist', require=True)
|