Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
E
ECE651_Backend
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container 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
Chris Li
ECE651_Backend
Commits
60f0b589
Commit
60f0b589
authored
2 years ago
by
Yirou Qiu
Browse files
Options
Downloads
Patches
Plain Diff
add bill tests
parent
1beacdf1
No related branches found
No related tags found
1 merge request
!6
add bill tests
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
core/tests/test_bill.py
+103
-0
103 additions, 0 deletions
core/tests/test_bill.py
core/urls.py
+6
-0
6 additions, 0 deletions
core/urls.py
ece651_backend/settings.py
+1
-0
1 addition, 0 deletions
ece651_backend/settings.py
with
110 additions
and
0 deletions
core/tests/test_bill.py
0 → 100644
+
103
−
0
View file @
60f0b589
import
requests
import
unittest
# """ login user """
user
=
{
"
username
"
:
"
superuser
"
,
"
email
"
:
""
,
"
password
"
:
"
1
"
}
auth_endpoint
=
"
http://localhost:8001/api/auth/
"
auth_response
=
requests
.
post
(
auth_endpoint
,
json
=
user
)
if
auth_response
.
status_code
==
200
:
token
=
auth_response
.
json
()[
"
token
"
]
headers
=
{
'
Authorization
'
:
f
"
Token
{
token
}
"
}
endpoint
=
"
http://localhost:8001/api/bill/
"
data_1
=
{
"
title
"
:
"
water
"
,
"
price
"
:
"
0.85
"
,
"
comment
"
:
"
discount
"
,
"
categories
"
:
8
}
data_2
=
{
"
title
"
:
"
mattress
"
,
"
price
"
:
"
99.65
"
,
"
comment
"
:
"
None
"
,
"
categories
"
:
2
}
class
BillTests
(
unittest
.
TestCase
):
def
test_create
(
self
):
get_response_create_1
=
requests
.
post
(
endpoint
,
json
=
data_1
,
headers
=
headers
)
get_response_create_2
=
requests
.
post
(
endpoint
,
json
=
data_2
,
headers
=
headers
)
self
.
assertEqual
(
get_response_create_1
.
status_code
,
201
)
self
.
assertEqual
(
get_response_create_2
.
status_code
,
201
)
def
test_get
(
self
):
get_response_list_1
=
requests
.
get
(
endpoint
,
headers
=
headers
)
self
.
assertEqual
(
get_response_list_1
.
status_code
,
200
)
# print(get_response_list_1.json())
def
test_detailed_get
(
self
):
endpoint
=
"
http://localhost:8001/api/bill/d5b1886c-abff-44e3-b0a8-b26981d5cfe9/
"
get_response
=
requests
.
get
(
endpoint
,
headers
=
headers
)
print
(
get_response
.
json
())
self
.
assertEqual
(
get_response
.
status_code
,
200
)
self
.
assertEqual
(
get_response
.
json
()[
"
title
"
],
data_1
[
"
title
"
])
self
.
assertEqual
(
get_response
.
json
()[
"
price
"
],
data_1
[
"
price
"
])
self
.
assertEqual
(
get_response
.
json
()[
"
categories
"
],
data_1
[
"
categories
"
])
self
.
assertEqual
(
get_response
.
json
()[
"
comment
"
],
data_1
[
"
comment
"
])
def
test_detailed_update
(
self
):
endpoint
=
"
http://localhost:8001/api/bill/8bbf80af-12a0-4603-8270-79ad9feffda5/
"
data_updated
=
{
"
title
"
:
"
buttersquash
"
,
"
price
"
:
"
0.01
"
,
"
comment
"
:
"
juicy
"
,
"
categories
"
:
4
}
get_response
=
requests
.
put
(
endpoint
,
data
=
data_updated
,
headers
=
headers
)
# print(get_response.json())
self
.
assertEqual
(
get_response
.
status_code
,
200
)
self
.
assertEqual
(
get_response
.
json
()[
"
title
"
],
data_updated
[
"
title
"
])
self
.
assertEqual
(
get_response
.
json
()[
"
price
"
],
data_updated
[
"
price
"
])
self
.
assertEqual
(
get_response
.
json
()[
"
categories
"
],
data_updated
[
"
categories
"
])
self
.
assertEqual
(
get_response
.
json
()[
"
comment
"
],
data_updated
[
"
comment
"
])
## partial update
data_updated_2
=
{
"
title
"
:
"
buttersquash
"
,
"
price
"
:
"
56.60
"
,
"
comment
"
:
"
juicy
"
,
"
categories
"
:
4
}
get_response
=
requests
.
put
(
endpoint
,
data
=
data_updated_2
,
headers
=
headers
)
self
.
assertEqual
(
get_response
.
status_code
,
200
)
self
.
assertEqual
(
get_response
.
json
()[
"
title
"
],
data_updated_2
[
"
title
"
])
self
.
assertEqual
(
get_response
.
json
()[
"
price
"
],
data_updated_2
[
"
price
"
])
self
.
assertEqual
(
get_response
.
json
()[
"
categories
"
],
data_updated_2
[
"
categories
"
])
self
.
assertEqual
(
get_response
.
json
()[
"
comment
"
],
data_updated_2
[
"
comment
"
])
# def test_delete(self):
# endpoint = "http://localhost:8001/api/bill/cb0e20c4-5344-4130-8a29-cbd50656fb48/"
# get_response = requests.delete(endpoint, headers=headers)
# print(get_response.json())
# self.assertEqual(get_response.status_code, 204)
# get_response = requests.get(endpoint, headers=headers)
# # data not exist
# self.assertEqual(get_response.status_code, 404)
if
__name__
==
'
__main__
'
:
unittest
.
main
()
This diff is collapsed.
Click to expand it.
core/urls.py
+
6
−
0
View file @
60f0b589
...
@@ -34,3 +34,9 @@ urlpatterns += [
...
@@ -34,3 +34,9 @@ urlpatterns += [
path
(
'
api/bill/
'
,
bill_list_create_api
,
name
=
"
bill-list
"
),
path
(
'
api/bill/
'
,
bill_list_create_api
,
name
=
"
bill-list
"
),
path
(
'
api/bill/<uuid:pk>/
'
,
bill_detail_api
,
name
=
"
bill-detail
"
)
path
(
'
api/bill/<uuid:pk>/
'
,
bill_detail_api
,
name
=
"
bill-detail
"
)
]
]
from
rest_framework.authtoken.views
import
obtain_auth_token
urlpatterns
+=
[
path
(
'
api/auth/
'
,
obtain_auth_token
)
]
This diff is collapsed.
Click to expand it.
ece651_backend/settings.py
+
1
−
0
View file @
60f0b589
...
@@ -40,6 +40,7 @@ INSTALLED_APPS = [
...
@@ -40,6 +40,7 @@ INSTALLED_APPS = [
'
django.contrib.staticfiles
'
,
'
django.contrib.staticfiles
'
,
'
django_extensions
'
,
'
django_extensions
'
,
'
rest_framework
'
,
'
rest_framework
'
,
'
rest_framework.authtoken
'
,
'
django_rest_passwordreset
'
,
'
django_rest_passwordreset
'
,
'
knox
'
,
'
knox
'
,
'
core
'
,
'
core
'
,
...
...
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