1
1
import unittest
2
2
import warnings
3
- from abc import ABCMeta , abstactmethod
3
+ from abc import ABCMeta , abstractmethod
4
4
from copy import deepcopy
5
5
from distutils .version import LooseVersion
6
6
from typing import TYPE_CHECKING
@@ -29,45 +29,40 @@ class Base_Magpie_TestCase(six.with_metaclass(ABCMeta, unittest.TestCase)):
29
29
"""
30
30
Base definition for all other Test Suite interfaces.
31
31
32
- The implementers must provide :meth:`initClass ` which prepares the various test parameters, session cookies and
32
+ The implementers must provide :meth:`setUpClass ` which prepares the various test parameters, session cookies and
33
33
the local application or remote Magpie URL configuration to evaluate test cases on.
34
34
35
35
The implementers Test Suites must also set :attr:`__test__` to ``True`` so that tests are picked up as executable.
36
36
37
37
.. note::
38
38
Attribute attr:`__test__` is employed to avoid duplicate runs of this base class or other derived classes that
39
39
must not be considered as the *final implementer* Test Suite.
40
-
41
- .. warning::
42
- Do not use :meth:`setUpClass` with :py:exception:`NotImplementedError` in this class or any derived *incomplete*
43
- class as this method still gets called by some test runners although marked with ``__test__ = False``.
44
- The tests would be interpreted as failing in this situation (due to raised error) instead of only indicating an
45
- abstract class definition. You are free to use it if the method is non-raising, but remember that the code will
46
- be executed during initialization of the Test Suite even if seemingly disabled for testing.
47
40
"""
48
41
# pylint: disable=C0103,invalid-name
49
42
version = None # type: Optional[Str]
43
+ require = None # type: Optional[Str]
44
+ # parameters for setup operations, admin-level access to the app
50
45
grp = None # type: Optional[Str]
51
46
usr = None # type: Optional[Str]
52
47
pwd = None # type: Optional[Str]
53
- require = None # type: Optional[Str]
54
48
cookies = None # type: Optional[CookiesType]
55
49
headers = None # type: Optional[HeadersType]
56
50
json_headers = None # type: Optional[HeadersType]
51
+ # parameters for testing, extracted automatically within utils.TestSetup methods
57
52
test_service_type = None # type: Optional[Str]
58
53
test_service_name = None # type: Optional[Str]
59
- test_user = None # type: Optional[Str]
60
- test_group = None # type: Optional[Str]
54
+ test_user_name = None # type: Optional[Str]
55
+ test_group_name = None # type: Optional[Str]
61
56
62
57
__test__ = False # won't run this as a test suite, only its derived classes that overrides to True
63
58
64
59
@classmethod
65
- @abstactmethod
66
- def initClass (cls ):
60
+ @abstractmethod
61
+ def setUpClass (cls ):
67
62
raise NotImplementedError
68
63
69
64
@classmethod
70
- def tearDownClass (cls ): # noqa: N802
65
+ def tearDownClass (cls ):
71
66
pyramid .testing .tearDown ()
72
67
73
68
@@ -77,16 +72,12 @@ class Interface_MagpieAPI_NoAuth(six.with_metaclass(ABCMeta, Base_Magpie_TestCas
77
72
"""
78
73
Interface class for unittests of Magpie API. Test any operation that do not require user AuthN/AuthZ.
79
74
80
- Derived classes must implement :meth:`initClass ` accordingly to generate the Magpie test application.
75
+ Derived classes must implement :meth:`setUpClass ` accordingly to generate the Magpie test application.
81
76
"""
82
77
83
- @classmethod
84
- def initClass (cls ):
85
- raise NotImplementedError
86
-
87
78
@classmethod
88
79
def setUpClass (cls ):
89
- cls . initClass ()
80
+ raise NotImplementedError
90
81
91
82
@runner .MAGPIE_TEST_LOGIN
92
83
def test_GetSession_Anonymous (self ):
@@ -130,18 +121,30 @@ def test_NotAcceptableRequest(self):
130
121
utils .check_response_basic_info (resp , expected_code = 406 )
131
122
132
123
@runner .MAGPIE_TEST_USERS
124
+ @runner .MAGPIE_TEST_LOGGED
133
125
def test_RegisterDiscoverableGroup_Unauthorized (self ):
134
126
"""Not logged-in user cannot update membership to group although group is discoverable."""
135
- raise NotImplementedError # TODO
127
+ utils .warn_version (self , "User registration views not yet available." , "2.0.0" , skip = True )
128
+ resp = utils .test_request (self , "GET" , "/register/groups" , headers = self .json_headers , expect_errors = True )
129
+ body = utils .check_response_basic_info (resp , 401 )
130
+ utils .check_val_not_in ("group_names" , body )
136
131
137
132
@runner .MAGPIE_TEST_USERS
138
133
def test_UnregisterDiscoverableGroup_Unauthorized (self ):
139
134
"""Not logged-in user cannot remove membership to group although group is discoverable."""
140
- raise NotImplementedError # TODO
135
+ utils .warn_version (self , "User registration views not yet available." , "2.0.0" , skip = True )
136
+ path = "/register/groups/random-group"
137
+ resp = utils .test_request (self , "DELETE" , path , headers = self .json_headers , expect_errors = True )
138
+ utils .check_response_basic_info (resp , 401 )
141
139
142
140
def test_ViewDiscoverableGroup_Unauthorized (self ):
143
141
"""Not logged-in user cannot view group although group is discoverable."""
144
- raise NotImplementedError # TODO
142
+ utils .warn_version (self , "User registration views not yet available." , "2.0.0" , skip = True )
143
+ utils .TestSetup
144
+
145
+ path = "/register/groups/random-group"
146
+ resp = utils .test_request (self , "DELETE" , path , headers = self .json_headers , expect_errors = True )
147
+ utils .check_response_basic_info (resp , 401 )
145
148
146
149
def test_ListDiscoverableGroup_Unauthorized (self ):
147
150
"""Not logged-in user cannot list group names although groups are discoverable."""
@@ -154,11 +157,11 @@ class Interface_MagpieAPI_UsersAuth(six.with_metaclass(ABCMeta, Base_Magpie_Test
154
157
"""
155
158
Interface class for unittests of Magpie API. Test any operation that require at least logged user AuthN/AuthZ.
156
159
157
- Derived classes must implement :meth:`initClass ` accordingly to generate the Magpie test application.
160
+ Derived classes must implement :meth:`setUpClass ` accordingly to generate the Magpie test application.
158
161
"""
159
162
160
163
@classmethod
161
- def initClass (cls ):
164
+ def setUpClass (cls ):
162
165
raise NotImplementedError
163
166
164
167
@classmethod
@@ -352,11 +355,11 @@ class Interface_MagpieAPI_AdminAuth(six.with_metaclass(ABCMeta, Base_Magpie_Test
352
355
Interface class for unittests of Magpie API. Test any operation that require at least 'administrator' group
353
356
AuthN/AuthZ.
354
357
355
- Derived classes must implement :meth:`initClass ` accordingly to generate the Magpie test application.
358
+ Derived classes must implement :meth:`setUpClass ` accordingly to generate the Magpie test application.
356
359
"""
357
360
358
361
@classmethod
359
- def initClass (cls ):
362
+ def setUpClass (cls ):
360
363
raise NotImplementedError
361
364
362
365
def tearDown (self ):
@@ -404,7 +407,6 @@ def setup_test_values(cls):
404
407
405
408
cls .test_group_name = "magpie-unittest-dummy-group"
406
409
cls .test_user_name = "magpie-unittest-toto"
407
- cls .test_user_group = get_constant ("MAGPIE_USERS_GROUP" )
408
410
409
411
def setUp (self ):
410
412
self .check_requirements ()
@@ -536,15 +538,15 @@ def test_GetCurrentUserResourcesPermissions_Queries(self):
536
538
body = utils .TestSetup .create_TestService (self , override_service_type = ServiceAPI .service_type )
537
539
test_svc_res_id = body ["service" ]["resource_id" ]
538
540
test_res_type = Route .resource_type_name
539
- body = utils .TestSetup .create_TestServiceResource (self , data_override = {"resource_type" : test_res_type })
541
+ body = utils .TestSetup .create_TestServiceResource (self , override_data = {"resource_type" : test_res_type })
540
542
test_parent_res_id = body ["resource" ]["resource_id" ]
541
543
child_resource_name = self .test_resource_name + "-child"
542
- data_override = {
544
+ override_data = {
543
545
"resource_name" : child_resource_name ,
544
546
"resource_type" : test_res_type ,
545
547
"parent_id" : test_parent_res_id
546
548
}
547
- body = utils .TestSetup .create_TestServiceResource (self , data_override )
549
+ body = utils .TestSetup .create_TestServiceResource (self , override_data )
548
550
test_child_res_id = body ["resource" ]["resource_id" ]
549
551
anonym_usr = get_constant ("MAGPIE_ANONYMOUS_USER" )
550
552
anonym_grp = get_constant ("MAGPIE_ANONYMOUS_GROUP" )
@@ -617,7 +619,7 @@ def test_PostUserResourcesPermissions_Created(self):
617
619
utils .TestSetup .delete_TestServiceResource (self , override_resource_name = resource_name )
618
620
619
621
data = {"resource_name" : resource_name }
620
- body = utils .TestSetup .create_TestServiceResource (self , data_override = data )
622
+ body = utils .TestSetup .create_TestServiceResource (self , override_data = data )
621
623
test_res_id = body ["resource" ]["resource_id" ]
622
624
623
625
# test permission creation
@@ -641,7 +643,7 @@ def test_PostUserResourcesPermissions_Conflict(self):
641
643
utils .TestSetup .delete_TestServiceResource (self , override_resource_name = resource_name )
642
644
643
645
data = {"resource_name" : resource_name }
644
- body = utils .TestSetup .create_TestServiceResource (self , data_override = data )
646
+ body = utils .TestSetup .create_TestServiceResource (self , override_data = data )
645
647
test_res_id = body ["resource" ]["resource_id" ]
646
648
647
649
path = "/users/{usr}/resources/{res}/permissions" .format (res = test_res_id , usr = self .usr )
@@ -978,7 +980,7 @@ def test_PostUsers_InvalidParameters(self):
978
980
"user_name" : self .test_user_name ,
979
981
"email" : "{}@mail.com" .format (self .test_user_name ),
980
982
"password" : self .test_user_name ,
981
- "group_name" : self .test_user_group ,
983
+ "group_name" : self .test_group_name ,
982
984
}
983
985
for code , variant in [
984
986
(400 , {"user_name" : "" }),
@@ -1214,7 +1216,8 @@ def test_PostUserGroup_conflict(self):
1214
1216
1215
1217
@runner .MAGPIE_TEST_USERS
1216
1218
def test_GetUserGroups (self ):
1217
- utils .TestSetup .create_TestUser (self ) # automatically adds user to "MAGPIE_USERS_GROUP"
1219
+ users_group = get_constant ("MAGPIE_USERS_GROUP" )
1220
+ utils .TestSetup .create_TestUser (self , override_group_name = users_group )
1218
1221
utils .TestSetup .create_TestGroup (self )
1219
1222
utils .TestSetup .assign_TestUserGroup (self )
1220
1223
@@ -1224,7 +1227,7 @@ def test_GetUserGroups(self):
1224
1227
body = utils .check_response_basic_info (resp , 200 , expected_method = "GET" )
1225
1228
utils .check_val_is_in ("group_names" , body )
1226
1229
utils .check_val_type (body ["group_names" ], list )
1227
- expected_groups = {self .test_group_name , self . test_user_group }
1230
+ expected_groups = {self .test_group_name , users_group }
1228
1231
if LooseVersion (self .version ) >= LooseVersion ("1.4.0" ):
1229
1232
expected_groups .add (get_constant ("MAGPIE_ANONYMOUS_GROUP" ))
1230
1233
utils .check_all_equal (body ["group_names" ], expected_groups , any_order = True )
@@ -1767,12 +1770,12 @@ def test_PostServiceResources_ChildrenResource_ParentID(self):
1767
1770
1768
1771
# create the child resource under the direct resource and validate response info
1769
1772
child_resource_name = self .test_resource_name + "-children"
1770
- data_override = {
1773
+ override_data = {
1771
1774
"resource_name" : child_resource_name ,
1772
1775
"resource_type" : self .test_resource_type ,
1773
1776
"parent_id" : test_resource_id
1774
1777
}
1775
- body = utils .TestSetup .create_TestServiceResource (self , data_override )
1778
+ body = utils .TestSetup .create_TestServiceResource (self , override_data )
1776
1779
if LooseVersion (self .version ) >= LooseVersion ("0.6.3" ):
1777
1780
utils .check_val_is_in ("resource" , body )
1778
1781
utils .check_val_type (body ["resource" ], dict )
@@ -1950,11 +1953,11 @@ class Interface_MagpieUI_NoAuth(six.with_metaclass(ABCMeta, Base_Magpie_TestCase
1950
1953
"""
1951
1954
Interface class for unittests of Magpie UI. Test any operation that do not require user AuthN/AuthZ.
1952
1955
1953
- Derived classes must implement :meth:`initClass ` accordingly to generate the Magpie test application.
1956
+ Derived classes must implement :meth:`setUpClass ` accordingly to generate the Magpie test application.
1954
1957
"""
1955
1958
1956
1959
@classmethod
1957
- def initClass (cls ):
1960
+ def setUpClass (cls ):
1958
1961
raise NotImplementedError
1959
1962
1960
1963
@runner .MAGPIE_TEST_STATUS
@@ -2028,7 +2031,7 @@ class Interface_MagpieUI_UsersAuth(six.with_metaclass(ABCMeta, Base_Magpie_TestC
2028
2031
"""
2029
2032
Interface class for unittests of Magpie UI. Test any operation that require at least logged user AuthN/AuthZ.
2030
2033
2031
- Derived classes must implement :meth:`initClass ` accordingly to generate the Magpie test application.
2034
+ Derived classes must implement :meth:`setUpClass ` accordingly to generate the Magpie test application.
2032
2035
"""
2033
2036
2034
2037
def __init__ (self , * args , ** kwargs ):
@@ -2087,11 +2090,11 @@ class Interface_MagpieUI_AdminAuth(six.with_metaclass(ABCMeta, Base_Magpie_TestC
2087
2090
Interface class for unittests of Magpie UI. Test any operation that require at least 'administrator' group
2088
2091
AuthN/AuthZ.
2089
2092
2090
- Derived classes must implement :meth:`initClass ` accordingly to generate the Magpie test application.
2093
+ Derived classes must implement :meth:`setUpClass ` accordingly to generate the Magpie test application.
2091
2094
"""
2092
2095
2093
2096
@classmethod
2094
- def initClass (cls ):
2097
+ def setUpClass (cls ):
2095
2098
raise NotImplementedError
2096
2099
2097
2100
@classmethod
0 commit comments