Files
@ cf4902b6480a
Branch filter:
Location: rattail-project/rattail/tests/autocomplete/test_products.py - annotation
cf4902b6480a
5.0 KiB
text/x-python
Do not allow executing custorder batch if no customer set
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 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 | 84ed805e2250 84ed805e2250 84ed805e2250 84ed805e2250 84ed805e2250 84ed805e2250 84ed805e2250 84ed805e2250 84ed805e2250 84ed805e2250 84ed805e2250 84ed805e2250 84ed805e2250 84ed805e2250 84ed805e2250 84ed805e2250 84ed805e2250 84ed805e2250 84ed805e2250 84ed805e2250 84ed805e2250 84ed805e2250 84ed805e2250 84ed805e2250 84ed805e2250 84ed805e2250 84ed805e2250 84ed805e2250 84ed805e2250 84ed805e2250 84ed805e2250 84ed805e2250 84ed805e2250 84ed805e2250 84ed805e2250 84ed805e2250 84ed805e2250 84ed805e2250 84ed805e2250 84ed805e2250 84ed805e2250 84ed805e2250 84ed805e2250 84ed805e2250 84ed805e2250 84ed805e2250 84ed805e2250 84ed805e2250 84ed805e2250 84ed805e2250 84ed805e2250 84ed805e2250 84ed805e2250 84ed805e2250 84ed805e2250 84ed805e2250 84ed805e2250 84ed805e2250 84ed805e2250 84ed805e2250 84ed805e2250 84ed805e2250 84ed805e2250 84ed805e2250 84ed805e2250 84ed805e2250 84ed805e2250 84ed805e2250 84ed805e2250 84ed805e2250 84ed805e2250 84ed805e2250 84ed805e2250 84ed805e2250 84ed805e2250 84ed805e2250 84ed805e2250 84ed805e2250 84ed805e2250 84ed805e2250 84ed805e2250 84ed805e2250 84ed805e2250 84ed805e2250 84ed805e2250 84ed805e2250 84ed805e2250 84ed805e2250 84ed805e2250 84ed805e2250 84ed805e2250 84ed805e2250 84ed805e2250 84ed805e2250 84ed805e2250 84ed805e2250 84ed805e2250 84ed805e2250 84ed805e2250 84ed805e2250 84ed805e2250 84ed805e2250 84ed805e2250 84ed805e2250 84ed805e2250 84ed805e2250 84ed805e2250 84ed805e2250 84ed805e2250 84ed805e2250 84ed805e2250 84ed805e2250 84ed805e2250 84ed805e2250 84ed805e2250 84ed805e2250 84ed805e2250 84ed805e2250 84ed805e2250 84ed805e2250 84ed805e2250 84ed805e2250 84ed805e2250 84ed805e2250 84ed805e2250 84ed805e2250 84ed805e2250 84ed805e2250 84ed805e2250 84ed805e2250 84ed805e2250 84ed805e2250 84ed805e2250 84ed805e2250 84ed805e2250 84ed805e2250 84ed805e2250 84ed805e2250 84ed805e2250 84ed805e2250 84ed805e2250 84ed805e2250 84ed805e2250 84ed805e2250 84ed805e2250 | # -*- coding: utf-8; -*-
from __future__ import unicode_literals, absolute_import
from unittest import TestCase
import sqlalchemy as sa
from rattail.autocomplete import products as mod
from rattail.config import make_config
from rattail.db import Session
class AutocompleterTestCase(TestCase):
def setUp(self):
self.config = self.make_config()
self.autocompleter = self.make_autocompleter()
self.engine = sa.create_engine('sqlite://')
self.model = self.config.get_model()
self.model.Base.metadata.create_all(bind=self.engine)
self.session = Session(bind=self.engine)
def tearDown(self):
self.session.rollback()
self.session.close()
def make_config(self):
return make_config([], extend=False)
class TestProductAutocompleter(AutocompleterTestCase):
def make_autocompleter(self):
return mod.ProductAutocompleter(self.config)
def test_autocomplete(self):
session = self.session
model = self.model
# first create a few products
vinegar = model.Product(description='Apple Cider Vinegar')
session.add(vinegar)
dressing = model.Product(description='Apple Cider Dressing')
session.add(dressing)
oats = model.Product(description='Bulk Oats')
session.add(oats)
deleted = model.Product(description='More Oats', deleted=True)
session.add(deleted)
# searching for nothing yields no results
result = self.autocompleter.autocomplete(session, '')
self.assertEqual(len(result), 0)
# search for 'apple' yields Vinegar, Dressing
result = self.autocompleter.autocomplete(session, 'apple')
self.assertEqual(len(result), 2)
uuids = [info['value'] for info in result]
self.assertIn(vinegar.uuid, uuids)
self.assertIn(dressing.uuid, uuids)
# search for 'oats' yields just the undeleted product
result = self.autocompleter.autocomplete(session, 'oats')
self.assertEqual(len(result), 1)
self.assertEqual(result[0]['value'], oats.uuid)
class TestProductAllAutocompleter(AutocompleterTestCase):
def make_autocompleter(self):
return mod.ProductAllAutocompleter(self.config)
def test_autocomplete(self):
session = self.session
model = self.model
# first create a few products
vinegar = model.Product(description='Apple Cider Vinegar')
session.add(vinegar)
dressing = model.Product(description='Apple Cider Dressing')
session.add(dressing)
oats = model.Product(description='Bulk Oats')
session.add(oats)
deleted = model.Product(description='More Oats', deleted=True)
session.add(deleted)
# searching for nothing yields no results
result = self.autocompleter.autocomplete(session, '')
self.assertEqual(len(result), 0)
# search for 'apple' yields Vinegar, Dressing
result = self.autocompleter.autocomplete(session, 'apple')
self.assertEqual(len(result), 2)
uuids = [info['value'] for info in result]
self.assertIn(vinegar.uuid, uuids)
self.assertIn(dressing.uuid, uuids)
# search for 'oats' yields Bulk, More
result = self.autocompleter.autocomplete(session, 'oats')
self.assertEqual(len(result), 2)
uuids = [info['value'] for info in result]
self.assertIn(oats.uuid, uuids)
self.assertIn(deleted.uuid, uuids)
class TestProductNewOrderAutocompleter(AutocompleterTestCase):
def make_autocompleter(self):
return mod.ProductNewOrderAutocompleter(self.config)
def test_autocomplete(self):
session = self.session
model = self.model
# first create a few products
vinegar = model.Product(description='Apple Cider Vinegar',
upc='074305001321')
session.add(vinegar)
dressing = model.Product(description='Apple Cider Dressing')
session.add(dressing)
oats = model.Product(description='Bulk Oats')
session.add(oats)
deleted = model.Product(description='More Oats', deleted=True)
session.add(deleted)
# searching for nothing yields no results
result = self.autocompleter.autocomplete(session, '')
self.assertEqual(len(result), 0)
# search for 'apple' yields Vinegar, Dressing
result = self.autocompleter.autocomplete(session, 'apple')
self.assertEqual(len(result), 2)
uuids = [info['value'] for info in result]
self.assertIn(vinegar.uuid, uuids)
self.assertIn(dressing.uuid, uuids)
# search for unknown upc yields no results
result = self.autocompleter.autocomplete(session, '7430500116')
self.assertEqual(len(result), 0)
# search for known upc yields just that product
result = self.autocompleter.autocomplete(session, '7430500132')
self.assertEqual(len(result), 1)
self.assertEqual(result[0]['value'], vinegar.uuid)
|