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 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.assertEquals(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.assertEquals(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.assertEquals("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.assertEquals("", self.product.description)

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

    def test_num_in_stock_is_imported(self):
        stockrecord = self.product.stockrecords.all()[0]
        self.assertEquals(6, stockrecord.num_in_stock)
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.assertEquals(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.assertEquals(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.assertEquals("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.assertEquals("", self.product.description)

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

    def test_num_in_stock_is_imported(self):
        stockrecord = self.product.stockrecords.all()[0]
        self.assertEquals(6, stockrecord.num_in_stock)
示例#4
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)
示例#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 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(ImportError):
            self.importer.handle()

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

    def test_importing_nonexistant_file_raises_exception(self):
        self.importer.afile = "/tmp/catalogue-import.zgvsfsdfsd"
        with self.assertRaises(ImportError):
            self.importer.handle()
示例#7
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(ImportError):
            self.importer.handle()

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

    def test_importing_nonexistant_file_raises_exception(self):
        self.importer.afile = "/tmp/catalogue-import.zgvsfsdfsd"
        with self.assertRaises(ImportError):
            self.importer.handle()
 def setUp(self):
     self.importer = CatalogueImporter(logger)
     self.importer.handle(TEST_BOOKS_CSV)
     self.product = Product.objects.get(upc='9780115531446')
 def setUp(self):
     self.importer = CatalogueImporter(logger)
 def setUp(self):
     self.importer = CatalogueImporter(logger, flush=True)
 def setUp(self):
     self.importer = CatalogueImporter(logger, delimiter=";")
示例#12
0
 def setUp(self):
     self.importer = CatalogueImporter(logger)
     self.importer.handle(TEST_BOOKS_CSV)
     self.item = Product.objects.get(upc='9780115531446')
示例#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
class ImportSemicolonDelimitedFileTest(TestCase):
    def setUp(self):
        self.importer = CatalogueImporter(logger, delimiter=";")

    def test_import(self):
        self.importer.handle(TEST_BOOKS_SEMICOLON_CSV)