Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
T
TDT4242-group15
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
Vegard Murvold Sporstøl
TDT4242-group15
Commits
2b38f73c
Commit
2b38f73c
authored
4 years ago
by
Vegard Murvold Sporstøl
Browse files
Options
Downloads
Patches
Plain Diff
working test on FR5
parent
88e5fa71
No related branches found
Branches containing commit
No related tags found
1 merge request
!7
Task3
Changes
2
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
backend/secfit/users/tests.py
+85
-18
85 additions, 18 deletions
backend/secfit/users/tests.py
backend/secfit/workouts/tests.py
+404
-41
404 additions, 41 deletions
backend/secfit/workouts/tests.py
with
489 additions
and
59 deletions
backend/secfit/users/tests.py
+
85
−
18
View file @
2b38f73c
from
rest_framework
import
status
from
rest_framework.test
import
APITestCase
import
json
# Tests new registration, boundary values and 2-way domain
class
RegistrationTestCase
(
APITestCase
):
def
test_boundaryValuesOfRegistrationInvalid
(
self
):
from
django.test
import
TestCase
,
RequestFactory
,
Client
from
users.serializers
import
UserSerializer
from
users.models
import
User
from
django.core.exceptions
import
ValidationError
class
RegistrationTestCase
(
TestCase
):
def
setUp
(
self
):
self
.
client
=
Client
()
def
test_registration
(
self
):
data
=
{
"
username
"
:
"
Test
"
,
"
email
"
:
"
test@test.no
"
,
"
password
"
:
"
strong_pwd
"
,
"
password1
"
:
"
strong_pwd
"
,
"
phone_number
"
:
"
12345678
"
,
"
country
"
:
"
Norway
"
,
"
city
"
:
"
Trondheim
"
,
"
street_address
"
:
"
Trondheimsvegen 1
"
}
response
=
self
.
client
.
post
(
'
/api/users/
'
,
data
)
self
.
assertEqual
(
response
.
status_code
,
201
)
### Test boundary values of registration ###
class
BoundaryValuesOfRegistrationTestCase
(
TestCase
):
def
setUp
(
self
):
self
.
client
=
Client
()
def
test_minimumData
(
self
):
data
=
{
"
username
"
:
"
t
"
,
"
email
"
:
""
,
"
password
"
:
"
1
"
,
"
password1
"
:
"
1
"
,
"
phone_number
"
:
""
,
"
country
"
:
""
,
"
city
"
:
""
,
"
street_address
"
:
""
}
response
=
self
.
client
.
post
(
"
/api/users/
"
,
data
)
self
.
assertEqual
(
response
.
status_code
,
201
)
#should work at one char pwd and username
def
test_blankPassword
(
self
):
data
=
{
"
username
"
:
"
test
"
,
"
email
"
:
""
,
"
password
"
:
""
,
"
password1
"
:
""
,
"
phone_number
"
:
""
,
"
country
"
:
""
,
"
city
"
:
""
,
"
street_address
"
:
""
}
response
=
self
.
client
.
post
(
"
/api/users/
"
,
data
)
self
.
assertEqual
(
response
.
status_code
,
status
.
HTTP_400_BAD_REQUEST
)
#should fail at blank pwd
self
.
assertEqual
(
response
.
status_code
,
400
)
#should fail at blank pwd
def
test_blankUsername
(
self
):
data
=
{
"
username
"
:
""
,
"
email
"
:
""
,
"
password
"
:
"
1
"
,
"
password1
"
:
"
1
"
,
"
phone_number
"
:
""
,
"
country
"
:
""
,
"
city
"
:
""
,
"
street_address
"
:
""
}
response
=
self
.
client
.
post
(
"
/api/users/
"
,
data
)
self
.
assertEqual
(
response
.
status_code
,
status
.
HTTP_400_BAD_REQUEST
)
#should fail at blank username
self
.
assertEqual
(
response
.
status_code
,
400
)
#should fail at blank username
# Seem to be no upper value and no restrictions to the other fields
def
test_boundaryValuesOfRegistrationValid
(
self
):
data
=
{
"
username
"
:
"
t
"
,
"
email
"
:
""
,
def
test_invalidEmail
(
self
):
data
=
{
"
username
"
:
"
Test
"
,
"
email
"
:
"
test.no
"
,
"
password
"
:
"
1
"
,
"
password1
"
:
"
1
"
,
"
phone_number
"
:
""
,
"
country
"
:
""
,
"
city
"
:
""
,
"
street_address
"
:
""
}
response
=
self
.
client
.
post
(
"
/api/users/
"
,
data
)
self
.
assertEqual
(
response
.
status_code
,
status
.
HTTP_201_CREATED
)
#should work at one char pwd and username
self
.
assertEqual
(
response
.
status_code
,
400
)
#should fail if email does not conatin @
### 2-way domain testing of registration ###
class
TwoWayDomainTestOfRegistrationTestCase
(
TestCase
):
def
setUp
(
self
):
self
.
client
=
Client
()
def
test_domainRegistration
(
self
):
"
2-way domain tests to test the register page
"
# Tests new functionality in UC-2
class
Statistics
(
APITestCase
):
def
test_renderStatistics
(
self
):
"
test that the statistics are rendered
"
def
test_correctStatistics
(
self
):
"
Check that statistics are correctly calculated
"
### Test the class UserSerializer ###
class
UserSerializerTestCase
(
TestCase
):
def
setUp
(
self
):
self
.
user1
=
User
.
objects
.
create
(
username
=
"
user1
"
)
self
.
user2
=
User
.
objects
.
create
(
username
=
"
user2
"
,
coach
=
self
.
user1
)
self
.
factory
=
RequestFactory
()
def
test_validate_passwordValid
(
self
):
password
=
"
some_very_strong_pwd
"
serializer
=
UserSerializer
(
data
=
{
'
password
'
:
password
,
'
password1
'
:
password
})
validated_password
=
serializer
.
validate_password
(
password
)
self
.
assertEqual
(
validated_password
,
password
)
def
test_validate_passwordInValid
(
self
):
password
=
"
some_very_strong_pwd
"
password1
=
"
Some_wrong_pwd
"
serializer
=
UserSerializer
(
data
=
{
'
password
'
:
password
,
'
password1
'
:
password
})
validated_password
=
serializer
.
validate_password
(
password1
)
self
.
assertRaises
(
ValidationError
)
def
test_create
(
self
):
data
=
{
"
username
"
:
"
Test
"
,
"
email
"
:
"
test@test.no
"
,
"
password
"
:
"
strong_pwd
"
,
"
password1
"
:
"
strong_pwd
"
,
"
phone_number
"
:
"
12345678
"
,
"
country
"
:
"
Norway
"
,
"
city
"
:
"
Trondheim
"
,
"
street_address
"
:
"
Trondheimsvegen 1
"
}
serializer
=
UserSerializer
(
data
)
user
=
serializer
.
create
(
data
)
self
.
assertEqual
(
user
.
username
,
"
Test
"
)
self
.
assertEqual
(
user
.
email
,
"
test@test.no
"
)
self
.
assertEqual
(
user
.
phone_number
,
"
12345678
"
)
self
.
assertEqual
(
user
.
country
,
"
Norway
"
)
self
.
assertEqual
(
user
.
city
,
"
Trondheim
"
)
self
.
assertEqual
(
user
.
street_address
,
"
Trondheimsvegen 1
"
)
This diff is collapsed.
Click to expand it.
backend/secfit/workouts/tests.py
+
404
−
41
View file @
2b38f73c
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