2018-11-14 09:23:44 +01:00
from __future__ import absolute_import
import unittest
2018-11-20 07:24:13 +01:00
from testutils import ADMIN_CLIENT
2018-11-14 09:23:44 +01:00
from testutils import TEARDOWN
from library . project import Project
from library . user import User
from library . configurations import Configurations
class TestProjects ( unittest . TestCase ) :
@classmethod
def setUp ( self ) :
2020-03-16 03:13:28 +01:00
self . conf = Configurations ( )
self . project = Project ( )
self . user = User ( )
2018-11-14 09:23:44 +01:00
@classmethod
def tearDown ( self ) :
print " Case completed "
2018-12-04 05:26:12 +01:00
@unittest.skipIf ( TEARDOWN == False , " Test data won ' t be erased. " )
2018-11-14 09:23:44 +01:00
def test_ClearData ( self ) :
print " Clear trace "
#1. Delete project(PA);
self . project . delete_project ( TestProjects . project_edit_project_creation_id , * * TestProjects . USER_edit_project_creation_CLIENT )
#2. Delete user(UA);
2018-11-20 07:24:13 +01:00
self . user . delete_user ( TestProjects . user_edit_project_creation_id , * * ADMIN_CLIENT )
2018-11-14 09:23:44 +01:00
def testEditProjectCreation ( self ) :
"""
Test case :
Edit Project Creation
2018-12-04 05:26:12 +01:00
Test step and expected result :
2018-11-14 09:23:44 +01:00
1. Create a new user ( UA ) ;
2. Set project creation to " admin only " ;
3. Create a new project ( PA ) by user ( UA ) , and fail to create a new project ;
4. Set project creation to " everyone " ;
5. Create a new project ( PA ) by user ( UA ) , success to create a project .
Tear down :
1. Delete project ( PA ) ;
2. Delete user ( UA ) ;
"""
2018-11-20 07:24:13 +01:00
url = ADMIN_CLIENT [ " endpoint " ]
2018-11-14 09:23:44 +01:00
user_edit_project_creation_password = " Aa123456 "
#1. Create a new user(UA);
2018-11-29 11:27:53 +01:00
TestProjects . user_edit_project_creation_id , user_edit_project_creation_name = self . user . create_user ( user_password = user_edit_project_creation_password , * * ADMIN_CLIENT )
2018-11-14 09:23:44 +01:00
TestProjects . USER_edit_project_creation_CLIENT = dict ( endpoint = url , username = user_edit_project_creation_name , password = user_edit_project_creation_password )
#2. Set project creation to "admin only";
2018-11-29 11:27:53 +01:00
self . conf . set_configurations_of_project_creation_restriction ( " adminonly " , * * ADMIN_CLIENT )
2018-11-14 09:23:44 +01:00
#3. Create a new project(PA) by user(UA), and fail to create a new project;
self . project . create_project ( metadata = { " public " : " false " } , expect_status_code = 403 ,
2020-03-13 10:31:41 +01:00
expect_response_body = " { \" errors \" :[ { \" code \" : \" FORBIDDEN \" , \" message \" : \" Only system admin can create project \" }]} " , * * TestProjects . USER_edit_project_creation_CLIENT )
2018-11-14 09:23:44 +01:00
#4. Set project creation to "everyone";
2018-11-29 11:27:53 +01:00
self . conf . set_configurations_of_project_creation_restriction ( " everyone " , * * ADMIN_CLIENT )
2018-11-14 09:23:44 +01:00
#5. Create a new project(PA) by user(UA), success to create a project.
TestProjects . project_edit_project_creation_id , _ = self . project . create_project ( metadata = { " public " : " false " } , * * TestProjects . USER_edit_project_creation_CLIENT )
if __name__ == ' __main__ ' :
unittest . main ( )