Преглед изворни кода

More tests on LeObject, this time by mocking the queries classes

Yann Weber пре 8 година
родитељ
комит
a306f4c054
1 измењених фајлова са 24 додато и 1 уклоњено
  1. 24
    1
      tests/leapi/test_leobject.py

+ 24
- 1
tests/leapi/test_leobject.py Прегледај датотеку

1
 import unittest
1
 import unittest
2
+from unittest import mock
3
+from unittest.mock import patch
2
 
4
 
3
 import tests.loader_utils
5
 import tests.loader_utils
4
 from tests.leapi.query.utils import dyncode_module as dyncode
6
 from tests.leapi.query.utils import dyncode_module as dyncode
5
 
7
 
6
 from lodel.leapi.leobject import LeObject
8
 from lodel.leapi.leobject import LeObject
7
-from lodel.leapi.query import LeDeleteQuery, LeUpdateQuery, LeGetQuery
9
+from lodel.leapi.query import LeDeleteQuery, LeUpdateQuery, LeGetQuery, \
10
+    LeInsertQuery
8
 from lodel.leapi.exceptions import *
11
 from lodel.leapi.exceptions import *
9
 
12
 
10
 class LeObjectDummyTestCase(unittest.TestCase):
13
 class LeObjectDummyTestCase(unittest.TestCase):
104
             lodel_id = 1, firstname = "foo", lastname = "bar")
107
             lodel_id = 1, firstname = "foo", lastname = "bar")
105
         inst.delete()
108
         inst.delete()
106
 
109
 
110
+
111
+class LeObjectQueryMockTestCase(unittest.TestCase):
112
+    """ Testing LeObject mocking LeQuery objects """
113
+
114
+    def test_insert(self):
115
+        datas = {'lastname': 'foo', 'firstname': 'bar'}
116
+        with patch.object(
117
+            LeInsertQuery, '__init__', return_value = None) as mock_init:
118
+
119
+            dyncode.Person.insert(datas)
120
+            mock_insert.assert_called_once_with(dyncode.Person)
121
+
122
+        with patch.object(
123
+            LeInsertQuery, 'execute', return_value = 42) as mock_insert:
124
+
125
+            ret = dyncode.Person.insert(datas)
126
+            self.AssertEqual(ret, 42, 'Bad return value forwarding')
127
+            mock_insert.assert_called_once_with(datas)
128
+                
129
+        

Loading…
Откажи
Сачувај