def test_get_update_statement(self, mocked_get_loader_fields, mocked_get_loader_table, mocked_get_sql_where_fields):

        mocked_get_loader_fields.return_value = "mock_fields"
        mocked_get_loader_table.return_value = "mock_table"
        mocked_get_sql_where_fields.return_value = "mock_where_fields"

        UpdateStatementMixin.create_update_statement = MagicMock()

        update_statement_mixin = UpdateStatementMixin()
        update_statement_mixin.get_update_statement()

        UpdateStatementMixin.create_update_statement.assert_called_with(
            table="mock_table", fields="mock_fields", where_fields="mock_where_fields", statement_string=True
        )
示例#2
0
    def test_create_update_statement_with_where_fields(self):

        table = "test"
        fields = ["field1", "field2"]
        where_fields = [
            {
                "field_name": "field3",
                "operator": ">",
            },
            {
                "field_name": "field4",
                "operator": "=",
            },
        ]

        statement_fields, statement = UpdateStatementMixin.create_update_statement(
            table=table,
            fields=fields,
            where_fields=where_fields,
            statement_string=True,
        )

        expected_statement_fields = fields + [
            field["field_name"] for field in where_fields
        ]
        self.assertTrue(statement_fields == expected_statement_fields)

        for word in [
                "test", "field1", "field2", "field3", "field4", ">", "=",
                "UPDATE", "SET", "WHERE"
        ]:
            self.assertTrue(word in statement)
示例#3
0
    def test_get_update_statement(self, mocked_get_loader_fields,
                                  mocked_get_loader_table,
                                  mocked_get_sql_where_fields):

        mocked_get_loader_fields.return_value = "mock_fields"
        mocked_get_loader_table.return_value = "mock_table"
        mocked_get_sql_where_fields.return_value = "mock_where_fields"

        UpdateStatementMixin.create_update_statement = MagicMock()

        update_statement_mixin = UpdateStatementMixin()
        update_statement_mixin.get_update_statement()

        UpdateStatementMixin.create_update_statement.assert_called_with(
            table="mock_table",
            fields="mock_fields",
            where_fields="mock_where_fields",
            statement_string=True)
    def test_create_update_statement_without_where_fields(self):

        table = "test"
        fields = ["field1", "field2"]

        statement_fields, statement = UpdateStatementMixin.create_update_statement(
            table=table, fields=fields, where_fields=None, statement_string=True
        )

        expected_statement_fields = fields
        self.assertTrue(statement_fields == expected_statement_fields)

        for word in ["test", "field1", "field2", "UPDATE", "SET"]:
            self.assertTrue(word in statement)
    def test_create_update_statement_with_where_fields(self):

        table = "test"
        fields = ["field1", "field2"]
        where_fields = [{"field_name": "field3", "operator": ">"}, {"field_name": "field4", "operator": "="}]

        statement_fields, statement = UpdateStatementMixin.create_update_statement(
            table=table, fields=fields, where_fields=where_fields, statement_string=True
        )

        expected_statement_fields = fields + [field["field_name"] for field in where_fields]
        self.assertTrue(statement_fields == expected_statement_fields)

        for word in ["test", "field1", "field2", "field3", "field4", ">", "=", "UPDATE", "SET", "WHERE"]:
            self.assertTrue(word in statement)
示例#6
0
    def test_create_update_statement_without_where_fields(self):

        table = "test"
        fields = ["field1", "field2"]

        statement_fields, statement = UpdateStatementMixin.create_update_statement(
            table=table,
            fields=fields,
            where_fields=None,
            statement_string=True,
        )

        expected_statement_fields = fields
        self.assertTrue(statement_fields == expected_statement_fields)

        for word in ["test", "field1", "field2", "UPDATE", "SET"]:
            self.assertTrue(word in statement)