Ejemplo n.º 1
0
    def test_defaults(self):
        """
        Checks that we can load a default form view and perform trivial
        default_get & onchanges & computations
        """
        f = Form(self.env['test_testing_utilities.a'])
        self.assertEqual(f.id, False,
                         "check that our record is not in db (yet)")

        self.assertEqual(f.f2, 42)
        self.assertEqual(f.f3, 21)
        self.assertEqual(f.f4, 42)

        f.f1 = '4'
        self.assertEqual(f.f2, 42)
        self.assertEqual(f.f3, 21)
        self.assertEqual(f.f4, 10)

        f.f2 = 8
        self.assertEqual(f.f3, 4)
        self.assertEqual(f.f4, 2)

        r = f.save()
        self.assertEqual(
            (r.f1, r.f2, r.f3, r.f4),
            ('4', 8, 4, 2),
        )
Ejemplo n.º 2
0
 def test_required(self):
     f = Form(self.env['test_testing_utilities.a'])
     # f1 no default & no value => should fail
     with self.assertRaisesRegexp(AssertionError, 'f1 is a required field'):
         f.save()
     # set f1 and unset f2 => should work
     f.f1 = '1'
     f.f2 = False
     r = f.save()
     self.assertEqual((r.f1, r.f2, r.f3, r.f4), ('1', 0, 0, 0))
Ejemplo n.º 3
0
    def test_readonly(self):
        """
        Checks that fields with readonly modifiers (marked as readonly or
        computed w/o set) raise an error when set.
        """
        f = Form(self.env['test_testing_utilities.readonly'])

        with self.assertRaises(AssertionError):
            f.f1 = '5'
        with self.assertRaises(AssertionError):
            f.f2 = 42
Ejemplo n.º 4
0
    def test_attrs(self):
        """ Checks that attrs/modifiers with non-normalized domains work
        """
        f = Form(self.env['test_testing_utilities.a'],
                 view='test_testing_utilities.non_normalized_attrs')

        # not readonly yet, should work
        f.f2 = 5
        # make f2 readonly
        f.f1 = '63'
        f.f3 = 5
        with self.assertRaises(AssertionError):
            f.f2 = 6
Ejemplo n.º 5
0
    def test_readonly_save(self):
        """ Should not save readonly fields unless they're force_save
        """
        f = Form(self.env['test_testing_utilities.a'],
                 view='test_testing_utilities.non_normalized_attrs')

        f.f1 = '1'
        f.f2 = 987
        self.assertEqual(f.f5, 987)
        self.assertEqual(f.f6, 987)
        r = f.save()
        self.assertEqual(r.f5, 0)
        self.assertEqual(r.f6, 987)