Skip to content

Commit

Permalink
Merge pull request #373 from Aymanhki/cedricb12
Browse files Browse the repository at this point in the history
  • Loading branch information
Aymanhki authored Apr 8, 2024
2 parents 7c642fe + 6611bb3 commit fdedf7c
Show file tree
Hide file tree
Showing 3 changed files with 170 additions and 7 deletions.
2 changes: 1 addition & 1 deletion ReadMe.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,4 @@ Epoch is a social media platform for time capsules. Write down your thoughts, fe
- [Block Diagram](/epoch_project_documents/BlockDiagram)
- [Testing Plan](/epoch_project_documents/TestingPlan)
- [Sequence Diagrams](/epoch_project_documents/SequenceDiagrams)
- [Manual Acceptance Tests](https://github.com/Aymanhki/Epoch/wiki/Manual-Acceptance-Tests)
- [Manual Acceptance Tests / User Manual](https://github.com/Aymanhki/Epoch/wiki/Manual-Acceptance-Tests)
3 changes: 0 additions & 3 deletions epoch_backend/business/api_endpoints/router.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,6 @@ def handle_api_request(method, path, request_data, conn):
session_id = get_session_id_from_request(request_data)
get_user(conn, request_data, session_id)

elif method == "DELETE":
pass # log out logic

else:
send_response(conn, 405, "Method Not Allowed", body=b"<h1>405 Method Not Allowed</h1>")

Expand Down
172 changes: 169 additions & 3 deletions epoch_backend/tests/webserver_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class webserver_tests(unittest.TestCase):
server_thread = None
web_server = None
# allow us to go in manually if something happens when deleting this account
username = "WebserverTests"+str(random.randint(1000,9999))
username = "WebserverTests" + str(random.randint(1000,9999))
password = "Newuser1!"
name = "some name"
bio = "a big long bio with lots of words but no special characters."
Expand Down Expand Up @@ -318,6 +318,7 @@ def test_p_register_user_with_picture(self):
assert (response.status_code == 200)
print("User with picture registered and deleted.")

'''
def register_user(self, i, usernames, passwords, names, bios, session_ids, user_ids, media_ids):
print(f"Registering user {i}...")
response = requests.post('http://localhost:8080/api/register/',
Expand Down Expand Up @@ -438,7 +439,7 @@ def test_q_load_test(self):
for i in range(EXTREME_TEST_RANGE):
threads[i].join()

'''
def register_test_user(self):
# create a test account if it already exist log in to it
response = requests.post('http://localhost:8080/api/register/',
Expand Down Expand Up @@ -724,9 +725,174 @@ def test_z09_post_votes_test(self): # POST DELETE "/api/vote/post/"
self.assertEqual(response_json[0]["votes_count"], 0)
self.delete_post()

def test_z10_get_notification_test(self):
self.register_test_user()
response = requests.get('http://localhost:8080/api/notifications/user/',
cookies={'epoch_session_id': self.get_session_id()},
headers={'User-Id': str(self.get_user_id()), 'Offset': '0', 'Limit': '0'})
self.assertEqual(response.status_code, 200)
# check that we reject when fields missing
response = requests.get('http://localhost:8080/api/notifications/user/',
cookies={'epoch_session_id': self.get_session_id()})
self.assertEqual(response.status_code, 400)

def test_z11_read_notification_test(self):
self.register_test_user()
response = requests.put('http://localhost:8080/api/notifications/id/',
cookies={'epoch_session_id': self.get_session_id()},
headers={'User-Id': str(self.get_user_id()), 'Notif-Id': '69420'})
self.assertEqual(response.status_code, 200)
response = requests.put('http://localhost:8080/api/notifications/id/',
cookies={'epoch_session_id': self.get_session_id()})
self.assertEqual(response.status_code, 400)

def test_z12_put_notification_test(self):
self.register_test_user()
response = requests.put('http://localhost:8080/api/notifications/read/all/user/',
cookies={'epoch_session_id': self.get_session_id()},
headers={'User-Id': str(self.get_user_id())})
self.assertEqual(response.status_code, 200)
response = requests.put('http://localhost:8080/api/notifications/read/all/user/',
cookies={'epoch_session_id': self.get_session_id()})
self.assertEqual(response.status_code, 400)

def test_z13_router_coverage(self):
# this test just covers the "return 405" lines in router
self.register_test_user()
response = requests.head('http://localhost:8080/not_api/')
self.assertEqual(response.status_code, 404)
response = requests.head('http://localhost:8080/api/notfound/',
cookies={'epoch_session_id': self.get_session_id()})
self.assertEqual(response.status_code, 404)
response = requests.head('http://localhost:8080/api/login/',
cookies={'epoch_session_id': self.get_session_id()})
self.assertEqual(response.status_code, 405)
response = requests.head('http://localhost:8080/api/register/',
cookies={'epoch_session_id': self.get_session_id()})
self.assertEqual(response.status_code, 405)
response = requests.head('http://localhost:8080/api/delete/userId/',
cookies={'epoch_session_id': self.get_session_id()})
self.assertEqual(response.status_code, 405)
response = requests.head('http://localhost:8080/api/delete/username/',
cookies={'epoch_session_id': self.get_session_id()})
self.assertEqual(response.status_code, 405)
response = requests.head('http://localhost:8080/api/user/',
cookies={'epoch_session_id': self.get_session_id()})
self.assertEqual(response.status_code, 405)
response = requests.head('http://localhost:8080/api/user/posts/',
cookies={'epoch_session_id': self.get_session_id()})
self.assertEqual(response.status_code, 405)
response = requests.head('http://localhost:8080/api/followed/posts/',
cookies={'epoch_session_id': self.get_session_id()})
self.assertEqual(response.status_code, 405)
response = requests.head('http://localhost:8080/api/favorite/posts/',
cookies={'epoch_session_id': self.get_session_id()})
self.assertEqual(response.status_code, 405)
response = requests.head('http://localhost:8080/api/upload/profile/1/',
cookies={'epoch_session_id': self.get_session_id()})
self.assertEqual(response.status_code, 405)
response = requests.head('http://localhost:8080/api/comments/post/',
cookies={'epoch_session_id': self.get_session_id()})
self.assertEqual(response.status_code, 405)
response = requests.head('http://localhost:8080/api/comments/post/',
cookies={'epoch_session_id': self.get_session_id()})
self.assertEqual(response.status_code, 405)
response = requests.head('http://localhost:8080/api/comments/delete/',
cookies={'epoch_session_id': self.get_session_id()})
self.assertEqual(response.status_code, 405)
response = requests.head('http://localhost:8080/api/comments/get/',
cookies={'epoch_session_id': self.get_session_id()})
self.assertEqual(response.status_code, 405)
response = requests.head('http://localhost:8080/api/vote/post/',
cookies={'epoch_session_id': self.get_session_id()})
self.assertEqual(response.status_code, 405)

def test_z14_delete_by_username(self):
self.register_test_user()
response = requests.delete('http://localhost:8080/api/delete/username/',
json={'username': "5834cantfindusername"},
cookies={'epoch_session_id': self.get_session_id()})
self.assertEqual(response.status_code, 404)
response = requests.delete('http://localhost:8080/api/delete/username/',
json={'username': self.username},
cookies={'epoch_session_id': self.get_session_id()})
self.assertEqual(response.status_code, 200)

def test_z15_follow_missing_fields(self):
self.register_test_user()
response = requests.post('http://localhost:8080/api/follow/followerList/',
json={'target': str(self.get_user_id())},
cookies={'epoch_session_id': self.get_session_id()})
self.assertEqual(response.status_code, 200)
response = requests.post('http://localhost:8080/api/follow/followingList/',
json={'target': str(self.get_user_id())},
cookies={'epoch_session_id': self.get_session_id()})
self.assertEqual(response.status_code, 200)
response = requests.post('http://localhost:8080/api/follow/follow/',
cookies={'epoch_session_id': self.get_session_id()})
self.assertEqual(response.status_code, 500)
response = requests.post('http://localhost:8080/api/follow/unfollow/',
cookies={'epoch_session_id': self.get_session_id()})
self.assertEqual(response.status_code, 500)

def test_z16_post_api_coverage(self):
self.register_test_user()
response = requests.delete('http://localhost:8080/api/user/posts/',
headers={'Post-Id': "912991398934", 'User-Id': str(self.get_user_id())})
self.assertEqual(response.status_code, 404)

def test_z17_comment_api_coverage(self):
pass

def test_z18_user_api_coverage(self):
pass

def test_z19_post_with_mentions(self):
self.register_test_user()
response = requests.post('http://localhost:8080/api/post/',
cookies={'epoch_session_id': self.get_session_id()},
json={'postText': "test mention @cedric", 'file': base64.b64encode(TEST_PROFILE_PIC_BINARY).decode('utf-8'),
'fileType': 'image/jpeg', 'fileName': 'test.jpg', 'postNow': 'true', 'selectedDate': self.post_creation_time,
'createdAt': self.post_creation_time, 'username': self.username, 'time_zone': '+5:00'})
self.assertEqual(response.status_code, 200)
response = requests.get('http://localhost:8080/api/user/posts/',
cookies={'epoch_session_id': self.get_session_id()},
headers={'User-Id': str(self.get_user_id()), 'Offset': '0', 'Limit': '100'})
self.assertEqual(response.status_code, 200)
response_json = response.json()
response = requests.put('http://localhost:8080/api/user/posts/',
cookies={'epoch_session_id': self.get_session_id()},
headers={'User-Id': str(self.get_user_id()), 'Offset': '0', 'Limit': '100'},
json={'postId': response_json[0]["post_id"], 'username': self.username,
'fileName': '', 'fileType': '', 'file': '', 'postNow': 'true', 'postText': 'updated text #webservertest',
'selectedDate': self.post_creation_time, 'createdAt': self.post_creation_time, 'oldFileRemoved': 'false'})
self.delete_post()

def test_z20_remove_post(self):
self.register_test_user()
self.make_post()
response = requests.get('http://localhost:8080/api/user/posts/',
cookies={'epoch_session_id': self.get_session_id()},
headers={'User-Id': str(self.get_user_id()) })
self.assertEqual(response.status_code, 200)
response_json = response.json()
for post in response_json:
response = requests.delete('http://localhost:8080/api/user/posts/',
headers={'Post-Id': str(post["post_id"]), 'User-Id': str(self.get_user_id())})
self.assertEqual(response.status_code, 200)

def test_z21_cors_coverage(self):
self.register_test_user()
self.make_post()
response = requests.options('http://localhost:8080/api/user/posts/',
cookies={'epoch_session_id': self.get_session_id()},
headers={'User-Id': str(self.get_user_id()) })
self.assertEqual(response.status_code, 204)
self.delete_post()


if __name__ == '__main__':
unittest.main()


# python -m pytest ./epoch_backend/tests/webserver_tests.py
# python -m pytest --cov-config=.coveragerc --cov=epoch_backend -rA --color=yes --disable-warnings --disable-pytest-warnings --cov-report=html ./epoch_backend/tests/webserver_tests.py

0 comments on commit fdedf7c

Please sign in to comment.