Parcourir la source

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

Yann Weber il y a 8 ans
Parent
révision
a306f4c054
1 fichiers modifiés avec 24 ajouts et 1 suppressions
  1. 24
    1
      tests/leapi/test_leobject.py

+ 24
- 1
tests/leapi/test_leobject.py Voir le fichier

@@ -1,10 +1,13 @@
1 1
 import unittest
2
+from unittest import mock
3
+from unittest.mock import patch
2 4
 
3 5
 import tests.loader_utils
4 6
 from tests.leapi.query.utils import dyncode_module as dyncode
5 7
 
6 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 11
 from lodel.leapi.exceptions import *
9 12
 
10 13
 class LeObjectDummyTestCase(unittest.TestCase):
@@ -104,3 +107,23 @@ class LeObjectDummyTestCase(unittest.TestCase):
104 107
             lodel_id = 1, firstname = "foo", lastname = "bar")
105 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…
Annuler
Enregistrer