Ejemplo n.º 1
0
    def test_load(self):
        """tests load method"""

        mock_run_statement = MagicMock()
        PostgreSqlDatabase.run_statement = mock_run_statement

        config = MagicMock()
        config.schema = self.schema
        config.data = self.data
        fixture = PostgreSqlFixture(config=config)

        fixture.load()

        # Brittle way of testing that insert statement is run
        # Assumes the keys of first row in self.data are the fields to insert
        data_row = self.data[0]
        stmnt_fields, expected_statement = PostgreSqlInsertStatementMixin.create_insert_statement(
            table=self.schema.config.get_table(),
            fields=list(data_row.keys()),
            statement_string=True)

        expected_params = [data_row[field] for field in stmnt_fields]

        mock_run_statement.assert_called_with(expected_statement,
                                              params=expected_params,
                                              commit=True)
    def test_load(self):
        """tests load method"""

        mock_run_statement = MagicMock()
        PostgreSqlDatabase.run_statement = mock_run_statement

        config = MagicMock()
        config.schema = self.schema
        config.data = self.data
        fixture = PostgreSqlFixture(
            config=config
        )

        fixture.load()

        # Brittle way of testing that insert statement is run
        # Assumes the keys of first row in self.data are the fields to insert
        data_row = self.data[0]
        stmnt_fields, expected_statement = PostgreSqlInsertStatementMixin.create_insert_statement(
            table=self.schema.config.get_table(),
            fields=data_row.keys(),
            statement_string=True
        )

        expected_params = [data_row[field] for field in stmnt_fields]

        mock_run_statement.assert_called_with(
            expected_statement,
            params=expected_params,
            commit=True
        )
    def load(self):
        """insert data"""

        table = self.schema.config.get_table()

        # Inserts each row separately because we assume fields can be different
        # in each row.  If we don't want to allow this, we can get rid of this
        # for loop.
        for row in self.data:
            fields, values = list(zip(*iter(list(row.items()))))
            stmnt_fields, statement = PostgreSqlInsertStatementMixin.create_insert_statement(
                table,
                fields,
                statement_string=True,
            )

            # Hack to access db object of schema
            self.schema.datastore.run_statement(
                statement,
                params=[row[field] for field in stmnt_fields],
                commit=True
            )
    def load(self):
        """insert data"""

        table = self.schema.config.get_table()

        # Inserts each row separately because we assume fields can be different
        # in each row.  If we don't want to allow this, we can get rid of this
        # for loop.
        for row in self.data:
            fields, values = zip(*row.iteritems())
            stmnt_fields, statement = PostgreSqlInsertStatementMixin.create_insert_statement(
                table,
                fields,
                statement_string=True,
            )

            # Hack to access db object of schema
            self.schema.run_statement(
                statement,
                params=[row[field] for field in stmnt_fields],
                commit=True
            )