aboutsummaryrefslogtreecommitdiff
path: root/app/tests/test_views.py
diff options
context:
space:
mode:
authorNavan Chauhan <navanchauhan@gmail.com>2021-06-06 15:44:45 +0530
committerGitHub <noreply@github.com>2021-06-06 15:44:45 +0530
commit62a5ca363415b0f6f98785b6c3522a71fc895a72 (patch)
tree6fb829110658369321bab897707132f76f9b1b2c /app/tests/test_views.py
parent57207efe38174666d40964b74856537c6f5314ab (diff)
parent6595d53212eaa4b9319da7196f5e2286d30eb462 (diff)
Merge pull request #1 from navanchauhan/deepsource-transform-10f49d7d
Format code with black
Diffstat (limited to 'app/tests/test_views.py')
-rw-r--r--app/tests/test_views.py222
1 files changed, 110 insertions, 112 deletions
diff --git a/app/tests/test_views.py b/app/tests/test_views.py
index 0abd5e4..811815f 100644
--- a/app/tests/test_views.py
+++ b/app/tests/test_views.py
@@ -1,122 +1,120 @@
from itsdangerous.url_safe import URLSafeSerializer
from app import app as flask_app
+
ts = URLSafeSerializer(flask_app.config["SECRET_KEY"])
data2check_visitors = {
- "/index": {
- "code": 200, "data": b"Nice Tagline"
- },
- "/": {
- "code": 200, "data": b"Nice Tagline"
- },
- "/ContactUs":{
- "code": 200, "data": b"send us a message."
- },
- "/doesnotexists":{
- "code": 404, "data": b"Page Not Found"
- },
- "/logout":{
- "code": 200, "data": b"You have been logged out."
- },
- "/dashboard":{
- "code":401,"data":b"You need to be logged in to access this resource"
- },
- "/signup":{
- "code":200,"data":b"Register your account."
- },
- "/signin":{
- "code":200,"data":b"Sign in to your account."
- },
- "/Simulate500":{
- "code":500,"data":b"Server Could Not Process This."
- },
- "/admin/user/":{
- "code":403,"data":b"Forbidden"
- },
- "/confirm":{
- "code":200,"data":b"Token not provided in URL Parameter"
- },
- "/confirm?confirmation_token=123":{
- "code":200,"data":b"Bad Token Provided"
- }
+ "/index": {"code": 200, "data": b"Nice Tagline"},
+ "/": {"code": 200, "data": b"Nice Tagline"},
+ "/ContactUs": {"code": 200, "data": b"send us a message."},
+ "/doesnotexists": {"code": 404, "data": b"Page Not Found"},
+ "/logout": {"code": 200, "data": b"You have been logged out."},
+ "/dashboard": {
+ "code": 401,
+ "data": b"You need to be logged in to access this resource",
+ },
+ "/signup": {"code": 200, "data": b"Register your account."},
+ "/signin": {"code": 200, "data": b"Sign in to your account."},
+ "/Simulate500": {"code": 500, "data": b"Server Could Not Process This."},
+ "/admin/user/": {"code": 403, "data": b"Forbidden"},
+ "/confirm": {"code": 200, "data": b"Token not provided in URL Parameter"},
+ "/confirm?confirmation_token=123": {"code": 200, "data": b"Bad Token Provided"},
}
+
def test_visitors(app, client):
- for page in data2check_visitors:
- res = client.get(page)
- print("Testing %s",page)
- assert res.status_code == data2check_visitors[page]["code"]
- assert data2check_visitors[page]["data"] in res.data
+ for page in data2check_visitors:
+ res = client.get(page)
+ print("Testing %s", page)
+ assert res.status_code == data2check_visitors[page]["code"]
+ assert data2check_visitors[page]["data"] in res.data
+
def test_user_auth_flow(app, client):
- res = client.post("/signup",data=dict(
- email="test@example.com",
- first_name="John",
- password="testpassword",
- ), follow_redirects=True)
-
- assert res.status_code == 200
- assert b"confirm your email" in res.data
-
- res = client.post("/signin",data=dict(
- email="test@example.com",
- password="testpassword"),
- follow_redirects=True)
- assert res.status_code == 200
- assert b"Please Confirm Your Email First." in res.data
-
- confirmation_token = ts.dumps("test@example.com",salt="email-confirm-key")
- res = client.get("/confirm?confirmation_token={}".format(confirmation_token),
- follow_redirects=True)
- print(res.data)
- assert b"Succesfully Verified" in res.data
-
- res = client.post("/signin",data=dict(
- email="test@example.com",
- password="testpassword"),
- follow_redirects=True)
- assert res.status_code == 200
- assert b"Hi John" in res.data
-
- res = client.get("/logout", follow_redirects=True)
- assert res.status_code == 200
- assert b"You have been logged out." in res.data
-
- res = client.post("/signin",data=dict(
- email="test@example.com",
- password="testpassword"),
- follow_redirects=True)
- assert res.status_code == 200
- assert b"Hi John" in res.data
-
- res = client.get("/signin",follow_redirects=True)
- assert res.status_code == 200
- assert b"Hi John" in res.data
-
- res = client.get("/signup",follow_redirects=True)
- assert res.status_code == 200
- assert b"Hi John" in res.data
-
- res = client.get("/admin/user/")
- assert res.status_code == 403
-
- res = client.get("/logout")
- res = client.post("/signin",data=dict(
- email="testtest@example.com",
- password="123456"),follow_redirects=True)
- assert res.status_code == 200
- assert b"Incorrect Email" in res.data
- res = client.post("/signin",data=dict(
- email="test@example.com",
- password="incorrectpassword"),
- follow_redirects = True)
- assert res.status_code == 200
- assert b"Incorrect Password" in res.data
-
- res = client.post("/signup",data=dict(
- email="test@example.com",
- first_name="John",
- password="testpassword",
- ), follow_redirects=True)
- assert res.status_code == 200
- assert b"Oops! An account with that email already exists" in res.data \ No newline at end of file
+ res = client.post(
+ "/signup",
+ data=dict(
+ email="test@example.com",
+ first_name="John",
+ password="testpassword",
+ ),
+ follow_redirects=True,
+ )
+
+ assert res.status_code == 200
+ assert b"confirm your email" in res.data
+
+ res = client.post(
+ "/signin",
+ data=dict(email="test@example.com", password="testpassword"),
+ follow_redirects=True,
+ )
+ assert res.status_code == 200
+ assert b"Please Confirm Your Email First." in res.data
+
+ confirmation_token = ts.dumps("test@example.com", salt="email-confirm-key")
+ res = client.get(
+ "/confirm?confirmation_token={}".format(confirmation_token),
+ follow_redirects=True,
+ )
+ print(res.data)
+ assert b"Succesfully Verified" in res.data
+
+ res = client.post(
+ "/signin",
+ data=dict(email="test@example.com", password="testpassword"),
+ follow_redirects=True,
+ )
+ assert res.status_code == 200
+ assert b"Hi John" in res.data
+
+ res = client.get("/logout", follow_redirects=True)
+ assert res.status_code == 200
+ assert b"You have been logged out." in res.data
+
+ res = client.post(
+ "/signin",
+ data=dict(email="test@example.com", password="testpassword"),
+ follow_redirects=True,
+ )
+ assert res.status_code == 200
+ assert b"Hi John" in res.data
+
+ res = client.get("/signin", follow_redirects=True)
+ assert res.status_code == 200
+ assert b"Hi John" in res.data
+
+ res = client.get("/signup", follow_redirects=True)
+ assert res.status_code == 200
+ assert b"Hi John" in res.data
+
+ res = client.get("/admin/user/")
+ assert res.status_code == 403
+
+ res = client.get("/logout")
+ res = client.post(
+ "/signin",
+ data=dict(email="testtest@example.com", password="123456"),
+ follow_redirects=True,
+ )
+ assert res.status_code == 200
+ assert b"Incorrect Email" in res.data
+ res = client.post(
+ "/signin",
+ data=dict(email="test@example.com", password="incorrectpassword"),
+ follow_redirects=True,
+ )
+ assert res.status_code == 200
+ assert b"Incorrect Password" in res.data
+
+ res = client.post(
+ "/signup",
+ data=dict(
+ email="test@example.com",
+ first_name="John",
+ password="testpassword",
+ ),
+ follow_redirects=True,
+ )
+ assert res.status_code == 200
+ assert b"Oops! An account with that email already exists" in res.data