Skip to content
Snippets Groups Projects
Commit fd58ef8a authored by radek's avatar radek
Browse files

tests tests and readme

parent c83f8bd3
No related branches found
No related tags found
No related merge requests found
Pipeline #15185 failed
......@@ -12,6 +12,8 @@ Radek:
- wrote more tests
- played the “Privacy’s not dead!” game
- did OpenSSL Pratcice badge
- created new enpoints for users to use
- fixed issues and cleaned up a project a bit
Olli:
-
......
......@@ -3,6 +3,15 @@ from typing import Any
from flask import Flask
import pytest
from tjts5901 import create_app
from flask_restful import Resource, Api, reqparse, abort
from flask_jwt_extended import (
JWTManager, jwt_required, create_access_token,
get_jwt_identity)
import tjts5901.backend.item_api as items
import tjts5901.backend.admin_api as admin_api
import tjts5901.backend.login_api as log_in
import tjts5901.backend.bid_api as bid
@pytest.fixture
def app() -> Flask:
......@@ -34,6 +43,14 @@ def app() -> Flask:
# _app.config['WTF_CSRF_METHODS'] = []
# _app.config['WTF_CSRF_CHECK_DEFAULT'] = False
api = Api(flask_app)
#create JSON web token bearer
jwt = JWTManager(flask_app)
# added auction item resource
api.add_resource(items.AuctionItem, "/auction_item/", "/auction_item/<id>")
api.add_resource(admin_api.AdminAPI, "/users/", "/users/<email>")
api.add_resource(bid.Bid, "/bid")
flask_app.testing = True
yield flask_app
......
......@@ -2,24 +2,95 @@ import pytest
import json
import requests
from flask import Flask
from flask_restful import Api
from tjts5901.backend.models.users import User
from tjts5901.backend.admin_api import AdminAPI
from tjts5901.backend.item_api import AuctionItem
from flask_jwt_extended import (
JWTManager, jwt_required, create_access_token,)
"""
def test_login(client):
url = "http://localhost:5001/login?email=jozko@test.com&password="
resp = client.get(url)
assert resp.status_code == 200
def test_hello(client):
with client.application.app_context():
resp = client.get("/hello")
assert resp.status_code == 200
def test_get_all_items(client):
headers = {
"Authorization": "Bearer " + create_access_token({"username": "jozko@test.com"})
}
response = client.get("/auction_item/", headers=headers)
assert response.status_code == 200
assert isinstance(json.loads(response.data), list)
"""
\ No newline at end of file
"""Test getting all items
Args:
client (_type_): _description_
"""
with client.application.app_context():
#jwt = JWTManager(client.application)
access_token= create_access_token(identity="jozko@test.com")
bearer_str = r"Bearer " + access_token
#headers["Authorization"] = "Bearer "
headers = {
"Authorization": bearer_str
}
response = client.get("/auction_item/", headers=headers)
assert response.status_code == 200
assert isinstance(json.loads(response.data), str)
def test_get_my_auctions(client):
"""Test getting specific user with email: jozko@test.com
Args:
client (_type_): _description_
"""
with client.application.app_context():
#jwt = JWTManager(client.application)
access_token= create_access_token(identity="jozko@test.com")
bearer_str = r"Bearer " + access_token
#headers["Authorization"] = "Bearer "
headers = {
"Authorization": bearer_str
}
response = client.get("/auction_item/my", headers=headers)
assert response.status_code == 200
assert isinstance(json.loads(response.data), str)
def test_get_all_users(client):
"""Test getting all users
Args:
client (_type_): _description_
"""
with client.application.app_context():
#jwt = JWTManager(client.application)
access_token= create_access_token(identity="jozko@test.com")
bearer_str = r"Bearer " + access_token
#headers["Authorization"] = "Bearer "
headers = {
"Authorization": bearer_str
}
response = client.get("/users/", headers=headers)
assert response.status_code == 200
assert isinstance(json.loads(response.data), str)
def test_get_specific_user(client):
"""Test getting specific user with email: jozko@test.com
Args:
client (_type_): _description_
"""
with client.application.app_context():
#jwt = JWTManager(client.application)
access_token= create_access_token(identity="jozko@test.com")
bearer_str = r"Bearer " + access_token
#headers["Authorization"] = "Bearer "
headers = {
"Authorization": bearer_str
}
response = client.get("/users/jozko@test.com", headers=headers)
assert response.status_code == 200
assert isinstance(json.loads(response.data), str)
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment