Exemplo n.º 1
0
    def __init__(self, expression, msg=None, mode="post", triggers="error", desired=False, required=False):
        """Initialize the rule with the expression and mode.

        :expr: string represention of the expression which will be
        checked.
        :msg: string error msg for the rule. If not provied use the
        string represention of the provided expression.
        :mode: string of the mode when to evaluate this rule. Defaults
        to 'post'
        :triggers: string of the type of "effect" this rule should
        generate if the evaluation fails. Can either be a error message
        or a warning. In case of a warning the validation of the form
        will fail. In case of a warning only a warning message will be
        displayer. Defaults to 'error'
        """
        Expression.__init__(self, expression)
        self.msg = msg
        if msg is None:
            self.msg = 'Expression "%s" failed' % self._expression
        self.mode = mode
        if mode is None:
            self.mode = "post"
        self.triggers = triggers
        if triggers is None:
            self.triggers = "error"
        self.required = required
        self.desired = desired
Exemplo n.º 2
0
    def test_5(self):
        import datetime

        expression = Expression("len($xxx) le 9")
        values = {"xxx": u"abcdefghi"}
        result = expression.evaluate(values)
        self.assertEqual(result, True)
Exemplo n.º 3
0
    def __init__(self,
                 expression,
                 msg=None,
                 mode='post',
                 triggers='error',
                 desired=False,
                 required=False):
        """Initialize the rule with the expression and mode.

        :expr: string represention of the expression which will be
        checked.
        :msg: string error msg for the rule. If not provied use the
        string represention of the provided expression.
        :mode: string of the mode when to evaluate this rule. Defaults
        to 'post'
        :triggers: string of the type of "effect" this rule should
        generate if the evaluation fails. Can either be a error message
        or a warning. In case of a warning the validation of the form
        will fail. In case of a warning only a warning message will be
        displayer. Defaults to 'error'
        """
        Expression.__init__(self, expression)
        self.msg = msg
        if msg is None:
            self.msg = 'Expression "%s" failed' % self._expression
        self.mode = mode
        if mode is None:
            self.mode = 'post'
        self.triggers = triggers
        if triggers is None:
            self.triggers = 'error'
        self.required = required
        self.desired = desired
Exemplo n.º 4
0
 def test_smaller(self):
     import datetime
     expression = Expression("$a > timedelta($b)")
     result = expression.evaluate({
         "a": datetime.timedelta(seconds=100),
         "b": "00:00:120"
     })
     self.assertEqual(result, False)
Exemplo n.º 5
0
 def test_sum_smaller(self):
     expression = Expression(
         "(timedelta($a) +  timedelta($b)) < timedelta($c)")
     result = expression.evaluate({
         "a": "04:00:00",
         "b": "05:00:00",
         "c": "08:00:00"
     })
     self.assertEqual(result, False)
Exemplo n.º 6
0
    def test_4(self):
        import datetime

        expression = Expression(
            "( ( ( $ap_ausb eq '1' ) and ( $pp_phase in ['1','2'] ) ) or ( ( $ap_ausb eq '3' ) and ( $pp_phase in ['3','4'] ) ) or ( ( $ap_ausb in ['2','4'] ) or ( not bool($ap_ausb) ) ) )"
        )
        values = {
            "ap_austritt": u"1",
            "pp_phase_s": u"",
            "ap_q1": u"Rechtsanwalt und Notarfachangestellte",
            "ap_geschlecht": u"0",
            "ap_austritt_ja": u"ja",
            "programm_info": "",
            "bericht_state_id": 2,
            "pp_austritt_ca": datetime.date(2014, 3, 14),
            "ap_ausb": u"1",
            "pp_phase": u"",
            "pp_ga": [u"2", u""],
            "ap_austritt_date": datetime.date(2014, 3, 14),
            "proj_kommentar": u"",
            "proj_fkz": u"09.00101.13",
            "ap_bj1": u"",
            "ap_bj2": u"",
            "ap_bj3": u"",
            "pp_beginn": u"seit",
            "updated": datetime.datetime(2014, 10, 23, 12, 41, 39),
            "_roles": "",
            "ap_quer": u"1",
            "ap_quali": u"1",
            "pp_gesamtst": u"275",
            "form_info": "",
            "pp_kinder": [u"1", u""],
            "created": datetime.datetime(2014, 9, 23, 14, 5, 30),
            "projekt": None,
            "ausbildungsformat": None,
            "pp_eintritt_ps": datetime.date(2014, 1, 6),
            "logo_einbindung": None,
            "pp_eintritt_vb": None,
            "ap_code": u"A.CB257",
            "ap_q2": u"",
            "ap_austritt_s": u"",
            "ap_mhg": u"0",
            "ap_q3": u"",
        }
        result = expression.evaluate(values)
        self.assertEqual(result, False)
Exemplo n.º 7
0
 def test_4(self):
     import datetime
     expression = Expression(
         "( ( ( $ap_ausb eq '1' ) and ( $pp_phase in ['1','2'] ) ) or ( ( $ap_ausb eq '3' ) and ( $pp_phase in ['3','4'] ) ) or ( ( $ap_ausb in ['2','4'] ) or ( not bool($ap_ausb) ) ) )"
     )
     values = {
         'ap_austritt': u'1',
         'pp_phase_s': u'',
         'ap_q1': u'Rechtsanwalt und Notarfachangestellte',
         'ap_geschlecht': u'0',
         'ap_austritt_ja': u'ja',
         'programm_info': '',
         'bericht_state_id': 2,
         'pp_austritt_ca': datetime.date(2014, 3, 14),
         'ap_ausb': u'1',
         'pp_phase': u'',
         'pp_ga': [u'2', u''],
         'ap_austritt_date': datetime.date(2014, 3, 14),
         'proj_kommentar': u'',
         'proj_fkz': u'09.00101.13',
         'ap_bj1': u'',
         'ap_bj2': u'',
         'ap_bj3': u'',
         'pp_beginn': u'seit',
         'updated': datetime.datetime(2014, 10, 23, 12, 41, 39),
         '_roles': '',
         'ap_quer': u'1',
         'ap_quali': u'1',
         'pp_gesamtst': u'275',
         'form_info': '',
         'pp_kinder': [u'1', u''],
         'created': datetime.datetime(2014, 9, 23, 14, 5, 30),
         'projekt': None,
         'ausbildungsformat': None,
         'pp_eintritt_ps': datetime.date(2014, 1, 6),
         'logo_einbindung': None,
         'pp_eintritt_vb': None,
         'ap_code': u'A.CB257',
         'ap_q2': u'',
         'ap_austritt_s': u'',
         'ap_mhg': u'0',
         'ap_q3': u''
     }
     result = expression.evaluate(values)
     self.assertEqual(result, False)
Exemplo n.º 8
0
 def test_addstr(self):
     expression = Expression("$a + 'abc'")
     result = expression.evaluate({"a": u"xyz"})
     self.assertEqual(result, 'xyzabc')
Exemplo n.º 9
0
 def test_equal(self):
     expression = Expression("timedelta($a) == timedelta($b)")
     result = expression.evaluate({"a": "01:30:00", "b": "00:90:00"})
     self.assertEqual(result, True)
Exemplo n.º 10
0
 def test_addmul(self):
     expression = Expression("4 + 3 * 7")
     result = expression.evaluate()
     self.assertEqual(result, 25.0)
Exemplo n.º 11
0
 def test_len4ticks(self):
     expression = Expression("len($a)")
     result = expression.evaluate({"a": "''''"})
     self.assertEqual(result, 4)
Exemplo n.º 12
0
 def test_listing(self):
     expression = Expression("[1,2,3]")
     result = expression.evaluate()
     self.assertEqual(result, [1, 2, 3])
Exemplo n.º 13
0
 def test_sub(self):
     expression = Expression("7 - 4")
     result = expression.evaluate()
     self.assertEqual(result, 3.0)
Exemplo n.º 14
0
 def test_2(self):
     expression = Expression(
         "( 'abfrages' eq 'antrags' ) and ( '1' eq '2') or ( 'admin' in ['institutionen_einsicht','user','antragsteller'] ) or ( 'formularmanager' in ['institutionen_einsicht','user','antragsteller'] )"
     )
     result = expression.evaluate()
     self.assertEqual(result, False)
Exemplo n.º 15
0
 def test_8(self):
     expression = Expression("bool($x) and ($x == 1)")
     result = expression.evaluate({'x': 0})
     self.assertEqual(result, False)
Exemplo n.º 16
0
 def test_1(self):
     expression = Expression(
         "( 'antragsteller' in       ['institutionen_einsicht', 'user', 'antragsteller']   ) == False"
     )
     result = expression.evaluate()
     self.assertEqual(result, False)
Exemplo n.º 17
0
 def test_variable(self):
     expression = Expression("$string")
     result = expression.evaluate({"string": "string"})
     self.assertEqual(result, "string")
Exemplo n.º 18
0
 def test_sum_smaller(self):
     expression = Expression("(timedelta($a) +  timedelta($b)) < timedelta($c)")
     result = expression.evaluate({"a": "04:00:00", "b": "05:00:00", "c": "08:00:00"})
     self.assertEqual(result, False)
Exemplo n.º 19
0
 def test_equal(self):
     expression = Expression("timedelta($a) == timedelta($b)")
     result = expression.evaluate({"a": "01:30:00", "b": "00:90:00"})
     self.assertEqual(result, True)
Exemplo n.º 20
0
    def test_smaller(self):
        import datetime

        expression = Expression("$a > timedelta($b)")
        result = expression.evaluate({"a": datetime.timedelta(seconds=100), "b": "00:00:120"})
        self.assertEqual(result, False)
Exemplo n.º 21
0
 def test_2(self):
     expression = Expression("( 'abfrages' eq 'antrags' ) and ( '1' eq '2') or ( 'admin' in ['institutionen_einsicht','user','antragsteller'] ) or ( 'formularmanager' in ['institutionen_einsicht','user','antragsteller'] )")
     result = expression.evaluate()
     self.assertEqual(result, False)
Exemplo n.º 22
0
 def test_missingvariable(self):
     expression = Expression("$missingstring")
     result = expression.evaluate({"string": "string"})
     self.assertEqual(result, None)
Exemplo n.º 23
0
 def test_5(self):
     import datetime
     expression = Expression("len($xxx) le 9")
     values = {'xxx': u'abcdefghi'}
     result = expression.evaluate(values)
     self.assertEqual(result, True)
Exemplo n.º 24
0
 def test_boolempty(self):
     expression = Expression("bool($string)")
     result = expression.evaluate({"string": ""})
     self.assertEqual(result, False)
Exemplo n.º 25
0
 def test_true(self):
     expression = Expression("True")
     result = expression.evaluate()
     self.assertEqual(result, True)
Exemplo n.º 26
0
 def test_true(self):
     expression = Expression("True")
     result = expression.evaluate()
     self.assertEqual(result, True)
Exemplo n.º 27
0
 def test_notfalse(self):
     expression = Expression("not False")
     result = expression.evaluate()
     self.assertEqual(result, True)
Exemplo n.º 28
0
 def test_stringwithspace(self):
     expression = Expression("'foo and bar'")
     result = expression.evaluate()
     self.assertEqual(result, "foo and bar")
Exemplo n.º 29
0
 def test_number(self):
     expression = Expression("1")
     result = expression.evaluate()
     self.assertEqual(result, 1.0)
Exemplo n.º 30
0
 def test_stringwithspace(self):
     expression = Expression("'foo and bar'")
     result = expression.evaluate()
     self.assertEqual(result, "foo and bar")
Exemplo n.º 31
0
 def test_plusnediv(self):
     expression = Expression("2 + 2 == 8 / 2")
     result = expression.evaluate()
     self.assertEqual(result, True)
Exemplo n.º 32
0
 def test_addstr(self):
     expression = Expression("$a + 'abc'")
     result = expression.evaluate({"a": u"xyz"})
     self.assertEqual(result, "xyzabc")
Exemplo n.º 33
0
 def test_boolvar(self):
     expression = Expression("bool($float)")
     result = expression.evaluate({"float": 1})
     self.assertEqual(result, True)
Exemplo n.º 34
0
 def test_6(self):
     expression = Expression("( 'LOP-PM' in ['admins'] ) or ( 'False' == 'True' )")
     result = expression.evaluate({})
     self.assertEqual(result, False)
Exemplo n.º 35
0
 def test_boolempty(self):
     expression = Expression("bool($string)")
     result = expression.evaluate({"string": ""})
     self.assertEqual(result, False)
Exemplo n.º 36
0
 def test_8(self):
     expression = Expression("bool($x) and ($x == 1)")
     result = expression.evaluate({"x": 0})
     self.assertEqual(result, False)
Exemplo n.º 37
0
 def test_len4ticks(self):
     expression = Expression("len($a)")
     result = expression.evaluate({"a": "''''"})
     self.assertEqual(result, 4)
Exemplo n.º 38
0
 def test_false(self):
     expression = Expression("False")
     result = expression.evaluate()
     self.assertEqual(result, False)
Exemplo n.º 39
0
 def test_1(self):
     expression = Expression("( 'antragsteller' in       ['institutionen_einsicht', 'user', 'antragsteller']   ) == False")
     result = expression.evaluate()
     self.assertEqual(result, False)
Exemplo n.º 40
0
 def test_listing(self):
     expression = Expression("[1,2,3]")
     result = expression.evaluate()
     self.assertEqual(result, [1, 2, 3])
Exemplo n.º 41
0
 def test_variable(self):
     expression = Expression("$string")
     result = expression.evaluate({"string": "string"})
     self.assertEqual(result, "string")
Exemplo n.º 42
0
 def test_nottrue(self):
     expression = Expression("not True")
     result = expression.evaluate()
     self.assertEqual(result, False)
Exemplo n.º 43
0
 def test_6(self):
     expression = Expression("( 'LOP-PM' in ['admins'] ) or ( 'False' == 'True' )")
     result = expression.evaluate({})
     self.assertEqual(result, False)
Exemplo n.º 44
0
 def test_notfalse(self):
     expression = Expression("not False")
     result = expression.evaluate()
     self.assertEqual(result, True)
Exemplo n.º 45
0
 def test_missingvariable(self):
     expression = Expression("$missingstring")
     result = expression.evaluate({"string": "string"})
     self.assertEqual(result, None)
Exemplo n.º 46
0
 def test_plusplus(self):
     expression = Expression("1 + 1 + 1")
     result = expression.evaluate()
     self.assertEqual(result, 3.0)
Exemplo n.º 47
0
 def test_false(self):
     expression = Expression("False")
     result = expression.evaluate()
     self.assertEqual(result, False)
Exemplo n.º 48
0
 def test_sub(self):
     expression = Expression("7 - 4")
     result = expression.evaluate()
     self.assertEqual(result, 3.0)
Exemplo n.º 49
0
 def test_nottrue(self):
     expression = Expression("not True")
     result = expression.evaluate()
     self.assertEqual(result, False)
Exemplo n.º 50
0
 def test_mul(self):
     expression = Expression("7 * 7")
     result = expression.evaluate()
     self.assertEqual(result, 49.0)
Exemplo n.º 51
0
 def test_plusplus(self):
     expression = Expression("1 + 1 + 1")
     result = expression.evaluate()
     self.assertEqual(result, 3.0)
Exemplo n.º 52
0
 def test_number(self):
     expression = Expression("1")
     result = expression.evaluate()
     self.assertEqual(result, 1.0)
Exemplo n.º 53
0
 def test_mul(self):
     expression = Expression("7 * 7")
     result = expression.evaluate()
     self.assertEqual(result, 49.0)
Exemplo n.º 54
0
 def test_div(self):
     expression = Expression("49 / 7")
     result = expression.evaluate()
     self.assertEqual(result, 7.0)
Exemplo n.º 55
0
 def test_div(self):
     expression = Expression("49 / 7")
     result = expression.evaluate()
     self.assertEqual(result, 7.0)
Exemplo n.º 56
0
 def test_addmulpar(self):
     expression = Expression("(4 + 3) * 7")
     result = expression.evaluate()
     self.assertEqual(result, 49.0)
Exemplo n.º 57
0
 def test_addmulpar(self):
     expression = Expression("(4 + 3) * 7")
     result = expression.evaluate()
     self.assertEqual(result, 49.0)
Exemplo n.º 58
0
 def test_plusnediv(self):
     expression = Expression("2 + 2 == 8 / 2")
     result = expression.evaluate()
     self.assertEqual(result, True)
Exemplo n.º 59
0
 def test_addmul(self):
     expression = Expression("4 + 3 * 7")
     result = expression.evaluate()
     self.assertEqual(result, 25.0)
Exemplo n.º 60
0
 def test_boolvar(self):
     expression = Expression("bool($float)")
     result = expression.evaluate({"float": 1})
     self.assertEqual(result, True)