Skip to content

Commit

Permalink
Implemented test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
omjain2001 committed Oct 25, 2023
1 parent d13ef98 commit 00acfca
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 28 deletions.
6 changes: 6 additions & 0 deletions backend/requirements_2.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down
79 changes: 51 additions & 28 deletions backend/test_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import datetime
from flask_mongoengine import MongoEngine
import yaml
import certifi
from app import create_app, Users


Expand All @@ -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()
Expand All @@ -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"] = []
Expand Down Expand Up @@ -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"] == "[email protected]"


def test_updateProfile(client, user):
userDetails, headers = user
headers = {**headers, "userid": userDetails.id}
updatedUser = client.post(
"/updateProfile", json={"email": "[email protected]"}, 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"] == "[email protected]"

# 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

0 comments on commit 00acfca

Please sign in to comment.