Exemple #1
0
 def test_update_instance(self):
     """ Checking that LeObject update method calls LeUpdateQuery
         correctly """
     with patch.object(
         LeUpdateQuery, '__init__', return_value = None) as mock_init:
         with patch.object(
             LeObject, 'datas', return_value = {
                 'lodel_id': 1, 'firstname': 'foo', 'lastname': 'bar',
                 'fullname': 'Foo Bar', 'alias': None }) as mock_datas:
         
             inst = dyncode.Person(
                 lodel_id = 1, firstname = "foo", lastname = "bar")
             try:
                inst.update()
             except AttributeError:
                 pass
             mock_init.assert_called_once_with(
                 dyncode.Person, [('lodel_id', '=', 1)])
     
     with patch.object(
         LeUpdateQuery, 'execute', return_value = None) as mock_update:
         with patch.object(
             LeObject, 'datas', return_value = {
                 'lodel_id': 1, 'firstname': 'foo', 'lastname': 'bar',
                 'fullname': 'Foo Bar', 'alias': None }) as mock_datas:
         
             inst = dyncode.Person(
                 lodel_id = 1, firstname = "foo", lastname = "bar")
             inst.update()
             mock_update.assert_called_once_with({
                 'lodel_id': 1, 'firstname': 'foo', 'lastname': 'bar',
                 'fullname': 'Foo Bar', 'alias': None })
Exemple #2
0
 def test_init_bad_fields(self):
     """ Testing init with bad arguments """
     with self.assertRaises(LeApiErrors):
         dyncode.Person(
             lodel_id = 1,
             foobar = "barfoo")
     with self.assertRaises(LeApiError):
         dyncode.Person(lastname = "foo", firstname = "bar")
Exemple #3
0
 def test_init(self):
     """ Testing LeObject child class __init__ """
     dyncode.Person(
         lodel_id = '1',
         lastname = "Foo",
         firstname = "Bar",
         alias = "Foobar")
Exemple #4
0
    def test_delete(self):
        """ Checking that LeObject delete method calls LeDeleteQuery
            correctly """
        with patch.object(
            LeDeleteQuery, '__init__', return_value = None) as mock_init:

            inst = dyncode.Person(
                lodel_id = 1, firstname = "foo", lastname = "bar")
            try:
                inst.delete()
            except AttributeError:
                pass
            mock_init.assert_called_once_with(
                dyncode.Person, [('lodel_id', '=', 1)])

        with patch.object(
            LeDeleteQuery, 'execute', return_value = 1) as mock_execute:

            inst = dyncode.Person(
                lodel_id = 1, firstname = "foo", lastname = "bar")
            ret = inst.delete()
            self.assertEqual(ret, 1, 'Bad return value forwarding')
            mock_execute.assert_called_once_with()
Exemple #5
0
 def test_initilized(self):
     """ Testing initialized method """
     inst = dyncode.Person(
         lodel_id = 1, lastname="foo")
     self.assertFalse(inst.initialized)
Exemple #6
0
 def test_data_accessor_fails(self):
     """ Testing that data accessor detects unitialized fields """
     inst = dyncode.Person(lodel_id = 1, lastname = "foo")
     with self.assertRaises(RuntimeError):
         inst.data('firstname')
Exemple #7
0
 def test_data_accessor(self):
     """ Testing data accessor method """
     inst = dyncode.Person(lodel_id = 1, lastname = "foo")
     self.assertEqual(inst.data('lodel_id'), 1)
     self.assertEqual(inst.data('lastname'), 'foo')
Exemple #8
0
 def test_delete_instance(self):
     """ Testing instance method delete """
     inst = dyncode.Person(
         lodel_id = 1, firstname = "foo", lastname = "bar")
     inst.delete()