This repository was archived by the owner on Aug 30, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 55
Expand file tree
/
Copy pathsecurity_document_tests.py
More file actions
115 lines (99 loc) · 3.35 KB
/
Copy pathsecurity_document_tests.py
File metadata and controls
115 lines (99 loc) · 3.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
#!/usr/bin/env python
# Copyright (C) 2016, 2018 IBM Corp. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""
security_document module - Unit tests for the SecurityDocument class
See configuration options for environment variables in unit_t_db_base
module docstring.
"""
import json
import unittest
from cloudant.security_document import SecurityDocument
from nose.plugins.attrib import attr
from .unit_t_db_base import UnitTestDbBase
@attr(db=['cloudant','couch'])
class SecurityDocumentTests(UnitTestDbBase):
"""
SecurityDocument unit tests
"""
def setUp(self):
"""
Set up test attributes
"""
super(SecurityDocumentTests, self).setUp()
self.db_set_up()
self.load_security_document_data()
def tearDown(self):
"""
Reset test attributes
"""
self.db_tear_down()
super(SecurityDocumentTests, self).tearDown()
def test_constructor(self):
"""
Test constructing a SecurityDocument
"""
sdoc = SecurityDocument(self.db)
self.assertIsInstance(sdoc, SecurityDocument)
self.assertEqual(sdoc.r_session, self.db.r_session)
def test_document_url(self):
"""
Test that the document url is populated correctly
"""
sdoc = SecurityDocument(self.db)
self.assertEqual(
sdoc.document_url,
'/'.join([self.db.database_url, '_security'])
)
def test_json(self):
"""
Test the security document dictionary renders as a JSON string
"""
sdoc = SecurityDocument(self.db)
sdoc.fetch()
sdoc_as_json_string = sdoc.json()
self.assertIsInstance(sdoc_as_json_string, str)
sdoc_as_a_dict = json.loads(sdoc_as_json_string)
self.assertDictEqual(sdoc_as_a_dict, sdoc)
def test_fetch(self):
"""
Test that the security document is retrieved as expected
"""
sdoc = SecurityDocument(self.db)
sdoc.fetch()
self.assertDictEqual(sdoc, self.sdoc)
def test_save(self):
"""
Test that the security document is updated correctly
"""
sdoc = SecurityDocument(self.db)
sdoc.fetch()
sdoc.update(self.mod_sdoc)
sdoc.save()
mod_sdoc = SecurityDocument(self.db)
mod_sdoc.fetch()
self.assertDictEqual(mod_sdoc, self.mod_sdoc)
def test_context_manager(self):
"""
Test that the context SecurityDocument context manager enter and exit
routines work as expected.
"""
with SecurityDocument(self.db) as sdoc:
self.assertDictEqual(sdoc, self.sdoc)
sdoc.update(self.mod_sdoc)
mod_sdoc = SecurityDocument(self.db)
mod_sdoc.fetch()
self.assertDictEqual(mod_sdoc, self.mod_sdoc)
if __name__ == '__main__':
unittest.main()