-
Notifications
You must be signed in to change notification settings - Fork 5
/
test_magpie_api.py
151 lines (121 loc) · 5.09 KB
/
test_magpie_api.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
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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
test_magpie_api
----------------------------------
Tests for `magpie.api` module.
"""
import unittest
from magpie.constants import get_constant
from magpie.common import JSON_TYPE
from magpie import __meta__
from tests import utils, runner
# NOTE: must be imported without 'from', otherwise the interface's test cases are also executed
import tests.interfaces as ti # noqa: F401
@runner.MAGPIE_TEST_API
@runner.MAGPIE_TEST_LOCAL
class TestCase_MagpieAPI_NoAuth_Local(ti.Interface_MagpieAPI_NoAuth, unittest.TestCase):
"""
Test any operation that do not require user AuthN/AuthZ.
Use a local Magpie test application.
"""
__test__ = True
@classmethod
def setUpClass(cls):
cls.app = utils.get_test_magpie_app()
cls.json_headers = utils.get_headers(cls.app, {'Accept': JSON_TYPE, 'Content-Type': JSON_TYPE})
# FIXME: use get_version()
cls.version = __meta__.__version__
#cls.version = utils.TestSetup.get_Version(cls)
cls.cookies = None
cls.usr = get_constant('MAGPIE_ANONYMOUS_USER')
cls.grp = get_constant('MAGPIE_ANONYMOUS_GROUP')
@runner.MAGPIE_TEST_API
@runner.MAGPIE_TEST_LOCAL
class TestCase_MagpieAPI_UsersAuth_Local(ti.Interface_MagpieAPI_UsersAuth, unittest.TestCase):
"""
Test any operation that require at least 'Users' group AuthN/AuthZ.
Use a local Magpie test application.
"""
__test__ = True
@classmethod
def setUpClass(cls):
cls.app = utils.get_test_magpie_app()
@runner.MAGPIE_TEST_API
@runner.MAGPIE_TEST_LOCAL
class TestCase_MagpieAPI_AdminAuth_Local(ti.Interface_MagpieAPI_AdminAuth, unittest.TestCase):
"""
Test any operation that require at least 'Administrator' group AuthN/AuthZ.
Use a local Magpie test application.
"""
__test__ = True
@classmethod
def setUpClass(cls):
cls.app = utils.get_test_magpie_app()
cls.grp = get_constant('MAGPIE_ADMIN_GROUP')
cls.usr = get_constant('MAGPIE_TEST_ADMIN_USERNAME')
cls.pwd = get_constant('MAGPIE_TEST_ADMIN_PASSWORD')
cls.json_headers = utils.get_headers(cls.app, {'Accept': JSON_TYPE, 'Content-Type': JSON_TYPE})
cls.cookies = None
# FIXME: use get_version()
cls.version = __meta__.__version__
#cls.version = utils.TestSetup.get_Version(cls)
# TODO: fix UI views so that they can be 'found' directly in the WebTest.TestApp
# NOTE: localhost magpie has to be running for following login call to work
cls.headers, cls.cookies = utils.check_or_try_login_user(cls.app, cls.usr, cls.pwd,
use_ui_form_submit=True, version=cls.version)
cls.require = "cannot run tests without logged in user with '{}' permissions".format(cls.grp)
cls.check_requirements()
cls.setup_test_values()
@runner.MAGPIE_TEST_API
@runner.MAGPIE_TEST_REMOTE
class TestCase_MagpieAPI_NoAuth_Remote(ti.Interface_MagpieAPI_NoAuth, unittest.TestCase):
"""
Test any operation that do not require user AuthN/AuthZ.
Use an already running remote bird server.
"""
__test__ = True
@classmethod
def setUpClass(cls):
cls.url = get_constant('MAGPIE_TEST_REMOTE_SERVER_URL')
cls.json_headers = utils.get_headers(cls.url, {'Accept': JSON_TYPE, 'Content-Type': JSON_TYPE})
cls.cookies = None
cls.usr = get_constant('MAGPIE_ANONYMOUS_USER')
cls.grp = get_constant('MAGPIE_ANONYMOUS_GROUP')
# FIXME: use get_version()
cls.version = __meta__.__version__
#cls.version = utils.TestSetup.get_Version(cls)
@runner.MAGPIE_TEST_API
@runner.MAGPIE_TEST_REMOTE
class TestCase_MagpieAPI_UsersAuth_Remote(ti.Interface_MagpieAPI_UsersAuth, unittest.TestCase):
"""
Test any operation that require at least 'Users' group AuthN/AuthZ.
Use an already running remote bird server.
"""
__test__ = True
@classmethod
def setUpClass(cls):
cls.url = get_constant('MAGPIE_TEST_REMOTE_SERVER_URL')
@runner.MAGPIE_TEST_API
@runner.MAGPIE_TEST_REMOTE
class TestCase_MagpieAPI_AdminAuth_Remote(ti.Interface_MagpieAPI_AdminAuth, unittest.TestCase):
"""
Test any operation that require at least 'Administrator' group AuthN/AuthZ.
Use an already running remote bird server.
"""
__test__ = True
@classmethod
def setUpClass(cls):
cls.grp = get_constant('MAGPIE_ADMIN_GROUP')
cls.usr = get_constant('MAGPIE_TEST_ADMIN_USERNAME')
cls.pwd = get_constant('MAGPIE_TEST_ADMIN_PASSWORD')
cls.url = get_constant('MAGPIE_TEST_REMOTE_SERVER_URL')
cls.headers, cls.cookies = utils.check_or_try_login_user(cls.url, cls.usr, cls.pwd)
cls.require = "cannot run tests without logged in user with '{}' permissions".format(cls.grp)
cls.json_headers = utils.get_headers(cls.url, {'Accept': JSON_TYPE, 'Content-Type': JSON_TYPE})
cls.version = utils.TestSetup.get_Version(cls)
cls.check_requirements()
cls.setup_test_values()
if __name__ == '__main__':
import sys
sys.exit(unittest.main())