From 63472d8de5e978b51d6145b07c6e4e12463da954 Mon Sep 17 00:00:00 2001
From: cedricb12 <123005335+cedricb12@users.noreply.github.com>
Date: Mon, 8 Apr 2024 16:33:56 -0500
Subject: [PATCH 1/3] added some back end tests
- Added tests for notification api routing
- Improves test coverage
---
ReadMe.md | 2 +-
epoch_backend/tests/webserver_tests.py | 34 ++++++++++++++++++++++++--
2 files changed, 33 insertions(+), 3 deletions(-)
diff --git a/ReadMe.md b/ReadMe.md
index cc1fb91..ad60952 100644
--- a/ReadMe.md
+++ b/ReadMe.md
@@ -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)
diff --git a/epoch_backend/tests/webserver_tests.py b/epoch_backend/tests/webserver_tests.py
index c6484b2..4deff7d 100644
--- a/epoch_backend/tests/webserver_tests.py
+++ b/epoch_backend/tests/webserver_tests.py
@@ -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."
@@ -724,9 +724,39 @@ 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)
+
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
\ No newline at end of file
From 97e51876404f2e6bf96e4a0f8d49ef5c31fe4481 Mon Sep 17 00:00:00 2001
From: cedricb12 <123005335+cedricb12@users.noreply.github.com>
Date: Mon, 8 Apr 2024 17:33:11 -0500
Subject: [PATCH 2/3] improved test coverage
- added a few more test but added code mostly just improves coverage
---
.../business/api_endpoints/router.py | 3 -
epoch_backend/tests/webserver_tests.py | 87 +++++++++++++++++++
2 files changed, 87 insertions(+), 3 deletions(-)
diff --git a/epoch_backend/business/api_endpoints/router.py b/epoch_backend/business/api_endpoints/router.py
index c2a5efc..65cc3a5 100644
--- a/epoch_backend/business/api_endpoints/router.py
+++ b/epoch_backend/business/api_endpoints/router.py
@@ -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"
405 Method Not Allowed
")
diff --git a/epoch_backend/tests/webserver_tests.py b/epoch_backend/tests/webserver_tests.py
index 4deff7d..2ff63b2 100644
--- a/epoch_backend/tests/webserver_tests.py
+++ b/epoch_backend/tests/webserver_tests.py
@@ -754,6 +754,93 @@ def test_z12_put_notification_test(self):
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': 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
if __name__ == '__main__':
unittest.main()
From 6611bb3345dca36457a8b40e73572b1e87fb07c3 Mon Sep 17 00:00:00 2001
From: cedricb12 <123005335+cedricb12@users.noreply.github.com>
Date: Mon, 8 Apr 2024 18:02:49 -0500
Subject: [PATCH 3/3] more tests
- added more tests improving coverage
- removed old load test from webserver tests since it is handled elsewhere now
---
epoch_backend/tests/webserver_tests.py | 53 +++++++++++++++++++++++++-
1 file changed, 51 insertions(+), 2 deletions(-)
diff --git a/epoch_backend/tests/webserver_tests.py b/epoch_backend/tests/webserver_tests.py
index 2ff63b2..b468950 100644
--- a/epoch_backend/tests/webserver_tests.py
+++ b/epoch_backend/tests/webserver_tests.py
@@ -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/',
@@ -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/',
@@ -805,9 +806,13 @@ def test_z13_router_coverage(self):
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()})
@@ -842,6 +847,50 @@ def test_z17_comment_api_coverage(self):
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()