44 lines
1.2 KiB
Python
44 lines
1.2 KiB
Python
# -*- coding: utf-8; -*-
|
|
|
|
from __future__ import unicode_literals, absolute_import
|
|
|
|
from unittest import TestCase
|
|
|
|
import six
|
|
|
|
from rattail import products as mod
|
|
from rattail.config import make_config
|
|
from rattail.gpc import GPC
|
|
|
|
|
|
class TestProductsHandler(TestCase):
|
|
|
|
def setUp(self):
|
|
self.config = self.make_config()
|
|
self.handler = self.make_handler()
|
|
|
|
def make_config(self):
|
|
return make_config([], extend=False)
|
|
|
|
def make_handler(self):
|
|
return mod.ProductsHandler(self.config)
|
|
|
|
def test_make_gpc(self):
|
|
|
|
# basic real-world example
|
|
result = self.handler.make_gpc('74305001321')
|
|
self.assertIsInstance(result, GPC)
|
|
self.assertEqual(six.text_type(result), '00074305001321')
|
|
|
|
# and let it calculate check digit
|
|
result = self.handler.make_gpc('7430500132', calc_check_digit='upc')
|
|
self.assertIsInstance(result, GPC)
|
|
self.assertEqual(six.text_type(result), '00074305001321')
|
|
|
|
# bad one should raise error
|
|
self.assertRaises(ValueError, self.handler.make_gpc, 'BAD_VALUE')
|
|
|
|
# unless we suppress errors
|
|
result = self.handler.make_gpc('BAD_VALUE', ignore_errors=True)
|
|
self.assertIsNone(result)
|