Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
13th
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
13th
13th
Commits
fd58ef8a
Commit
fd58ef8a
authored
2 years ago
by
radek
Browse files
Options
Downloads
Patches
Plain Diff
tests tests and readme
parent
c83f8bd3
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Pipeline
#15185
failed
2 years ago
Stage: build
Stage: test
Changes
3
Pipelines
2
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
docs/week4.md
+2
-0
2 additions, 0 deletions
docs/week4.md
tests/conftest.py
+17
-0
17 additions, 0 deletions
tests/conftest.py
tests/functional/api_test.py
+87
-16
87 additions, 16 deletions
tests/functional/api_test.py
with
106 additions
and
16 deletions
docs/week4.md
+
2
−
0
View file @
fd58ef8a
...
...
@@ -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:
-
...
...
This diff is collapsed.
Click to expand it.
tests/conftest.py
+
17
−
0
View file @
fd58ef8a
...
...
@@ -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
...
...
This diff is collapsed.
Click to expand it.
tests/functional/api_test.py
+
87
−
16
View file @
fd58ef8a
...
...
@@ -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
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment