Example #1
0
    def test_copy(self):
        action1 = WhereAction(["[model.property]", "value"])
        action2 = action1.copy()
        action2.value = "value2"

        self.assertNotEqual(action1.value, action2.value)
        self.assertNotEqual(id(action1), id(action2))
Example #2
0
    def test_where_action_logical_operator_or(self):
        where_action1 = WhereAction(["[or]", "[0]", "[user.name]", "Igor"])
        where_action2 = WhereAction(["[or]", "[0]", "[user.name]", "Fernando"])
        self.grouped_action.add(where_action1)
        self.grouped_action.add(where_action2)

        self.assertEqual(
            {
                "where": ["user.name = 'Igor' OR user.name = 'Fernando'"],
                "order": [],
                "include": []
            }, self._translate())
Example #3
0
    def test_where_action_logical_operator_and(self):
        where_action1 = WhereAction(["[and]", "[0]", "[user.name]", "Igor"])
        where_action2 = WhereAction(
            ["[and]", "[0]", "[user.email]", "*****@*****.**"])
        self.grouped_action.add(where_action1)
        self.grouped_action.add(where_action2)

        self.assertEqual(
            {
                "where":
                ["user.name = 'Igor' AND user.email = '*****@*****.**'"],
                "order": [],
                "include": []
            }, self._translate())
Example #4
0
 def test_del(self):
     action = WhereAction(["[and]", "[0]", "[model.property]", "value"])
     self.assertEqual(0, self.group.total)
     self.group.add(action)
     self.group.delete(action)
     self.assertEqual(0, self.group.total)
     self.assertEqual({}, self.group.actions)
Example #5
0
    def test_with_five_segments(self):
        action = WhereAction(["[and]", "[0]", "[model.property]", "[gte]", "value"])

        self.assertEqual(0, action.index)
        self.assertEqual("and", action.logical_operator)
        self.assertEqual("gte", action.relational_operator)
        self.assertEqual("model", action.model)
        self.assertEqual("property", action.property)
        self.assertEqual("value", action.value)
Example #6
0
    def test_with_three_segments(self):
        action = WhereAction(["[model.property]", "[lt]", "value"])

        self.assertEqual(None, action.index)
        self.assertEqual(None, action.logical_operator)
        self.assertEqual("lt", action.relational_operator)
        self.assertEqual("model", action.model)
        self.assertEqual("property", action.property)
        self.assertEqual("value", action.value)
Example #7
0
    def test_where_action_operator_gt(self):
        where_action = WhereAction(["[user.name]", "[gt]", "Igor"])
        self.grouped_action.add(where_action)

        self.assertEqual(
            {
                "where": ["user.name > 'Igor'"],
                "order": [],
                "include": []
            }, self._translate())
Example #8
0
    def test_where_action_operator_nlike(self):
        where_action = WhereAction(["[user.name]", "[nlike]", "%Igor%"])
        self.grouped_action.add(where_action)

        self.assertEqual(
            {
                "where": ["user.name NOT LIKE '%%Igor%%'"],
                "order": [],
                "include": []
            }, self._translate())
Example #9
0
    def test_where_action_operator_inq(self):
        """Merge inq operator"""
        where_action = WhereAction(
            ["[user.name]", "[inq]", ["Igor", "Fernando"]])
        self.grouped_action.add(where_action)

        self.assertEqual(
            {
                "where": ["user.name IN ('Igor', 'Fernando')"],
                "order": [],
                "include": []
            }, self._translate())
Example #10
0
    def test_sort_where_action(self):
        where_action1 = WhereAction(["[and]", "[1]", "[user.name]", "Igor"])
        where_action2 = WhereAction(
            ["[and]", "[1]", "[user.email]", "*****@*****.**"])
        where_action3 = WhereAction(
            ["[and]", "[0]", "[user.name]", "Fernando"])
        where_action4 = WhereAction(
            ["[and]", "[0]", "[user.email]", "*****@*****.**"])
        self.grouped_action.add(where_action1)
        self.grouped_action.add(where_action2)
        self.grouped_action.add(where_action3)
        self.grouped_action.add(where_action4)

        self.assertEqual(
            {
                "where": [
                    "user.name = 'Fernando' AND user.email = '*****@*****.**'",
                    "user.name = 'Igor' AND user.email = '*****@*****.**'"
                ],
                "order": [],
                "include": []
            }, self._translate())
Example #11
0
    def test_raise_AttributeError(self):
        where_action = WhereAction(["[user.mobile_number]", "Brazil"])
        self.grouped_action.add(where_action)

        self.assertRaises(AttributeError, self.dialect.translate,
                          self.grouped_action.actions)
Example #12
0
    def test_raise_NotRegisteredTable(self):
        where_action = WhereAction(["[country.name]", "Brazil"])
        self.grouped_action.add(where_action)

        self.assertRaises(NotRegisteredTable, self.dialect.translate,
                          self.grouped_action.actions)
Example #13
0
 def test_add(self):
     action = WhereAction(["[model.property]", "value"])
     self.assertEqual(0, self.group.total)
     self.group.add(action)
     self.assertEqual(1, self.group.total)
     self.assertEqual({'where': {'main': [action]}}, self.group.actions)