예제 #1
0
class ImportSemicolonDelimitedFileTest(TestCase):

    def setUp(self):
        self.importer = CatalogueImporter(logger, delimiter=";")

    def test_import(self):
        self.importer.handle(TEST_BOOKS_SEMICOLON_CSV)
예제 #2
0
class ImportSemicolonDelimitedFileTest(TestCase):

    def setUp(self):
        self.importer = CatalogueImporter(logger, delimiter=";")

    def test_import(self):
        self.importer.handle(TEST_BOOKS_SEMICOLON_CSV)
예제 #3
0
class ImportSmokeTest(TestCase):

    # First row is:
    # "9780115531446","Prepare for Your Practical Driving Test",NULL,"Book","Gardners","9780115531446","10.32","6"
    #
    # Second row is (has no stock data):
    # "9780955337819","Better Photography",NULL,"Book"

    def setUp(self):
        self.importer = CatalogueImporter(logger)
        self.importer.handle(TEST_BOOKS_CSV)
        self.product = Product.objects.get(upc='9780115531446')

    def test_all_rows_are_imported(self):
        self.assertEqual(10, Product.objects.all().count())

    def test_class_is_created(self):
        try:
            ProductClass.objects.get(name="Book")
        except Product.DoesNotExist:
            self.fail()

    def test_only_one_class_is_created(self):
        self.assertEqual(1, ProductClass.objects.all().count())

    def test_item_is_created(self):
        try:
            Product.objects.get(upc="9780115531446")
        except Product.DoesNotExist:
            self.fail()

    def test_title_is_imported(self):
        self.assertEqual("Prepare for Your Practical Driving Test",
                         self.product.title)

    def test_partner_is_created(self):
        try:
            Partner.objects.get(name="Gardners")
        except Product.DoesNotExist:
            self.fail()

    def test_stockrecord_is_created(self):
        try:
            StockRecord.objects.get(partner_sku="9780115531446")
        except Product.DoesNotExist:
            self.fail()

    def test_null_fields_are_skipped(self):
        self.assertEqual("", self.product.description)

    def test_price_is_imported(self):
        stockrecord = self.product.stockrecords.all()[0]
        self.assertEqual(D('10.32'), stockrecord.price)

    def test_num_in_stock_is_imported(self):
        stockrecord = self.product.stockrecords.all()[0]
        self.assertEqual(6, stockrecord.num_in_stock)
예제 #4
0
class ImportSmokeTest(TestCase):

    # First row is:
    # "9780115531446","Prepare for Your Practical Driving Test",NULL,"Book","Gardners","9780115531446","10.32","6"
    #
    # Second row is (has no stock data):
    # "9780955337819","Better Photography",NULL,"Book"

    def setUp(self):
        self.importer = CatalogueImporter(logger)
        self.importer.handle(TEST_BOOKS_CSV)
        self.product = Product.objects.get(upc='9780115531446')

    def test_all_rows_are_imported(self):
        self.assertEqual(10, Product.objects.all().count())

    def test_class_is_created(self):
        try:
            ProductClass.objects.get(name="Book")
        except Product.DoesNotExist:
            self.fail()

    def test_only_one_class_is_created(self):
        self.assertEqual(1, ProductClass.objects.all().count())

    def test_item_is_created(self):
        try:
            Product.objects.get(upc="9780115531446")
        except Product.DoesNotExist:
            self.fail()

    def test_title_is_imported(self):
        self.assertEqual("Prepare for Your Practical Driving Test", self.product.title)

    def test_partner_is_created(self):
        try:
            Partner.objects.get(name="Gardners")
        except Product.DoesNotExist:
            self.fail()

    def test_stockrecord_is_created(self):
        try:
            StockRecord.objects.get(partner_sku="9780115531446")
        except Product.DoesNotExist:
            self.fail()

    def test_null_fields_are_skipped(self):
        self.assertEqual("", self.product.description)

    def test_price_is_imported(self):
        stockrecord = self.product.stockrecords.all()[0]
        self.assertEqual(D('10.32'), stockrecord.price_excl_tax)

    def test_num_in_stock_is_imported(self):
        stockrecord = self.product.stockrecords.all()[0]
        self.assertEqual(6, stockrecord.num_in_stock)
예제 #5
0
class ImportWithFlushTest(TestCase):
    def setUp(self):
        self.importer = CatalogueImporter(logger, flush=True)

    def test_items_are_flushed_by_importer(self):
        upc = "0000000000000"
        create_product(price=D('10.00'), upc=upc)

        self.importer.handle(TEST_BOOKS_CSV)

        with self.assertRaises(Product.DoesNotExist):
            Product.objects.get(upc=upc)
예제 #6
0
class ImportWithFlushTest(TestCase):

    def setUp(self):
        self.importer = CatalogueImporter(logger, flush=True)

    def test_items_are_flushed_by_importer(self):
        upc = "0000000000000"
        create_product(price=D('10.00'), upc=upc)

        self.importer.handle(TEST_BOOKS_CSV)

        with self.assertRaises(Product.DoesNotExist):
            Product.objects.get(upc=upc)
예제 #7
0
def add_partner_information(product, partner_code, price_purchase, price_sell):
    '''
	Deze methode voegt de prijsinformatie toe aan een product door gebruik te maken van de Partner app
	'''

    partner = Partner.objects.get_or_create(name='Eigen stock')

    price = price_sell  #.replace(',', '.')

    print('---- prijs %s' % price)

    if price != '':

        importer = CatalogueImporter(logger=None)

        importer._create_stockrecord(item=product,
                                     partner_name=partner[0],
                                     partner_sku=partner_code,
                                     price_excl_tax=price,
                                     num_in_stock=0,
                                     stats=None)
예제 #8
0
class CommandEdgeCasesTest(TestCase):
    def setUp(self):
        self.importer = CatalogueImporter(logger)

    def test_sending_no_file_argument_raises_exception(self):
        self.importer.afile = None
        with self.assertRaises(ImportingError):
            self.importer.handle()

    def test_sending_directory_as_file_raises_exception(self):
        self.importer.afile = "/tmp"
        with self.assertRaises(ImportingError):
            self.importer.handle()

    def test_importing_nonexistant_file_raises_exception(self):
        self.importer.afile = "/tmp/catalogue-import.zgvsfsdfsd"
        with self.assertRaises(ImportingError):
            self.importer.handle()
예제 #9
0
class CommandEdgeCasesTest(TestCase):

    def setUp(self):
        self.importer = CatalogueImporter(logger)

    def test_sending_no_file_argument_raises_exception(self):
        self.importer.afile = None
        with self.assertRaises(ImportingError):
            self.importer.handle()

    def test_sending_directory_as_file_raises_exception(self):
        self.importer.afile = "/tmp"
        with self.assertRaises(ImportingError):
            self.importer.handle()

    def test_importing_nonexistant_file_raises_exception(self):
        self.importer.afile = "/tmp/catalogue-import.zgvsfsdfsd"
        with self.assertRaises(ImportingError):
            self.importer.handle()
예제 #10
0
 def setUp(self):
     self.importer = CatalogueImporter(logger)
예제 #11
0
 def setUp(self):
     self.importer = CatalogueImporter(logger, flush=True)
예제 #12
0
 def setUp(self):
     self.importer = CatalogueImporter(logger, delimiter=";")
예제 #13
0
 def setUp(self):
     self.importer = CatalogueImporter(logger)
예제 #14
0
 def setUp(self):
     self.importer = CatalogueImporter(logger, flush=True)
예제 #15
0
 def setUp(self):
     self.importer = CatalogueImporter(logger, delimiter=";")
예제 #16
0
 def setUp(self):
     self.importer = CatalogueImporter(logger)
     self.importer.handle(TEST_BOOKS_CSV)
     self.product = Product.objects.get(upc='9780115531446')
예제 #17
0
 def setUp(self):
     self.importer = CatalogueImporter(logger)
     self.importer.handle(TEST_BOOKS_CSV)
     self.product = Product.objects.get(upc='9780115531446')