Пример #1
0
    def test_LoadOperationLoader_does_not_truncate_or_write_headers_on_resume(
        self, dict_writer
    ):
        ex = {
            "version": 1,
            "operation": [
                {
                    "sobject": "Account",
                    "fields": ["Name"],
                    "extract": {"all": True},
                    "input-validation": "none",
                }
            ],
        }

        context = loader.LoadOperationLoader(ex, MockConnection(), True)
        m = unittest.mock.mock_open()
        with unittest.mock.patch("builtins.open", m):
            context.load()

        self.assertEqual([], context.errors)
        self.assertIsInstance(context.result, amaxa.LoadOperation)

        m.assert_has_calls(
            [
                unittest.mock.call("Account.csv", "r"),
                unittest.mock.call("Account-results.csv", "a", newline=""),
            ],
            any_order=True,
        )
        dict_writer.assert_not_called()
Пример #2
0
    def _run_success_test(self, ex, mock_conn=None, input_data=None):
        context = loader.LoadOperationLoader(ex, mock_conn or MockConnection())

        self._mock_execute(context, input_data)

        self.assertEqual([], context.errors)
        self.assertIsInstance(context.result, amaxa.LoadOperation)

        return context.result
Пример #3
0
    def _run_error_validating_test(
        self, ex, error_list, mock_conn=None, input_data=None
    ):
        context = loader.LoadOperationLoader(ex, mock_conn or MockConnection())

        self._mock_execute(context, input_data)

        self.assertEqual(error_list, context.errors)
        self.assertIsNone(context.result)
Пример #4
0
    def test_LoadOperationLoader_creates_valid_steps_with_files(self):
        context = amaxa.LoadOperation(MockConnection())
        context.add_dependency = Mock()

        ex = {
            "version": 1,
            "operation": [
                {
                    "sobject": "Account",
                    "fields": ["Name"],
                    "extract": {"all": True},
                    "input-validation": "none",
                },
                {
                    "sobject": "Contact",
                    "fields": ["LastName"],
                    "extract": {"all": True},
                    "input-validation": "none",
                },
                {
                    "sobject": "Opportunity",
                    "fields": ["StageName"],
                    "extract": {"all": True},
                    "input-validation": "none",
                },
                {
                    "sobject": "Task",
                    "fields": ["Subject"],
                    "extract": {"all": True},
                    "input-validation": "none",
                },
            ],
        }

        context = loader.LoadOperationLoader(ex, MockConnection())
        m = unittest.mock.mock_open()
        with unittest.mock.patch("builtins.open", m):
            context.load()

        self.assertEqual([], context.errors)
        self.assertIsInstance(context.result, amaxa.LoadOperation)

        m.assert_has_calls(
            [
                unittest.mock.call("Account.csv", "r"),
                unittest.mock.call("Contact.csv", "r"),
                unittest.mock.call("Opportunity.csv", "r"),
                unittest.mock.call("Task.csv", "r"),
                unittest.mock.call("Account-results.csv", "w", newline=""),
                unittest.mock.call("Contact-results.csv", "w", newline=""),
                unittest.mock.call("Opportunity-results.csv", "w", newline=""),
                unittest.mock.call("Task-results.csv", "w", newline=""),
            ],
            any_order=True,
        )

        self.assertEqual(4, len(context.result.steps))
        self.assertEqual("Account", context.result.steps[0].sobjectname)
        self.assertEqual("Contact", context.result.steps[1].sobjectname)
        self.assertEqual("Opportunity", context.result.steps[2].sobjectname)
        self.assertEqual("Task", context.result.steps[3].sobjectname)