def test_notification_message_on_import_price_list_task(self, monkeypatch):
        # replace the ProductsExcelImporter class
        monkeypatch.setattr(tasks, "ProductsExcelImporter", BaseProductsExcelImporterMock)

        jf = JobFile.objects.create(file=SimpleUploadedFile("myfile.xlsx", b"xyz"))
        result = tasks.import_price_list(
            job_file_id=jf.id,
            create_notification_on_server=False,
            update_only=False,
            user_for_revision=User.objects.get(username="******")
        )

        assert "status_message" in result, "If successful, a status message should be returned"
        assert NotificationMessage.objects.count() == 0, "No notification message is created"
        assert JobFile.objects.count() == 0, "Should be deleted after the task was completed"

        jf = JobFile.objects.create(file=SimpleUploadedFile("myfile.xlsx", b"xyz"))
        result = tasks.import_price_list(
            job_file_id=jf.id,
            create_notification_on_server=True,
            update_only=False,
            user_for_revision=User.objects.get(username="******")
        )

        assert "status_message" in result
        assert NotificationMessage.objects.count() == 1
        assert JobFile.objects.count() == 0, "Should be deleted after the task was completed"
Example #2
0
    def test_notification_message_on_import_price_list_task(self, monkeypatch):
        # replace the ProductsExcelImporter class
        monkeypatch.setattr(tasks, "ProductsExcelImporter",
                            BaseProductsExcelImporterMock)

        jf = JobFile.objects.create(
            file=SimpleUploadedFile("myfile.xlsx", b"xyz"))
        result = tasks.import_price_list(
            job_file_id=jf.id,
            create_notification_on_server=False,
            update_only=False,
            user_for_revision=User.objects.get(username="******"))

        assert "status_message" in result, "If successful, a status message should be returned"
        assert NotificationMessage.objects.count(
        ) == 0, "No notification message is created"
        assert JobFile.objects.count(
        ) == 0, "Should be deleted after the task was completed"

        jf = JobFile.objects.create(
            file=SimpleUploadedFile("myfile.xlsx", b"xyz"))
        result = tasks.import_price_list(
            job_file_id=jf.id,
            create_notification_on_server=True,
            update_only=False,
            user_for_revision=User.objects.get(username="******"))

        assert "status_message" in result
        assert NotificationMessage.objects.count() == 1
        assert JobFile.objects.count(
        ) == 0, "Should be deleted after the task was completed"
    def test_successful_update_only_import_price_list_task(self, monkeypatch):
        # replace the ProductsExcelImporter class
        monkeypatch.setattr(tasks, "ProductsExcelImporter", BaseProductsExcelImporterMock)

        # import in update only mode
        jf = JobFile.objects.create(file=SimpleUploadedFile("myfile.xlsx", b"xyz"))
        result = tasks.import_price_list(
            job_file_id=jf.id,
            create_notification_on_server=True,
            update_only=True,
            user_for_revision=User.objects.get(username="******")
        )

        assert "status_message" in result, "If successful, a status message should be returned"
        assert JobFile.objects.count() == 0, "Should be deleted after the task was completed"
        assert Product.objects.count() == 0, "One Product was created"

        # create the product
        Product.objects.create(product_id="Product A")

        jf = JobFile.objects.create(file=SimpleUploadedFile("myfile.xlsx", b"xyz"))
        result = tasks.import_price_list(
            job_file_id=jf.id,
            create_notification_on_server=True,
            update_only=True,
            user_for_revision=User.objects.get(username="******")
        )

        assert "status_message" in result, "If successful, a status message should be returned"
        assert JobFile.objects.count() == 0, "Should be deleted after the task was completed"
        assert Product.objects.count() == 1, "One Product was created"
        p = Product.objects.get(product_id="Product A")
        assert "description of Product A" == p.description
Example #4
0
    def test_call_with_invalid_job_file_id(self):
        result = tasks.import_price_list(
            job_file_id=9999,
            create_notification_on_server=True,
            update_only=False,
            user_for_revision=User.objects.get(username="******"))

        assert "error_message" in result
        assert "Cannot find file that was uploaded." == result["error_message"]
    def test_call_with_invalid_job_file_id(self):
        result = tasks.import_price_list(
            job_file_id=9999,
            create_notification_on_server=True,
            update_only=False,
            user_for_revision=User.objects.get(username="******")
        )

        assert "error_message" in result
        assert "Cannot find file that was uploaded." == result["error_message"]
Example #6
0
    def test_call_with_invalid_invalid_file_format(self):
        jf = JobFile.objects.create(
            file=SimpleUploadedFile("myfile.xlsx", b"xyz"))
        expected_message = "import failed, invalid file format ("

        result = tasks.import_price_list(
            job_file_id=jf.id,
            create_notification_on_server=False,
            update_only=False,
            user_for_revision=User.objects.get(username="******"))

        assert "error_message" in result
        assert result["error_message"].startswith(expected_message)
    def test_call_with_invalid_invalid_file_format(self):
        jf = JobFile.objects.create(file=SimpleUploadedFile("myfile.xlsx", b"xyz"))
        expected_message = "import failed, invalid file format ("

        result = tasks.import_price_list(
            job_file_id=jf.id,
            create_notification_on_server=False,
            update_only=False,
            user_for_revision=User.objects.get(username="******")
        )

        assert "error_message" in result
        assert result["error_message"].startswith(expected_message)
Example #8
0
    def test_successful_update_only_import_price_list_task(self, monkeypatch):
        # replace the ProductsExcelImporter class
        monkeypatch.setattr(tasks, "ProductsExcelImporter",
                            BaseProductsExcelImporterMock)

        # import in update only mode
        jf = JobFile.objects.create(
            file=SimpleUploadedFile("myfile.xlsx", b"xyz"))
        result = tasks.import_price_list(
            job_file_id=jf.id,
            create_notification_on_server=True,
            update_only=True,
            user_for_revision=User.objects.get(username="******"))

        assert "status_message" in result, "If successful, a status message should be returned"
        assert JobFile.objects.count(
        ) == 0, "Should be deleted after the task was completed"
        assert Product.objects.count() == 0, "One Product was created"

        # create the product
        Product.objects.create(
            product_id="Product A",
            vendor=Vendor.objects.get(name__startswith="Cisco"))

        jf = JobFile.objects.create(
            file=SimpleUploadedFile("myfile.xlsx", b"xyz"))
        result = tasks.import_price_list(
            job_file_id=jf.id,
            create_notification_on_server=True,
            update_only=True,
            user_for_revision=User.objects.get(username="******"))

        assert "status_message" in result, "If successful, a status message should be returned"
        assert JobFile.objects.count(
        ) == 0, "Should be deleted after the task was completed"
        assert Product.objects.count() == 1, "One Product was created"
        p = Product.objects.get(product_id="Product A")
        assert "description of Product A" == p.description
    def test_call_with_invalid_products(self, monkeypatch):
        # replace the ProductsExcelImporter class
        monkeypatch.setattr(tasks, "ProductsExcelImporter", InvalidProductsImportProductsExcelFileMock)

        jf = JobFile.objects.create(file=SimpleUploadedFile("myfile.xlsx", b"xyz"))
        expected_message = "100 entries are invalid. Please check the following messages for more details."
        result = tasks.import_price_list(
            job_file_id=jf.id,
            create_notification_on_server=False,
            update_only=False,
            user_for_revision=User.objects.get(username="******")
        )

        assert "status_message" in result
        assert expected_message in result["status_message"]
Example #10
0
    def test_call_with_invalid_products(self, monkeypatch):
        # replace the ProductsExcelImporter class
        monkeypatch.setattr(tasks, "ProductsExcelImporter",
                            InvalidProductsImportProductsExcelFileMock)

        jf = JobFile.objects.create(
            file=SimpleUploadedFile("myfile.xlsx", b"xyz"))
        expected_message = "100 entries are invalid. Please check the following messages for more details."
        result = tasks.import_price_list(
            job_file_id=jf.id,
            create_notification_on_server=False,
            update_only=False,
            user_for_revision=User.objects.get(username="******"))

        assert "status_message" in result
        assert expected_message in result["status_message"]