Browse Source

Merge "Add unit test for session table in sqlalchemy"

tags/7.0.0
Zuul 6 months ago
parent
commit
3d4145000d
1 changed files with 62 additions and 0 deletions
  1. 62
    0
      freezer_api/tests/unit/sqlalchemy/test_session.py

+ 62
- 0
freezer_api/tests/unit/sqlalchemy/test_session.py View File

@@ -0,0 +1,62 @@
1
+# -*- encoding: utf-8 -*-
2
+# (c) Copyright 2018 ZTE Corporation.
3
+#
4
+# Licensed under the Apache License, Version 2.0 (the "License");
5
+# you may not use this file except in compliance with the License.
6
+# You may obtain a copy of the License at
7
+#
8
+#    http://www.apache.org/licenses/LICENSE-2.0
9
+#
10
+# Unless required by applicable law or agreed to in writing, software
11
+# distributed under the License is distributed on an "AS IS" BASIS,
12
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
13
+# implied.
14
+# See the License for the specific language governing permissions and
15
+# limitations under the License.
16
+
17
+
18
+"""Tests for manipulating job via the DB API"""
19
+
20
+import copy
21
+
22
+from freezer_api.tests.unit import common
23
+from freezer_api.tests.unit.sqlalchemy import base
24
+
25
+
26
+class DbSessionTestCase(base.DbTestCase):
27
+
28
+    def setUp(self):
29
+        super(DbSessionTestCase, self).setUp()
30
+        self.fake_session_0 = common.get_fake_session_0()
31
+        self.fake_session_0.pop('session_id')
32
+
33
+    def test_add_and_get_session(self):
34
+        session_doc = copy.deepcopy(self.fake_session_0)
35
+        session_id = self.dbapi.add_session(project_id=self.fake_session_0.
36
+                                            get('project_id'),
37
+                                            user_id=self.fake_session_0.
38
+                                            get('user_id'),
39
+                                            doc=session_doc)
40
+        self.assertIsNotNone(session_id)
41
+        result = self.dbapi.get_session(project_id=self.fake_session_0.
42
+                                        get('project_id'),
43
+                                        user_id=self.fake_session_0.
44
+                                        get('user_id'),
45
+                                        session_id=session_id)
46
+        self.assertIsNotNone(result)
47
+        self.assertEqual(result.get('session_tag'),
48
+                         self.fake_session_0.get('session_tag'))
49
+        self.assertEqual(result.get('description'),
50
+                         self.fake_session_0.get('description'))
51
+        self.assertEqual(result.get('hold_off'),
52
+                         self.fake_session_0.get('hold_off'))
53
+        self.assertEqual(result.get('time_start'),
54
+                         self.fake_session_0.get('time_start'))
55
+        self.assertEqual(result.get('time_end'),
56
+                         self.fake_session_0.get('time_end'))
57
+        self.assertEqual(result.get('user_id'),
58
+                         self.fake_session_0.get('user_id'))
59
+        self.assertEqual(result.get('project_id'),
60
+                         self.fake_session_0.get('project_id'))
61
+        self.assertEqual(result.get('schedule'),
62
+                         self.fake_session_0.get('schedule'))

Loading…
Cancel
Save