Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
T
tdt4242-base
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
Håvard Farestveit
tdt4242-base
Commits
9bd3c8db
Commit
9bd3c8db
authored
4 years ago
by
Håvard Farestveit
Browse files
Options
Downloads
Patches
Plain Diff
Created a test script to validate functionality of changes to Offer
parent
dcbea426
No related branches found
No related tags found
No related merge requests found
Pipeline
#125969
passed
4 years ago
Stage: test
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
backend/secfit/users/tests/__init__.py
+2
-1
2 additions, 1 deletion
backend/secfit/users/tests/__init__.py
backend/secfit/users/tests/offers.py
+92
-0
92 additions, 0 deletions
backend/secfit/users/tests/offers.py
with
94 additions
and
1 deletion
backend/secfit/users/tests/__init__.py
+
2
−
1
View file @
9bd3c8db
from
users.tests.UserRegistration
import
*
from
users.tests.UserRegistration
import
*
from
users.tests.UserSerializer
import
*
from
users.tests.UserSerializer
import
*
\ No newline at end of file
from
users.tests.offers
import
*
\ No newline at end of file
This diff is collapsed.
Click to expand it.
backend/secfit/users/tests/offers.py
0 → 100644
+
92
−
0
View file @
9bd3c8db
from
django.test
import
TestCase
from
django.contrib.auth
import
get_user_model
from
rest_framework.test
import
APIClient
from
users.models
import
Offer
class
OfferTestCase
(
TestCase
):
def
setUp
(
self
):
self
.
client
=
APIClient
()
self
.
user_model
=
get_user_model
()
self
.
password
=
"
password
"
self
.
user1
=
self
.
user_model
(
username
=
"
testOffer1
"
,
email
=
"
test@test.com
"
,
phone_number
=
"
12345678
"
,
country
=
"
Norway
"
,
city
=
"
Oslo
"
,
street_address
=
"
address 10
"
)
self
.
user1
.
set_password
(
self
.
password
)
self
.
user1
.
save
()
self
.
user2
=
self
.
user_model
(
username
=
"
testOffer2
"
,
email
=
"
test@test.com
"
,
phone_number
=
"
12345678
"
,
country
=
"
Norway
"
,
city
=
"
Oslo
"
,
street_address
=
"
address 10
"
)
self
.
user2
.
set_password
(
self
.
password
)
self
.
user2
.
save
()
def
_send_offer
(
self
,
user_id
,
status
):
request
=
{}
request
[
"
status
"
]
=
status
request
[
"
recipient
"
]
=
"
http://127.0.0.1:8000/api/users/{0}/
"
.
format
(
user_id
)
response
=
self
.
client
.
post
(
'
/api/offers/
'
,
request
)
return
response
.
status_code
def
_login
(
self
,
user
):
request
=
{}
request
[
"
username
"
]
=
user
.
username
request
[
"
password
"
]
=
self
.
password
response
=
self
.
client
.
post
(
'
/api/token/
'
,
request
)
access_token
=
response
.
data
[
'
access
'
]
self
.
client
.
credentials
(
HTTP_AUTHORIZATION
=
'
Bearer
'
+
access_token
)
def
test_create_offer
(
self
):
recipient
=
self
.
user2
.
id
self
.
_login
(
self
.
user1
)
status_code
=
self
.
_send_offer
(
recipient
,
Offer
.
PENDING
)
self
.
assertEqual
(
status_code
,
201
)
def
test_get_offers
(
self
):
self
.
_login
(
self
.
user1
)
self
.
_send_offer
(
self
.
user2
.
id
,
Offer
.
PENDING
)
self
.
_login
(
self
.
user2
)
response
=
self
.
client
.
get
(
'
/api/offers/
'
)
number_of_offers
=
response
.
data
[
"
count
"
]
self
.
assertEqual
(
1
,
number_of_offers
)
def
test_get_offer_detail
(
self
):
self
.
_login
(
self
.
user1
)
self
.
_send_offer
(
self
.
user2
.
id
,
Offer
.
PENDING
)
self
.
_login
(
self
.
user2
)
response
=
self
.
client
.
get
(
'
/api/offers/1/
'
)
self
.
assertEqual
(
200
,
response
.
status_code
)
def
test_decline_offer
(
self
):
self
.
_login
(
self
.
user1
)
self
.
_send_offer
(
self
.
user2
.
id
,
Offer
.
PENDING
)
self
.
_login
(
self
.
user2
)
response
=
self
.
client
.
patch
(
'
/api/offers/1/
'
,
{
"
status
"
:
Offer
.
DECLINED
})
self
.
assertEqual
(
200
,
response
.
status_code
)
def
test_accept_offer
(
self
):
self
.
_login
(
self
.
user1
)
self
.
_send_offer
(
self
.
user2
.
id
,
Offer
.
PENDING
)
self
.
_login
(
self
.
user2
)
offer_response
=
self
.
client
.
patch
(
'
/api/offers/1/
'
,
{
"
status
"
:
Offer
.
ACCEPTED
})
self
.
assertEqual
(
200
,
offer_response
.
status_code
)
coach_response
=
self
.
client
.
patch
(
'
/api/users/{0}/
'
.
format
(
self
.
user2
.
id
),
{
"
coach
"
:
"
http://127.0.0.1:8000/api/users/{0}/
"
.
format
(
self
.
user1
.
id
)}
)
self
.
assertEqual
(
200
,
coach_response
.
status_code
)
athlete
=
self
.
user_model
.
objects
.
get
(
username
=
self
.
user2
.
username
)
self
.
assertEqual
(
athlete
.
coach
.
id
,
self
.
user1
.
id
)
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