8686 UserContactInfoViewSet ,
8787 UsersViewSet ,
8888)
89+ from dojo .asset .api .views import (
90+ AssetAPIScanConfigurationViewSet ,
91+ AssetGroupViewSet ,
92+ AssetMemberViewSet ,
93+ AssetViewSet ,
94+ )
8995from dojo .authorization .roles_permissions import Permissions
9096from dojo .models import (
9197 Announcement ,
140146 User ,
141147 UserContactInfo ,
142148)
149+ from dojo .organization .api .views import (
150+ OrganizationGroupViewSet ,
151+ OrganizationMemberViewSet ,
152+ OrganizationViewSet ,
153+ )
143154
144155from .dojo_test_case import DojoAPITestCase , get_unit_tests_scans_path
145156
@@ -1905,6 +1916,29 @@ def __init__(self, *args, **kwargs):
19051916 BaseClass .RESTEndpointTest .__init__ (self , * args , ** kwargs )
19061917
19071918
1919+ class Asset_API_Scan_ConfigurationTest (BaseClass .BaseClassTest ):
1920+ fixtures = ["dojo_testdata.json" ]
1921+
1922+ def __init__ (self , * args , ** kwargs ):
1923+ self .endpoint_model = Product_API_Scan_Configuration
1924+ self .endpoint_path = "asset_api_scan_configurations"
1925+ self .viewname = "asset_api_scan_configuration"
1926+ self .viewset = AssetAPIScanConfigurationViewSet
1927+ self .payload = {
1928+ "asset" : 2 ,
1929+ "service_key_1" : "dojo_sonar_key" ,
1930+ "tool_configuration" : 3 ,
1931+ }
1932+ self .update_fields = {"tool_configuration" : 2 }
1933+ self .test_type = TestType .OBJECT_PERMISSIONS
1934+ self .permission_check_class = Product_API_Scan_Configuration
1935+ self .permission_create = Permissions .Product_API_Scan_Configuration_Add
1936+ self .permission_update = Permissions .Product_API_Scan_Configuration_Edit
1937+ self .permission_delete = Permissions .Product_API_Scan_Configuration_Delete
1938+ self .deleted_objects = 1
1939+ BaseClass .RESTEndpointTest .__init__ (self , * args , ** kwargs )
1940+
1941+
19081942class ProductTest (BaseClass .BaseClassTest ):
19091943 fixtures = ["dojo_testdata.json" ]
19101944
@@ -1932,6 +1966,33 @@ def __init__(self, *args, **kwargs):
19321966 BaseClass .RESTEndpointTest .__init__ (self , * args , ** kwargs )
19331967
19341968
1969+ class AssetTest (BaseClass .BaseClassTest ):
1970+ fixtures = ["dojo_testdata.json" ]
1971+
1972+ def __init__ (self , * args , ** kwargs ):
1973+ self .endpoint_model = Product
1974+ self .endpoint_path = "assets"
1975+ self .viewname = "asset"
1976+ self .viewset = AssetViewSet
1977+ self .payload = {
1978+ "product_manager" : 2 ,
1979+ "technical_contact" : 3 ,
1980+ "team_manager" : 2 ,
1981+ "organization" : 1 ,
1982+ "name" : "Test Product" ,
1983+ "description" : "test product" ,
1984+ "tags" : ["mytag" , "yourtag" ],
1985+ }
1986+ self .update_fields = {"organization" : 2 }
1987+ self .test_type = TestType .OBJECT_PERMISSIONS
1988+ self .permission_check_class = Product
1989+ self .permission_create = Permissions .Product_Type_Add_Product
1990+ self .permission_update = Permissions .Product_Edit
1991+ self .permission_delete = Permissions .Product_Delete
1992+ self .deleted_objects = 25
1993+ BaseClass .RESTEndpointTest .__init__ (self , * args , ** kwargs )
1994+
1995+
19351996class StubFindingsTest (BaseClass .BaseClassTest ):
19361997 fixtures = ["dojo_testdata.json" ]
19371998
@@ -2873,6 +2934,47 @@ def test_create_authorized_owner(self):
28732934 self .assertEqual (201 , response .status_code , response .content [:1000 ])
28742935
28752936
2937+ class OrganizationTest (BaseClass .BaseClassTest ):
2938+ fixtures = ["dojo_testdata.json" ]
2939+
2940+ def __init__ (self , * args , ** kwargs ):
2941+ self .endpoint_model = Product_Type
2942+ self .endpoint_path = "organizations"
2943+ self .viewname = "organization"
2944+ self .viewset = OrganizationViewSet
2945+ self .payload = {
2946+ "name" : "Test Organization" ,
2947+ "description" : "Test" ,
2948+ "key_product" : True ,
2949+ "critical_product" : False ,
2950+ }
2951+ self .update_fields = {"description" : "changed" }
2952+ self .test_type = TestType .OBJECT_PERMISSIONS
2953+ self .permission_check_class = Product_Type
2954+ self .permission_update = Permissions .Product_Type_Edit
2955+ self .permission_delete = Permissions .Product_Type_Delete
2956+ self .deleted_objects = 25
2957+ BaseClass .RESTEndpointTest .__init__ (self , * args , ** kwargs )
2958+
2959+ def test_create_object_not_authorized (self ):
2960+ self .setUp_not_authorized ()
2961+
2962+ response = self .client .post (self .url , self .payload )
2963+ self .assertEqual (403 , response .status_code , response .content [:1000 ])
2964+
2965+ def test_create_not_authorized_reader (self ):
2966+ self .setUp_global_reader ()
2967+
2968+ response = self .client .post (self .url , self .payload )
2969+ self .assertEqual (403 , response .status_code , response .content [:1000 ])
2970+
2971+ def test_create_authorized_owner (self ):
2972+ self .setUp_global_owner ()
2973+
2974+ response = self .client .post (self .url , self .payload )
2975+ self .assertEqual (201 , response .status_code , response .content [:1000 ])
2976+
2977+
28762978class DojoGroupsTest (BaseClass .BaseClassTest ):
28772979 fixtures = ["dojo_testdata.json" ]
28782980
@@ -3016,6 +3118,29 @@ def __init__(self, *args, **kwargs):
30163118 BaseClass .RESTEndpointTest .__init__ (self , * args , ** kwargs )
30173119
30183120
3121+ class OrganizationMemberTest (BaseClass .MemberEndpointTest ):
3122+ fixtures = ["dojo_testdata.json" ]
3123+
3124+ def __init__ (self , * args , ** kwargs ):
3125+ self .endpoint_model = Product_Type_Member
3126+ self .endpoint_path = "organization_members"
3127+ self .viewname = "organization_member"
3128+ self .viewset = OrganizationMemberViewSet
3129+ self .payload = {
3130+ "organization" : 1 ,
3131+ "user" : 3 ,
3132+ "role" : 2 ,
3133+ }
3134+ self .update_fields = {"role" : 3 }
3135+ self .test_type = TestType .OBJECT_PERMISSIONS
3136+ self .permission_check_class = Product_Type_Member
3137+ self .permission_create = Permissions .Product_Type_Manage_Members
3138+ self .permission_update = Permissions .Product_Type_Manage_Members
3139+ self .permission_delete = Permissions .Product_Type_Member_Delete
3140+ self .deleted_objects = 1
3141+ BaseClass .RESTEndpointTest .__init__ (self , * args , ** kwargs )
3142+
3143+
30193144class ProductMemberTest (BaseClass .MemberEndpointTest ):
30203145 fixtures = ["dojo_testdata.json" ]
30213146
@@ -3039,6 +3164,29 @@ def __init__(self, *args, **kwargs):
30393164 BaseClass .RESTEndpointTest .__init__ (self , * args , ** kwargs )
30403165
30413166
3167+ class AssetMemberTest (BaseClass .MemberEndpointTest ):
3168+ fixtures = ["dojo_testdata.json" ]
3169+
3170+ def __init__ (self , * args , ** kwargs ):
3171+ self .endpoint_model = Product_Member
3172+ self .endpoint_path = "asset_members"
3173+ self .viewname = "asset_member"
3174+ self .viewset = AssetMemberViewSet
3175+ self .payload = {
3176+ "asset" : 3 ,
3177+ "user" : 2 ,
3178+ "role" : 2 ,
3179+ }
3180+ self .update_fields = {"role" : 3 }
3181+ self .test_type = TestType .OBJECT_PERMISSIONS
3182+ self .permission_check_class = Product_Member
3183+ self .permission_create = Permissions .Product_Manage_Members
3184+ self .permission_update = Permissions .Product_Manage_Members
3185+ self .permission_delete = Permissions .Product_Member_Delete
3186+ self .deleted_objects = 1
3187+ BaseClass .RESTEndpointTest .__init__ (self , * args , ** kwargs )
3188+
3189+
30423190class ProductTypeGroupTest (BaseClass .MemberEndpointTest ):
30433191 fixtures = ["dojo_testdata.json" ]
30443192
@@ -3062,6 +3210,29 @@ def __init__(self, *args, **kwargs):
30623210 BaseClass .RESTEndpointTest .__init__ (self , * args , ** kwargs )
30633211
30643212
3213+ class OrganiazationGroupTest (BaseClass .MemberEndpointTest ):
3214+ fixtures = ["dojo_testdata.json" ]
3215+
3216+ def __init__ (self , * args , ** kwargs ):
3217+ self .endpoint_model = Product_Type_Group
3218+ self .endpoint_path = "organization_groups"
3219+ self .viewname = "organization_group"
3220+ self .viewset = OrganizationGroupViewSet
3221+ self .payload = {
3222+ "organization" : 1 ,
3223+ "group" : 2 ,
3224+ "role" : 2 ,
3225+ }
3226+ self .update_fields = {"role" : 3 }
3227+ self .test_type = TestType .OBJECT_PERMISSIONS
3228+ self .permission_check_class = Product_Type_Group
3229+ self .permission_create = Permissions .Product_Type_Group_Add
3230+ self .permission_update = Permissions .Product_Type_Group_Edit
3231+ self .permission_delete = Permissions .Product_Type_Group_Delete
3232+ self .deleted_objects = 1
3233+ BaseClass .RESTEndpointTest .__init__ (self , * args , ** kwargs )
3234+
3235+
30653236class ProductGroupTest (BaseClass .MemberEndpointTest ):
30663237 fixtures = ["dojo_testdata.json" ]
30673238
@@ -3085,6 +3256,29 @@ def __init__(self, *args, **kwargs):
30853256 BaseClass .RESTEndpointTest .__init__ (self , * args , ** kwargs )
30863257
30873258
3259+ class AssetGroupTest (BaseClass .MemberEndpointTest ):
3260+ fixtures = ["dojo_testdata.json" ]
3261+
3262+ def __init__ (self , * args , ** kwargs ):
3263+ self .endpoint_model = Product_Group
3264+ self .endpoint_path = "asset_groups"
3265+ self .viewname = "asset_group"
3266+ self .viewset = AssetGroupViewSet
3267+ self .payload = {
3268+ "asset" : 1 ,
3269+ "group" : 2 ,
3270+ "role" : 2 ,
3271+ }
3272+ self .update_fields = {"role" : 3 }
3273+ self .test_type = TestType .OBJECT_PERMISSIONS
3274+ self .permission_check_class = Product_Group
3275+ self .permission_create = Permissions .Product_Group_Add
3276+ self .permission_update = Permissions .Product_Group_Edit
3277+ self .permission_delete = Permissions .Product_Group_Delete
3278+ self .deleted_objects = 1
3279+ BaseClass .RESTEndpointTest .__init__ (self , * args , ** kwargs )
3280+
3281+
30883282class LanguageTypeTest (BaseClass .BaseClassTest ):
30893283 fixtures = ["dojo_testdata.json" ]
30903284
0 commit comments