def test_admin_create_sprint(self): """ test role creation """ warnings.simplefilter("ignore") request_token = self.client().get( '/api/login/', headers={ 'Content-Type': 'application/json', 'Authorization': _basic_auth_str(self.user_admin.get('username'), self.user_admin.get('password')) }) json_data = json.loads(request_token.data) self.user_admin['token'] = json_data.get('token') json_sprint = { "name": string_generator(), "start_date": "2019-02-20 00:00:00", "due_date": "2019-02-28 00:00:00", "comment": string_generator(), "project_id": 2 } request_sprint_admin_create = self.client().post( '/api/sprint/', headers={ 'Content-Type': 'application/json', 'x-access-token': self.user_admin['token'] }, data=json.dumps(json_sprint)) json_data = json.loads(request_sprint_admin_create.data) self.assertTrue(json_data.get('message')) self.assertEqual(json_data.get('message'), 'New sprint created!') self.assertEqual(request_sprint_admin_create.status_code, 200)
def test_not_admin_create_role(self): """ test role creation fail by non admin""" warnings.simplefilter("ignore") request_token = self.client().get( '/api/login/', headers={ 'Content-Type': 'application/json', 'Authorization': _basic_auth_str(self.user_not_admin.get('username'), self.user_not_admin.get('password')) }) json_data = json.loads(request_token.data) self.user_not_admin['token'] = json_data.get('token') json_role = { 'name': string_generator() + 'role_test_name', 'comment': string_generator() + 'role_test_comment' } request_role_not_admin_create = self.client().post( '/api/role/', headers={ 'Content-Type': 'application/json', 'x-access-token': self.user_not_admin['token'] }, data=json.dumps(json_role)) json_data = json.loads(request_role_not_admin_create.data) self.assertTrue(json_data.get('message')) self.assertEqual(json_data.get('message'), 'Cannot perform that function!') self.assertEqual(request_role_not_admin_create.status_code, 200)
def test_create_task(self): """ test task creation """ warnings.simplefilter("ignore") request_token = self.client().get('/api/login/', headers={'Content-Type': 'application/json', 'Authorization': _basic_auth_str(self.user.get('username'), self.user.get('password'))}) json_data = json.loads(request_token.data) self.user['token'] = json_data.get('token') json_task = { "name": string_generator(), "start_date": '2018-1-12', "due_date": '2019-1-23', "status": string_generator(), "sprint_id": 1, "employee_id": 11 } request_task_create = self.client().post('/api/task/', headers={'Content-Type': 'application/json', 'x-access-token': self.user['token']}, data=json.dumps(json_task)) json_data = json.loads(request_task_create.data) self.assertTrue(json_data.get('message')) self.assertEqual(json_data.get('message'), 'New Task created!')
def test_user_instance(self): json_user = { "name": "cyril_2", "email": string_generator() + "@email.com", "password": string_generator(), "admin": False, "profile": "Software Engineer", "skills": ["java", "C#", "Python"] } usr = User(name=json_user['name'], email=json_user['email'], password=string_generator(), admin=False, profile="", skills=json_user['skills']) self.assertIsInstance(usr, User)
def test_create_employee_with_invalid_user(self): """test employee creation with invalid user""" warnings.simplefilter("ignore") json_employee = { "badge": "badge_" + string_generator(), "start_date": "2019-02-19 13:10:00", "end_date": "", "is_full_time": True, "user_id": 100, "role_id": 1, "team_id": 1, "company_id": 1 } request_employee_create = self.client().post( '/api/employee/', headers={ 'Content-Type': 'application/json', 'x-access-token': self.user['token'] }, data=json.dumps(json_employee)) json_data = json.loads(request_employee_create.data) self.assertTrue(json_data.get('message')) self.assertEqual( json_data.get('message'), 'No company | role | team | user found with your inputs ids') self.assertEqual(request_employee_create.status_code, 200)
def test_create_company(self): """ test company creation """ warnings.simplefilter("ignore") request_token = self.client().get('/api/login/', headers={ 'Content-Type': 'application/json', 'Authorization': _basic_auth_str( self.user.get('username'), self.user.get('password')) }) json_data = json.loads(request_token.data) self.user['token'] = json_data.get('token') json_user = { "name": "Software LTD" + string_generator(), "comment": "a software oriented company" } request_user_create = self.client().post('/api/company/', headers={ 'Content-Type': 'application/json', 'x-access-token': self.user['token'] }, data=json.dumps(json_user)) json_data = json.loads(request_user_create.data) self.assertTrue(json_data.get('message')) self.assertEqual(json_data.get('message'), 'New Company created!') self.assertEqual(request_user_create.status_code, 200)
def test_create_team(self): """ test user creation """ warnings.simplefilter("ignore") request_token = self.client().get('/api/login/', headers={ 'Content-Type': 'application/json', 'Authorization': _basic_auth_str( self.user.get('username'), self.user.get('password')) }) json_data = json.loads(request_token.data) self.user['token'] = json_data.get('token') json_team = { "name": string_generator(), "comment": 'This is a Team for CS', "company_id": 1 } request_team_create = self.client().post('/api/team/', headers={ 'Content-Type': 'application/json', 'x-access-token': self.user['token'] }, data=json.dumps(json_team)) json_data = json.loads(request_team_create.data) self.assertTrue(json_data.get('message')) self.assertEqual(json_data.get('message'), 'New Team created!')
def test_create_user(self): """ test user creation """ warnings.simplefilter("ignore") request_token = self.client().get('/api/login/', headers={ 'Content-Type': 'application/json', 'Authorization': _basic_auth_str( self.user.get('username'), self.user.get('password')) }) json_data = json.loads(request_token.data) self.user['token'] = json_data.get('token') json_user = { "name": "cyril_2", "email": string_generator() + "@email.com", "password": string_generator(), "admin": False, "profile": "Software Engineer", "skills": ["java", "C#", "Python"] } request_user_create = self.client().post('/api/user/', headers={ 'Content-Type': 'application/json', 'x-access-token': self.user['token'] }, data=json.dumps(json_user)) json_data = json.loads(request_user_create.data) self.assertTrue(json_data.get('message')) self.assertEqual(json_data.get('message'), 'New user created!') self.assertEqual(request_user_create.status_code, 200)
def test_create_new_tracking_on_a_task(self): warnings.simplefilter("ignore") request_token = self.client().get('/api/login/', headers={'Content-Type': 'application/json', 'Authorization': _basic_auth_str(self.user.get('username'), self.user.get('password'))}) json_tracking = { "comment": string_generator(), "employee_id": 8 } json_data = json.loads(request_token.data) self.user['token'] = json_data.get('token') request_create_tracking = self.client().post('/api/task/tracking/1/', headers={'Content-Type': 'application/json', 'x-access-token': self.user[ 'token']}, data=json.dumps(json_tracking)) json_data = json.loads(request_create_tracking.data) self.assertTrue(json_data.get('message')) self.assertEqual(json_data.get('message'), 'New TaskTracking created!')
def setUp(self): """ Test Setup """ self.app = app self.client = self.app.test_client self.user = { 'username': '******', 'password': '******', 'token': 'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpZCI6MSwiZXhwIjoxNTcyOTIwNjU1fQ.5x58vXL3Il3mqP9s9HmW5W3WMilW4kXFs2dp--X_BZ4' } db.session.query(Employee).delete() db.session.query(Team).delete() db.session.query(Role).delete() db.session.query(Company).delete() db.session.query(Project).delete() db.session.query(Issue).delete() for x in range(10): json_issue_test_user = {"name": "testuser_" + x.__str__(), "email": string_generator()+"@email.com", "password": string_generator(), "admin": False, "profile": "Software Engineer", "skills": ["java", "C#", "Python"]} request_user_create = self.client().post('/api/user/', headers={'Content-Type': 'application/json', 'x-access-token': self.user['token']}, data=json.dumps(json_issue_test_user)) self.assertEqual(request_user_create.status_code, 200) json_issue_test_role = dict(name="roleA", comment="role comment") request_role_create = self.client().post('/api/role/', headers={'Content-Type': 'application/json', 'x-access-token': self.user['token']}, data=json.dumps(json_issue_test_role)) self.assertEqual(request_role_create.status_code, 200) json_issue_test_company = {"name": "companyA", "comment": "company comment"} request_company_create = self.client().post('/api/company/', headers={'Content-Type': 'application/json', 'x-access-token': self.user['token']}, data=json.dumps(json_issue_test_company)) self.assertEqual(request_company_create.status_code, 200) json_issue_test_team = {"name": "teamA", "comment": "team comment", "company_id": 1} request_team_create = self.client().post('/api/team/', headers={'Content-Type': 'application/json', 'x-access-token': self.user['token']}, data=json.dumps(json_issue_test_team)) self.assertEqual(request_team_create.status_code, 200) for x in range(10): json_issue_test_employee = {"badge": "badge_"+x.__str__(), "start_date": "2019-02-19 13:10:00", "end_date": "", "is_full_time": True, "user_id": x+1, "role_id": 1, "team_id": 1, "company_id": 1} request_employee_create = self.client().post('/api/employee/', headers={'Content-Type': 'application/json', 'x-access-token': self.user['token']}, data=json.dumps(json_issue_test_employee)) self.assertEqual(request_employee_create.status_code, 200) for x in range(10): json_issue_test_project = {"name": "Project_" + x.__str__(), "start_date": "2019-02-19 13:10:00", "due_date": "2019-02-19 13:10:00", "comment": "test issue", "company_id": 1} request_project_create = self.client().post('/api/project/', headers={'Content-Type': 'application/json', 'x-access-token': self.user['token']}, data=json.dumps(json_issue_test_project)) self.assertEqual(request_project_create.status_code, 200) for x in range(5): json_issue = {"name": "issue_" + x.__str__(), "start_date": "2019-02-19 13:10:00", "due_date": "2019-02-28 20:30:00", "status": "TODO", "project_id": x+1, "employee_id": x+1} request_issue_create = self.client().post('/api/issue/', headers={'Content-Type': 'application/json', 'x-access-token': self.user['token']}, data=json.dumps(json_issue)) json_data = json.loads(request_issue_create.data) self.assertTrue(json_data.get('message')) self.assertEqual(json_data.get('message'), 'New Issue created!') self.assertEqual(request_issue_create.status_code, 200) with self.app.app_context(): # create all tables db.create_all()