diff --git a/backend/requirements_2.txt b/backend/requirements_2.txt index fbce4ea2..ad990e1a 100644 --- a/backend/requirements_2.txt +++ b/backend/requirements_2.txt @@ -19,6 +19,7 @@ cycler==0.10.0 decorator==4.4.2 dnspython==2.4.2 email-validator==2.0.0.post2 +exceptiongroup==1.1.3 fake-useragent==1.3.0 Flask==2.2.2 Flask-Cors==3.0.10 @@ -34,6 +35,7 @@ h5py==3.10.0 idna==2.10 importlib-metadata==6.8.0 importlib-resources==6.1.0 +iniconfig==2.0.0 ipykernel==5.3.4 ipython==7.19.0 ipython-genutils==0.2.0 @@ -62,6 +64,7 @@ parso==0.7.1 pexpect==4.8.0 pickleshare==0.7.5 Pillow==8.1.0 +pluggy==1.3.0 prompt-toolkit==3.0.8 protobuf==3.14.0 ptyprocess==0.6.0 @@ -72,6 +75,8 @@ Pygments==2.7.2 pylint==2.6.0 pymongo==4.5.0 pyparsing==2.4.7 +pytest==7.4.2 +pytest-mock==3.12.0 python-dateutil==2.8.1 python-dotenv==1.0.0 pytz==2020.4 @@ -87,6 +92,7 @@ six==1.15.0 soupsieve==2.2.1 termcolor==1.1.0 toml==0.10.2 +tomli==2.0.1 tornado==6.1 traitlets==5.0.5 urllib3==1.26.2 diff --git a/backend/test_app.py b/backend/test_app.py index e91a7a9e..584d6066 100644 --- a/backend/test_app.py +++ b/backend/test_app.py @@ -9,6 +9,7 @@ import datetime from flask_mongoengine import MongoEngine import yaml +import certifi from app import create_app, Users @@ -32,7 +33,7 @@ def client(): password = info["password"] app.config["MONGODB_SETTINGS"] = { "db": "appTracker", - "host": f"mongodb+srv://{username}:{password}@applicationtracker.287am.mongodb.net/myFirstDatabase?retryWrites=true&w=majority", + "host": f"mongodb+srv://{username}:{password}@cluster0.r0056lg.mongodb.net/appTracker?tls=true&tlsCAFile={certifi.where()}&retryWrites=true&w=majority", } db = MongoEngine() db.disconnect() @@ -51,7 +52,7 @@ def user(client): :return: the user object and auth token """ # print(request.data) - data = {"username": "testUser", "password": "test", "fullName": "fullName"} + data = {"username": "asmith", "password": "asmith", "fullName": "Adam Smith"} user = Users.objects(username=data["username"]) user.first()["applications"] = [] @@ -233,34 +234,56 @@ def test_logout(client, user): :param client: mongodb client :param user: the test user object """ - user, auth = user + userVar, auth = user rv = client.post("/users/logout", headers=auth) # assert no error occured assert rv.status_code == 200 -def test_resume(client, mocker, user): - """ - Tests that using the resume endpoint returns data - - :param client: mongodb client - :param mocker: pytest mocker - :param user: the test user object - """ - mocker.patch( - # Dataset is in slow.py, but imported to main.py - "app.get_new_user_id", - return_value=-1, - ) - user, header = user - user["applications"] = [] - user.save() - data = dict( - file=(BytesIO(b"testing resume"), "resume.txt"), - ) - rv = client.post( - "/resume", headers=header, content_type="multipart/form-data", data=data - ) - assert rv.status_code == 200 - rv = client.get("/resume", headers=header) - assert rv.status_code == 200 +def test_getProfile(client, user): + userDetails, headers = user + print(userDetails) + print(headers) + headers = {**headers, "userid": userDetails.id} + userProfile = client.get("/getProfile", headers=headers) + rv = json.loads(userProfile.data.decode("utf-8")) + assert rv["email"] == "asmith@ncsu.edu" + + +def test_updateProfile(client, user): + userDetails, headers = user + headers = {**headers, "userid": userDetails.id} + updatedUser = client.post( + "/updateProfile", json={"email": "asmith@ncsu.edu"}, headers=headers) + rv = json.loads(updatedUser.data.decode("utf-8")) + print(rv) + + fetchUser = client.get("/getProfile", headers=headers) + res = json.loads(fetchUser.data.decode("utf-8")) + assert res["email"] == "asmith@ncsu.edu" + +# def test_resume(client, mocker, user): +# """ +# Tests that using the resume endpoint returns data + +# :param client: mongodb client +# :param mocker: pytest mocker +# :param user: the test user object +# """ +# mocker.patch( +# # Dataset is in slow.py, but imported to main.py +# "app.get_new_user_id", +# return_value=-1, +# ) +# user, header = user +# user["applications"] = [] +# user.save() +# data = dict( +# file=(BytesIO(b"testing resume"), "resume.txt"), +# ) +# rv = client.post( +# "/resume", headers=header, content_type="multipart/form-data", data=data +# ) +# assert rv.status_code == 200 +# rv = client.get("/resume", headers=header) +# assert rv.status_code == 200