-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_about.py
78 lines (53 loc) · 2.28 KB
/
test_about.py
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
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from __future__ import division
from __future__ import print_function
from __future__ import absolute_import
# pylint: disable=protected-access,too-many-public-methods
from hamcrest import is_
from hamcrest import contains_exactly
from hamcrest import assert_that
from hamcrest import has_entries
from hamcrest import has_property
import unittest
from nti.testing.matchers import verifiably_provides
from nti.externalization import update_from_external_object
from nti.externalization import to_external_object
from nti.xapi.about import About
from nti.xapi.extensions import Extensions
from nti.xapi.interfaces import Version
from nti.xapi.interfaces import IExtensions
from nti.xapi.tests import SharedConfiguringTestLayer
class TestAbout(unittest.TestCase):
def test_defaults(self):
a = About()
assert_that(a, has_property('version', contains_exactly(Version.latest)))
def test_version_init(self):
about = About(version=['1.0.1', '1.0.0'])
assert_that(about, has_property('version', contains_exactly('1.0.1', '1.0.0')))
def test_takes_exts(self):
about = About(version=['1.0.1', '1.0.0'])
about.extensions = Extensions({'https://foo.com/a': 1})
assert_that(about.extensions, contains_exactly('https://foo.com/a'))
class TestAboutIO(TestAbout):
layer = SharedConfiguringTestLayer
def setUp(self):
self.data = {
'version': ['1.0.0'],
'extensions': {
'http://www.example.com/ext/a': 'a',
'http://www.example.com/ext/b': 'b'
},
}
def test_from_external_object(self):
about = About()
update_from_external_object(about, self.data)
assert_that(about, has_property('version', contains_exactly('1.0.0')))
assert_that(about.extensions, has_entries('http://www.example.com/ext/a', 'a',
'http://www.example.com/ext/b', 'b'))
assert_that(about.extensions, verifiably_provides(IExtensions))
def test_to_external_object(self):
about = About(version=['1.0.0'])
about.extensions = Extensions(self.data['extensions'])
external = to_external_object(about)
assert_that(external, is_(self.data))