def test_call_with_invalid_job_file_id(self): result = tasks.import_product_migrations( job_file_id=9999, 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_product_migrations( job_file_id=9999, 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_invalid_file_format(self): jf = JobFile.objects.create( file=SimpleUploadedFile("myfile.xlsx", b"xyz")) expected_message = "import failed, invalid file format (" result = tasks.import_product_migrations( job_file_id=jf.id, 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_product_migrations( job_file_id=jf.id, user_for_revision=User.objects.get(username="******") ) assert "error_message" in result assert result["error_message"].startswith(expected_message)
def test_successful_full_import_product_migration_task(self, monkeypatch): # replace the ProductMigrationsExcelImporter class monkeypatch.setattr(tasks, "ProductMigrationsExcelImporter", BaseProductMigrationsExcelImporterMock) mixer.blend("productdb.Product", product_id="Product A", vendor=Vendor.objects.get(id=1)) jf = JobFile.objects.create(file=SimpleUploadedFile("myfile.xlsx", b"xyz")) result = tasks.import_product_migrations( job_file_id=jf.id, 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 ProductMigrationSource.objects.count() == 2, "One Product Migration Source was created" assert ProductMigrationOption.objects.count() == 2, "One Product Migration Option was created"
def test_successful_full_import_product_migration_task(self, monkeypatch): # replace the ProductMigrationsExcelImporter class monkeypatch.setattr(tasks, "ProductMigrationsExcelImporter", BaseProductMigrationsExcelImporterMock) models.Product.objects.create(product_id="Product A", vendor=models.Vendor.objects.get(id=1)) jf = models.JobFile.objects.create( file=SimpleUploadedFile("myfile.xlsx", b"xyz")) result = tasks.import_product_migrations( job_file_id=jf.id, user_for_revision=User.objects.get(username="******")) assert "status_message" in result, "If successful, a status message should be returned" assert models.JobFile.objects.count( ) == 0, "Should be deleted after the task was completed" assert models.ProductMigrationSource.objects.count( ) == 2, "One Product Migration Source was created" assert models.ProductMigrationOption.objects.count( ) == 2, "One Product Migration Option was created"