|
@@ -0,0 +1,32 @@
|
|
1
|
+import unittest
|
|
2
|
+from unittest import mock
|
|
3
|
+from unittest.mock import patch
|
|
4
|
+
|
|
5
|
+import leapi_dyncode as dyncode
|
|
6
|
+
|
|
7
|
+from lodel.leapi.datahandlers.datas import UniqID
|
|
8
|
+from lodel.plugins.dummy_datasource.datasource import DummyDatasource
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+class UniqIDTestCase(unittest.TestCase):
|
|
12
|
+
|
|
13
|
+ def test_construct_data_sets_new_uid_if_none(self):
|
|
14
|
+ sent_uid = None
|
|
15
|
+ mocked_returned_uid = 987654321
|
|
16
|
+
|
|
17
|
+ with patch.object(DummyDatasource, 'new_numeric_id', return_value=mocked_returned_uid) as mock_method:
|
|
18
|
+ returned_uid = UniqID.construct_data(UniqID, dyncode.Object, 'lodel_id', '', sent_uid)
|
|
19
|
+
|
|
20
|
+ mock_method.assert_called_once_with(dyncode.Object)
|
|
21
|
+ self.assertEqual(returned_uid, mocked_returned_uid)
|
|
22
|
+
|
|
23
|
+ def test_construct_data_returns_already_set_uid(self):
|
|
24
|
+ sent_uid = 123456789
|
|
25
|
+ mocked_returned_uid = 987654321
|
|
26
|
+
|
|
27
|
+ with patch.object(DummyDatasource, 'new_numeric_id', return_value=mocked_returned_uid) as mock_method:
|
|
28
|
+ returned_uid = UniqID.construct_data(UniqID, dyncode.Object, '', '', sent_uid)
|
|
29
|
+
|
|
30
|
+ self.assertEqual(returned_uid, sent_uid)
|
|
31
|
+ mock_method.assert_not_called()
|
|
32
|
+
|