def test_put_issues(self): # Can(2) will try to update an issue at an workspace in which he is a contributor. Success. valid_token = generate_token(2, datetime.timedelta(minutes=10)) data = { 'workspace_id': 2, 'issue_id': 2, 'description': "hi alperen", 'deadline': datetime.datetime(2020, 12, 30), 'is_open': False } actual_response = self.client.put('/api/workspaces/issue', data=data, headers={'auth_token': valid_token}) self.assertEqual(actual_response.status_code, 200, 'Incorrect HTTP Response Code') # Can(2) will try to update an issue at an workspace in which he is not a contributor. Fail. valid_token = generate_token(2, datetime.timedelta(minutes=10)) data = { 'workspace_id': 1, 'issue_id': 2, 'title': "alperen related issue 2", 'description': "hi alperen", 'deadline': datetime.datetime(2020, 12, 30), 'is_open': True } actual_response = self.client.put('/api/workspaces/issue', data=data, headers={'auth_token': valid_token}) # 404 is used, because active_contribution_required decorator returns 404. self.assertEqual(actual_response.status_code, 404, 'Incorrect HTTP Response Code')
def test_put_milestones(self): # Can(2) will try to update an milestone at an workspace in which he is a contributor. Success. valid_token = generate_token(2, datetime.timedelta(minutes=10)) data = { 'workspace_id': 2, 'milestone_id': 2, 'description': "MILESTONEEEEEEE", 'deadline': datetime.datetime(2020, 12, 30) } actual_response = self.client.put('/api/workspaces/milestone', data=data, headers={'auth_token': valid_token}) self.assertEqual(actual_response.status_code, 200, 'Incorrect HTTP Response Code') # Can(2) will try to update an milestone at an workspace in which he is not a contributor. Fail. valid_token = generate_token(2, datetime.timedelta(minutes=10)) data = { 'workspace_id': 1, 'milestone_id': 2, 'title': "milestoneeeee", 'description': "goodbye", 'deadline': datetime.datetime(2020, 12, 30) } actual_response = self.client.put('/api/workspaces/milestone', data=data, headers={'auth_token': valid_token}) # 404 is used, because active_contribution_required decorator returns 404. self.assertEqual(actual_response.status_code, 404, 'Incorrect HTTP Response Code')
def test_reject_follow_request(self): alperen_token = generate_token(3, datetime.timedelta(minutes=10)) data = {'follower_id': 2, 'following_id': 3, 'state': 2} actual_response = self.client.delete( '/api/follow/follow_requests', data=data, headers={'auth_token': alperen_token}) self.assertEqual(actual_response.status_code, 200, 'Incorrect HTTP Response Code') # Should return no request found. There is no follow request with these ids. data_2 = {'follower_id': 1, 'following_id': 3, 'state': 2} actual_response = self.client.delete( '/api/follow/follow_requests', data=data_2, headers={'auth_token': alperen_token}, ) self.assertEqual(actual_response.status_code, 404, 'Incorrect HTTP Response Code') # Let Can try to reject the follow request of Alperen. It should return authorization error. can_token = generate_token(2, datetime.timedelta(minutes=10)) actual_response = self.client.delete('/api/follow/follow_requests', data=data, headers={'auth_token': can_token}) self.assertEqual(actual_response.status_code, 401, 'Incorrect HTTP Response Code')
def test_get_follow_requests(self): valid_token = generate_token( 3, datetime.timedelta(minutes=10)) # token created for Alperen. actual_response = self.client.get('/api/follow/follow_requests', query_string={'following_id': 3}, headers={'auth_token': valid_token}) self.assertEqual(actual_response.status_code, 200, 'Incorrect HTTP Response Code') # Check if the follow request exists. fr_dict = actual_response.json mylist = [str(fr['id']) for fr in fr_dict["follow_requests"]] self.assertTrue( '2' in mylist, "Follow Requests does not contain Can's follow request.") # Token will be created for another user. Should return an error. another_token = generate_token( 1, datetime.timedelta(minutes=10)) # token created for Umut. actual_response = self.client.get( '/api/follow/follow_requests', query_string={'following_id': 3}, headers={'auth_token': another_token}) self.assertEqual(actual_response.status_code, 401, 'Incorrect HTTP Response Code') # Token will not be created. Login_required should return an error. actual_response = self.client.get('/api/follow/follow_requests', query_string={'following_id': 3}) self.assertEqual(actual_response.status_code, 401, 'Incorrect HTTP Response Code')
def test_get_issues(self): # Can will try to get the issues of a public workspace in which there is no issue. valid_token = generate_token(2, datetime.timedelta(minutes=10)) data = {'workspace_id': 4} actual_response = self.client.get('/api/workspaces/issue', query_string=data, headers={'auth_token': valid_token}) self.assertEqual(actual_response.status_code, 200, 'Incorrect HTTP Response Code') # Can(2) will try to get the issues of a public workspace. It should be successful. valid_token = generate_token(2, datetime.timedelta(minutes=10)) data = {'workspace_id': 1} actual_response = self.client.get('/api/workspaces/issue', query_string=data, headers={'auth_token': valid_token}) self.assertEqual(actual_response.status_code, 200, 'Incorrect HTTP Response Code') # Umut(1) will try to get the issues of a private workspace. It should be unsuccessful. valid_token = generate_token(1, datetime.timedelta(minutes=10)) data = {'workspace_id': 2} actual_response = self.client.get('/api/workspaces/issue', query_string=data, headers={'auth_token': valid_token}) self.assertEqual(actual_response.status_code, 401, 'Incorrect HTTP Response Code') # Can(2) will try to get the issues of a private workspace in which # he is an active contributor. It should be successful. valid_token = generate_token(2, datetime.timedelta(minutes=10)) data = {'workspace_id': 2} actual_response = self.client.get('/api/workspaces/issue', query_string=data, headers={'auth_token': valid_token}) self.assertEqual(actual_response.status_code, 200, 'Incorrect HTTP Response Code') # Can(2) will try to get the issues of a private workspace in which # he is not anymore active contributor. It should be unsuccessful. valid_token = generate_token(2, datetime.timedelta(minutes=10)) data = {'workspace_id': 3} actual_response = self.client.get('/api/workspaces/issue', query_string=data, headers={'auth_token': valid_token}) self.assertEqual(actual_response.status_code, 401, 'Incorrect HTTP Response Code')
def test_get_issue_info(self): # Can will try to get an issue which does not exist in that workspace. # Fail valid_token = generate_token(2, datetime.timedelta(minutes=10)) data = {'issue_id': 1, 'workspace_id': 2} actual_response = self.client.get('/api/workspaces/issue/info', query_string=data, headers={'auth_token': valid_token}) self.assertEqual(actual_response.status_code, 404, 'Incorrect HTTP Response Code') # Can(2) will try to get an issue of a public workspace. It should be successful. valid_token = generate_token(2, datetime.timedelta(minutes=10)) data = {'issue_id': 1, 'workspace_id': 1} actual_response = self.client.get('/api/workspaces/issue/info', query_string=data, headers={'auth_token': valid_token}) self.assertEqual(actual_response.status_code, 200, 'Incorrect HTTP Response Code') # Can(2) will try to get an issue of a private workspace in which # he is not anymore active contributor. It should be unsuccessful. valid_token = generate_token(2, datetime.timedelta(minutes=10)) data = {'issue_id': 3, 'workspace_id': 3} actual_response = self.client.get('/api/workspaces/issue/info', query_string=data, headers={'auth_token': valid_token}) self.assertEqual(actual_response.status_code, 401, 'Incorrect HTTP Response Code') # Can(2) will try to get an issue with its collaborators. # Success valid_token = generate_token(2, datetime.timedelta(minutes=10)) data = {'issue_id': 2, 'workspace_id': 2} actual_response = self.client.get('/api/workspaces/issue/info', query_string=data, headers={'auth_token': valid_token}) self.assertEqual(actual_response.status_code, 200, 'Incorrect HTTP Response Code') expected_list_length = 2 self.assertEqual(len(actual_response.json.get('contributors')), expected_list_length)
def test_sorting_with_alphabetical_order(self): valid_token = generate_token(2, datetime.timedelta(minutes=10)) data = { 'search_query': 'bravest', 'sorting_criteria': 5 } # alphabetical order. # Success expected_status_code = 200 actual_response = self.client.get('/api/search_engine/workspace', query_string=data, headers={'auth_token': valid_token}) self.assertEqual(actual_response.status_code, expected_status_code, 'Incorrect HTTP Response Code') # It should be in ascending order expected_workspace_ids = [3, 5] result_list = actual_response.json.get('result_list') actual_result = [] for result in result_list: actual_result.append(result.get("id")) self.assertEqual( actual_result, expected_workspace_ids, "Expected workspace ids and actual lists are not equal!")
def test_reset_password_valid(self): valid_token = generate_token(1,datetime.timedelta(minutes=10)) expected_response = {'mgs' : 'Password successfully changed'} actual_response = self.client.post("/api/auth_system/reset_password",data={'new_password' : '123456','new_password_repeat' : '123456'},headers={'auth_token' : valid_token}) self.assertEqual(actual_response.status_code,200) self.assertEqual(json.loads(actual_response.data),expected_response)
def test_reset_password_invalid_input(self): valid_token = generate_token(1,datetime.timedelta(minutes=10)) expected_response = {'error' : 'Passwords are not matched' } actual_response = self.client.post("/api/auth_system/reset_password",data={'new_password' : '123','new_password_repeat' : '123456'},headers={'auth_token' : valid_token}) self.assertEqual(actual_response.status_code,400) self.assertEqual(json.loads(actual_response.data),expected_response)
def test_post_issue_assignees(self): # Hilal(4) will try to post an issue assignee at an workspace in which she is a contributor. # Assignee(Umut(1)) is also the contributor of the workspace. # Success. valid_token = generate_token(4, datetime.timedelta(minutes=10)) data = {'workspace_id': 3, 'issue_id': 3, 'assignee_id': 1} actual_response = self.client.post('/api/workspaces/issue/assignee', data=data, headers={'auth_token': valid_token}) self.assertEqual(actual_response.status_code, 200, 'Incorrect HTTP Response Code') # Can(2) will try to post an issue assignee at an workspace in which he is a contributor. # Assignee is not a contributor of the workspace. # Fail. valid_token = generate_token(2, datetime.timedelta(minutes=10)) data = {'workspace_id': 2, 'issue_id': 2, 'assignee_id': 4} actual_response = self.client.post('/api/workspaces/issue/assignee', data=data, headers={'auth_token': valid_token}) self.assertEqual(actual_response.status_code, 404, 'Incorrect HTTP Response Code') # Can(2) will try to post issue assignee at an workspace in which he is not a contributor. Fail. valid_token = generate_token(2, datetime.timedelta(minutes=10)) data = {'workspace_id': 1, 'issue_id': 1, 'assignee_id': 4} actual_response = self.client.post('/api/workspaces/issue/assignee', data=data, headers={'auth_token': valid_token}) self.assertEqual(actual_response.status_code, 404, 'Incorrect HTTP Response Code') # Can(2) will try to post an issue assignee at an workspace in which he is a contributor. # However, that person already exists in the issue assignees. # Fail. valid_token = generate_token(2, datetime.timedelta(minutes=10)) data = {'workspace_id': 2, 'issue_id': 2, 'assignee_id': 3} actual_response = self.client.post('/api/workspaces/issue/assignee', data=data, headers={'auth_token': valid_token}) self.assertEqual(actual_response.status_code, 403, 'Incorrect HTTP Response Code')
def test_get_issue_assignees(self): # Hilal(4) will try to get the issue assignees of a public workspace in which there is no issue assignee. # Success valid_token = generate_token(4, datetime.timedelta(minutes=10)) data = {'workspace_id': 3, 'issue_id': 3} actual_response = self.client.get('/api/workspaces/issue/assignee', query_string=data, headers={'auth_token': valid_token}) self.assertEqual(actual_response.status_code, 200, 'Incorrect HTTP Response Code') # Can(2) will try to get the issue assignees at a public workspace. Success. valid_token = generate_token(2, datetime.timedelta(minutes=10)) data = {'workspace_id': 1, 'issue_id': 1} actual_response = self.client.get('/api/workspaces/issue/assignee', query_string=data, headers={'auth_token': valid_token}) self.assertEqual(actual_response.status_code, 200, 'Incorrect HTTP Response Code') # Can(2) will try to get the issue assignees at a private workspace. Fail. valid_token = generate_token(2, datetime.timedelta(minutes=10)) data = {'workspace_id': 3, 'issue_id': 3} actual_response = self.client.get('/api/workspaces/issue/assignee', query_string=data, headers={'auth_token': valid_token}) self.assertEqual(actual_response.status_code, 401, 'Incorrect HTTP Response Code') # Can(2) will try to get the issue assignees at a private workspace # in which he is a contributor. Success. valid_token = generate_token(2, datetime.timedelta(minutes=10)) data = {'workspace_id': 2, 'issue_id': 2} actual_response = self.client.get('/api/workspaces/issue/assignee', query_string=data, headers={'auth_token': valid_token}) self.assertEqual(actual_response.status_code, 200, 'Incorrect HTTP Response Code')
def test_deadline_filter(self): # Check that without a deadline filter, workspace_ids 3 and 5 is found with "bravest" query. valid_token = generate_token(2, datetime.timedelta(minutes=10)) data = {'search_query': 'bravest'} # Success expected_status_code = 200 actual_response = self.client.get('/api/search_engine/workspace', query_string=data, headers={'auth_token': valid_token}) self.assertEqual(actual_response.status_code, expected_status_code, 'Incorrect HTTP Response Code') expected_workspace_ids = [3, 5] result_list = actual_response.json.get('result_list') actual_result = [] for result in result_list: actual_result.append(result.get("id")) self.assertEqual( actual_result, expected_workspace_ids, "Expected workspace ids and actual lists are not equal!") # Check that with a deadline filter, only workspace_id=5 is found with "bravest" query. valid_token = generate_token(2, datetime.timedelta(minutes=10)) data = { 'search_query': 'bravest', 'deadline_start': datetime.datetime(2021, 7, 1, 23, 59, 59), 'deadline_end': datetime.datetime(2021, 12, 30, 23, 59, 59) } # Success expected_status_code = 200 actual_response = self.client.get('/api/search_engine/workspace', query_string=data, headers={'auth_token': valid_token}) self.assertEqual(actual_response.status_code, expected_status_code, 'Incorrect HTTP Response Code') expected_workspace_ids = [5] result_list = actual_response.json.get('result_list') actual_result = [] for result in result_list: actual_result.append(result.get("id")) self.assertEqual( actual_result, expected_workspace_ids, "Expected workspace ids and actual lists are not equal!")
def test_empty_result(self): valid_token = generate_token(2, TestConfig.SESSION_DURATION) actual_response = self.client.get("/api/search_engine/search_history", query_string={"search_type": 2}, headers={"auth_token": valid_token}) expected_response = {"search_history": []} self.assertEqual(actual_response.status_code, 200) self.assertEqual(json.loads(actual_response.data), expected_response)
def test_delete_report(self): valid_token = generate_token(1, datetime.timedelta(minutes=10)) actual_response = self.client.delete( '/api/follow/report', query_string={'report_id': 1}, headers={'auth_token': valid_token}) self.assertEqual(actual_response.status_code, 200, 'Incorrect HTTP Response Code')
def test_get_notification_invalid(self): valid_token = generate_token(2,TestConfig.SESSION_DURATION) + "c" expected_response = {'error' : 'Wrong Token Format'} actual_response = self.client.get("/api/profile/notifications",headers = {"auth_token" : valid_token}) self.assertEqual(actual_response.status_code,401) self.assertEqual(expected_response,json.loads(actual_response.data))
def test_send_follow_requests(self): umut_token = generate_token(1, datetime.timedelta(minutes=10)) data = {'follower_id': 1, 'following_id': 4} # 1: Umut, 4: Hilal actual_response = self.client.post('/api/follow/follow_requests', data=data, headers={'auth_token': umut_token}) self.assertEqual(actual_response.status_code, 200, 'Incorrect HTTP Response Code') # Let's see if follow request can be seen by Hilal. data = {'following_id': 4} hilal_token = generate_token(4, datetime.timedelta(minutes=10)) follow_requests_list = self.client.get( '/api/follow/follow_requests', query_string=data, headers={'auth_token': hilal_token}) self.assertEqual(follow_requests_list.status_code, 200, 'Incorrect HTTP Response Code') umut_id = 1 mylist = [ fr['id'] for fr in follow_requests_list.json['follow_requests'] ] self.assertTrue(umut_id in mylist, "Follow Request of corresponding ID does not exist!") # Another Case. Let's follow a public profile. It should create Follow record, not FollowRequest record. can_token = generate_token(2, datetime.timedelta(minutes=10)) data = {'follower_id': 2, 'following_id': 1} # 1: Umut, 2: Can actual_response = self.client.post('/api/follow/follow_requests', data=data, headers={'auth_token': can_token}) self.assertEqual(actual_response.status_code, 200, 'Incorrect HTTP Response Code') follow_list = self.client.get('/api/follow/followers', query_string={'following_id': 1}, headers={'auth_token': can_token}) self.assertEqual(follow_list.status_code, 200, 'Incorrect HTTP Response Code') fr_dict = follow_list.json mylist = [fr['id'] for fr in fr_dict['followers']] self.assertTrue(2 in mylist, "Follow record of corresponding ID does not exist!")
def test_get_notification_valid(self): valid_token = generate_token(2,TestConfig.SESSION_DURATION) notification = Notification.query.filter(Notification.id == 2).first() expected_response = [{'id':2,'text': 'Umut deletes a workspace','link':'/workspace/1', 'timestamp' : notification.timestamp,'related_users': [1]}] actual_response = self.client.get("/api/profile/notifications",headers = {"auth_token" : valid_token}) self.assertEqual(actual_response.status_code,200) self.assertEqual(expected_response[0]['id'],json.loads(actual_response.data)["notification_list"][0]['id'])
def test_delete_notification_invalid(self): valid_token = generate_token(1,TestConfig.SESSION_DURATION) expected_response = {'error':'Notification Not Found'} actual_response = self.client.delete("/api/profile/notifications",data = {'notification_id' : 3},headers = {"auth_token" : valid_token}) self.assertEqual(actual_response.status_code,404) self.assertEqual(expected_response,json.loads(actual_response.data)) self.assertIsNotNone(Notification.query.filter(Notification.id == 1).first()) self.assertIsNotNone(NotificationRelatedUser.query.filter(NotificationRelatedUser.notification_id == 1).first())
def test_get_follower_list(self): # Returns the follower list of the user. # e.g. Umut and Alperen follows Can. Then Can's follower list should contain their IDs. valid_token = generate_token(1, datetime.timedelta(minutes=10)) actual_response = self.client.get('/api/follow/followers', query_string={'following_id': 2}, headers={'auth_token': valid_token}) self.assertEqual(actual_response.status_code, 200, 'Incorrect HTTP Response Code')
def test_get_following_list(self): # Returns the following list of the user. # e.g. if Umut follows Can, Umut's following list should include Can. valid_token = generate_token(1, datetime.timedelta(minutes=10)) actual_response = self.client.get('/api/follow/followings', query_string={'follower_id': 1}, headers={'auth_token': valid_token}) self.assertEqual(actual_response.status_code, 200, 'Incorrect HTTP Response Code')
def test_post_report_valid(self): valid_token = generate_token(1, datetime.timedelta(minutes=10)) data = {'reported_user_id': 2, 'text': "report"} expected_response = { 'msg': 'Report addition is successfully sent via email' } actual_response = self.client.post('/api/follow/report', data=data, headers={'auth_token': valid_token}) self.assertEqual(expected_response, json.loads(actual_response.data)) self.assertEqual(actual_response.status_code, 200, 'Incorrect HTTP Response Code')
def test_remove_research_info_invalid(self): valid_token = generate_token(2,TestConfig.SESSION_DURATION) data = { 'research_id':1 } expected_result = { 'error':'You can not delete other user\'s information' } actual_response = self.client.delete("/api/profile/research_information",data=data,headers={'auth_token' : valid_token}) self.assertEqual(expected_result,json.loads(actual_response.data)) self.assertEqual(400,actual_response.status_code) self.assertIsNotNone(ResearchInformation.query.filter(ResearchInformation.id == 1).first())
def test_remove_research_info_valid(self): valid_token = generate_token(1,TestConfig.SESSION_DURATION) data = { 'research_id':1 } expected_result = { 'msg':'Successfully Deleted' } actual_response = self.client.delete("/api/profile/research_information",data=data,headers={'auth_token' : valid_token}) self.assertEqual(expected_result,json.loads(actual_response.data)) self.assertEqual(200,actual_response.status_code) self.assertIsNone(ResearchInformation.query.filter(ResearchInformation.id == 1).first())
def test_post_issue_comments(self): # Can(2) will try to post issue comment at an workspace in which he is a contributor. Success. valid_token = generate_token(2, datetime.timedelta(minutes=10)) data = {'workspace_id': 2, 'issue_id': 2, 'comment': "GREAAAT"} actual_response = self.client.post('/api/workspaces/issue/comment', data=data, headers={'auth_token': valid_token}) self.assertEqual(actual_response.status_code, 200, 'Incorrect HTTP Response Code') # Can(2) will try to post issue comment at an workspace in which he is not a contributor. Fail. valid_token = generate_token(2, datetime.timedelta(minutes=10)) data = {'workspace_id': 1, 'issue_id': 1, 'comment': "BADDDD"} actual_response = self.client.post('/api/workspaces/issue/comment', data=data, headers={'auth_token': valid_token}) self.assertEqual(actual_response.status_code, 404, 'Incorrect HTTP Response Code')
def test_add_research_info_invalid(self): valid_token = generate_token(1,TestConfig.SESSION_DURATION) data = { 'title' : 'Radar Preprocessing using DBCAN Clustring', 'description' : 'Preprocessing the radar hits using DBCAN Algorithm' } expected_response = { 'error' : 'Wrong input format' } actual_response = self.client.post("/api/profile/research_information",data=data,headers={'auth_token' : valid_token}) self.assertEqual(expected_response,json.loads(actual_response.data)) self.assertEqual(400,actual_response.status_code) self.assertIsNone(ResearchInformation.query.filter(ResearchInformation.research_title == 'Radar Preprocessing using DBCAN Clustring').first())
def skills_delete_invalid(self): valid_token = generate_token(1,TestConfig.SESSION_DURATION) data = { 'id': 100 } expected_result = { 'error': 'Skill does not exist' } actual_response = self.client.delete("/api/profile/skills", data=data, headers={'auth_token': valid_token}) self.assertEqual(expected_result, json.loads(actual_response.data)) self.assertEqual(400, actual_response.status_code) self.assertIsNotNone(Skills.query.filter(Skills.id == 100).first())
def skills_post_invalid(self): valid_token = generate_token(2,TestConfig.SESSION_DURATION) data = { 'title': 'german' } expected_response = { 'error': 'Wrong Input Format' } actual_response = self.client.post("/api/profile/skills", data=data, headers={'auth_token': valid_token}) self.assertEqual(expected_response, json.loads(actual_response.data)) self.assertEqual(400, actual_response.status_code) self.assertIsNone(Skills.query.filter(Skills.name == 'german').first())
def skills_delete_valid(self): valid_token = generate_token(1,TestConfig.SESSION_DURATION) data = { 'id': 1 } expected_result = { 'msg': 'Successfully Deleted' } actual_response = self.client.delete("/api/profile/skills", data=data, headers={'auth_token': valid_token}) self.assertEqual(expected_result, json.loads(actual_response.data)) self.assertEqual(200, actual_response.status_code) self.assertIsNone(Skills.query.filter(Skills.id == 1).first())
def test_no_element_found(self): valid_token = generate_token(2, datetime.timedelta(minutes=10)) data = {'search_query': 'sattas los mancos'} # Success expected_status_code = 200 actual_response = self.client.get('/api/search_engine/workspace', query_string=data, headers={'auth_token': valid_token}) self.assertEqual(actual_response.status_code, expected_status_code, 'Incorrect HTTP Response Code') self.assertEqual(len(actual_response.json.get('result_list')), 0, "Workspace is not found in the searched list")
def test_ue_search_history(self): valid_token = generate_token(1, TestConfig.SESSION_DURATION) actual_response = self.client.get("/api/search_engine/search_history", query_string={"search_type": 2}, headers={"auth_token": valid_token}) expected_response = { "search_history": [{ "query": "nanonetwork", "number_of_use": 1 }] } self.assertEqual(actual_response.status_code, 200) self.assertEqual(json.loads(actual_response.data), expected_response)