Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
T
tdt4242-base-APU
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
Tor Martin Frøberg Wang
tdt4242-base-APU
Commits
9adefd69
Commit
9adefd69
authored
4 years ago
by
Tobias Ørstad
Browse files
Options
Downloads
Patches
Plain Diff
Finish 2-way boundary testing
parent
22818d78
No related branches found
Branches containing commit
No related tags found
2 merge requests
!20
Dev
,
!19
Finish Domaintesting
Pipeline
#114253
passed
4 years ago
Stage: test
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
backend/secfit/users/tests.py
+200
-36
200 additions, 36 deletions
backend/secfit/users/tests.py
with
200 additions
and
36 deletions
backend/secfit/users/tests.py
+
200
−
36
View file @
9adefd69
...
...
@@ -331,33 +331,41 @@ class UserSerializerTestCase(TestCase):
class
Register2WayDomainTestCase
(
TestCase
):
#Start by defining datatypes for each value of the inputs we want to test
#All arrays consists of data on the format [value to be tested, should this input be valid]
#If the value to be tested is itself an array it means that input should be tested twice, and the status be collected from the second post
#The exception is the password array, which uses both entries of the array as input to password and password1 in one post
def
setUp
(
self
):
self
.
request
=
json
.
loads
(
'
{
"
username
"
:
"
bob
"
,
"
password
"
:
"
Heihei1
"
,
"
password1
"
:
"
Heihei1
"
,
"
athletes
"
: [],
"
email
"
:
"
bob@bob.no
"
,
"
coach_files
"
: [],
"
athlete_files
"
: [],
"
workouts
"
:[],
"
phone_number
"
:
"
12345678
"
,
"
country
"
:
""
,
"
city
"
:
""
,
"
street_address
"
:
""
}
'
)
self
.
request1
=
json
.
loads
(
'
{
"
username
"
:
"
bob
1
"
,
"
password
"
:
"
Heihei1
"
,
"
password1
"
:
"
Heihei1
"
,
"
athletes
"
: [],
"
email
"
:
"
bob1@bob.no
"
,
"
coach_files
"
: [],
"
athlete_files
"
: [],
"
workouts
"
:[],
"
phone_number
"
:
"
12345679
"
,
"
country
"
:
""
,
"
city
"
:
""
,
"
street_address
"
:
""
}
'
)
self
.
request
=
json
.
loads
(
'
{
"
username
"
:
"
bob
1
"
,
"
password
"
:
"
Heihei1
"
,
"
password1
"
:
"
Heihei1
"
,
"
athletes
"
: [],
"
email
"
:
"
bob@bob.no
"
,
"
coach_files
"
: [],
"
athlete_files
"
: [],
"
workouts
"
:[],
"
phone_number
"
:
"
12345678
"
,
"
country
"
:
""
,
"
city
"
:
""
,
"
street_address
"
:
""
}
'
)
self
.
request1
=
json
.
loads
(
'
{
"
username
"
:
"
bob
2
"
,
"
password
"
:
"
Heihei1
"
,
"
password1
"
:
"
Heihei1
"
,
"
athletes
"
: [],
"
email
"
:
"
bob1@bob.no
"
,
"
coach_files
"
: [],
"
athlete_files
"
: [],
"
workouts
"
:[],
"
phone_number
"
:
"
12345679
"
,
"
country
"
:
""
,
"
city
"
:
""
,
"
street_address
"
:
""
}
'
)
self
.
client
=
APIClient
()
User
.
objects
.
create
(
id
=
"
1
"
,
username
=
"
Bill
"
,
password
=
"
secret
"
)
self
.
user_1
=
User
.
objects
.
get
(
id
=
"
1
"
)
self
.
client
.
force_authenticate
(
user
=
self
.
user_1
)
self
.
usernames
=
[[
"
bob
"
,
True
],[
"
<<<
"
,
False
],[[
"
bob
"
,
"
bob
"
],
False
]]
self
.
emails
=
[[
"
bob@bob.no
"
,
True
],
[
"
bob
"
,
False
],
[[
"
bob2@bob.no
"
,
"
bob2@bob.no
"
],
False
]]
self
.
password
=
[[[
"
Bobobo12
"
,
"
Bobobo12
"
],
True
],
[[
"
bob
"
,
"
bob
"
],
False
],
[[
"
Bobobo12
"
,
"
Bobobo11
"
],
False
]]
self
.
number
=
[[
"
123
"
,
False
],[
"
123456789
"
,
True
],[[
"
123456789
"
,
"
123456789
"
],
False
]]
self
.
country
=
[[
"
Norway
"
,
True
],[
"
Norway10
"
,
False
]]
self
.
city
=
[[
"
Hei
"
,
True
]]
self
.
street_address
=
[[
"
hei
"
,
True
]]
self
.
usernames
=
[[
"
bob
"
,
True
],[
"
<<<
"
,
False
],[[
"
bob
"
,
"
bob
"
],
False
],
[
""
,
False
]]
self
.
emails
=
[[
"
bob@bob.no
"
,
True
],
[
"
bob
"
,
False
],
[[
"
bob2@bob.no
"
,
"
bob2@bob.no
"
],
False
],
[
""
,
False
]]
self
.
password
=
[[[
"
Bobobo12
"
,
"
Bobobo12
"
],
True
],
[[
"
bob
"
,
"
bob
"
],
False
],
[[
"
Bobobo12
"
,
"
Bobobo11
"
],
False
],[[
""
,
""
],
False
]]
self
.
number
=
[[
"
123
"
,
False
],[
"
12345678
"
,
True
],[[
"
12345678
"
,
"
12345678
"
],
False
]]
self
.
country
=
[[
"
Norway
"
,
True
],[
"
Norway10
"
,
False
],[
""
,
True
]]
self
.
city
=
[[
"
Hei
"
,
True
],[
""
,
True
]]
self
.
street_address
=
[[
"
hei
"
,
True
],[
""
,
True
]]
#Method for cleaning up users by deleting
def
delete_user
(
self
,
id
):
user
=
User
.
objects
.
get
(
id
=
id
)
self
.
client
.
force_authenticate
(
user
=
user
)
response
=
self
.
client
.
delete
(
'
http://testserver/api/users/
'
+
str
(
id
)
+
'
/
'
)
print
(
response
.
status_code
)
def
postUser
(
self
,
field
,
value
,
number
,
field1
=
None
,
value1
=
None
,):
try
:
user
=
User
.
objects
.
get
(
id
=
id
)
self
.
client
.
force_authenticate
(
user
=
user
)
response
=
self
.
client
.
delete
(
'
http://testserver/api/users/
'
+
str
(
id
)
+
'
/
'
)
except
:
pass
#Method for posting users, takes up to 2 fields and values. optional parameter for deleting the user
def
postUser
(
self
,
field
,
value
,
number
,
field1
=
None
,
value1
=
None
,
delete
=
True
):
request
=
[
self
.
request
.
copy
(),
self
.
request1
.
copy
()][
number
]
if
(
field
==
'
password
'
):
request
[
'
password
'
]
=
value
1
[
0
]
request
[
'
password1
'
]
=
value
1
[
1
]
request
[
'
password
'
]
=
value
[
0
]
request
[
'
password1
'
]
=
value
[
1
]
else
:
request
[
field
]
=
value
if
(
field1
!=
None
):
...
...
@@ -367,34 +375,48 @@ class Register2WayDomainTestCase(TestCase):
else
:
request
[
field1
]
=
value1
request
=
self
.
client
.
post
(
'
http://testserver/api/users/
'
,
json
.
dumps
(
request
),
content_type
=
'
application/json
'
)
if
request
.
status_code
==
201
:
if
request
.
status_code
==
201
and
delete
:
self
.
delete_user
(
request
.
data
[
'
id
'
])
return
request
.
status_code
return
request
.
status_code
,
request
.
data
#Method for making sure the correct amount of posts is sent based on the values
#Checks if values are strings or arrays and calls post accordingly
def
get_status_for_posts
(
self
,
field1
,
value1
,
field2
,
value2
):
status_code
=
""
code
=
0
postdata
=
""
if
(
isinstance
(
value1
,
list
)
and
isinstance
(
value2
,
list
)):
self
.
postUser
(
field1
,
value1
[
0
],
0
,
field2
,
value2
[
0
])
return
self
.
postUser
(
field1
,
value1
[
1
],
1
,
field2
,
value2
[
1
])
code
,
postdata
=
self
.
postUser
(
field1
,
value1
[
0
],
0
,
field2
,
value2
[
0
]
,
delete
=
False
)
status_code
,
data
=
self
.
postUser
(
field1
,
value1
[
1
],
1
,
field2
,
value2
[
1
])
elif
(
isinstance
(
value1
,
list
)
and
isinstance
(
value2
,
str
)):
self
.
postUser
(
field1
,
value1
[
0
],
0
)
return
self
.
postUser
(
field1
,
value1
[
1
],
1
,
field2
,
value2
)
code
,
postdata
=
self
.
postUser
(
field1
,
value1
[
0
],
0
,
delete
=
False
)
status_code
,
data
=
self
.
postUser
(
field1
,
value1
[
1
],
1
,
field2
,
value2
)
elif
(
isinstance
(
value1
,
str
)
and
isinstance
(
value2
,
list
)):
self
.
postUser
(
field2
,
value2
[
0
],
0
)
return
self
.
postUser
(
field1
,
value1
,
1
,
field2
,
value2
[
1
])
code
,
postdata
=
self
.
postUser
(
field2
,
value2
[
0
],
0
,
delete
=
False
)
status_code
,
data
=
self
.
postUser
(
field1
,
value1
,
1
,
field2
,
value2
[
1
])
else
:
return
self
.
postUser
(
field1
,
value1
,
0
,
field2
,
value2
)
status_code
,
data
=
self
.
postUser
(
field1
,
value1
,
0
,
field2
,
value2
)
if
code
==
201
:
self
.
delete_user
(
postdata
[
'
id
'
])
return
status_code
#Special version of method above for passwords, as they work differently, mentioned in setup.
def
get_status_for_posts_password
(
self
,
passwordlist
,
field1
,
value1
):
status_code
=
""
code
=
0
postdata
=
""
if
(
isinstance
(
value1
,
list
)):
self
.
postUser
(
field1
,
value1
[
0
],
0
)
return
self
.
postUser
(
'
password
'
,
passwordlist
,
1
,
field1
,
value1
[
1
])
code
,
postdata
=
self
.
postUser
(
field1
,
value1
[
0
],
0
,
delete
=
False
)
status_code
,
data
=
self
.
postUser
(
'
password
'
,
passwordlist
,
1
,
field1
,
value1
[
1
])
else
:
return
self
.
postUser
(
'
password
'
,
passwordlist
,
0
,
field1
,
value1
)
def
getUniqueNumber
(
self
):
return
datetime
.
utcnow
().
strftime
(
"
%m-%d-%Y-%H-%M-%S.%f
"
)[
-
11
:].
replace
(
'
.
'
,
''
).
replace
(
'
-
'
,
''
)
status_code
,
data
=
self
.
postUser
(
'
password
'
,
passwordlist
,
0
,
field1
,
value1
)
if
code
==
201
:
self
.
delete_user
(
postdata
[
'
id
'
])
return
status_code
#testing all usernames, a lot of this should be extracted to its own function, but because of time constrains code had to copied
#We have to catch the asserts because if not the method would not run to completion. Instead we collect all assertionErrors in a
#list which we print at the end. All methods below follow same format.
def
test_usernames
(
self
):
failures
=
[]
field1
=
'
username
'
...
...
@@ -408,6 +430,8 @@ class Register2WayDomainTestCase(TestCase):
try
:
self
.
assertEquals
((
status
==
201
),
expectedstatus
)
except
AssertionError
:
failures
.
append
({
field1
:
value1
,
field2
:
value2
})
for
password
in
self
.
password
:
field2
=
'
password
'
value2
=
password
[
0
]
expectedstatus
=
username
[
1
]
and
password
[
1
]
status
=
self
.
get_status_for_posts_password
(
password
[
0
],
field1
,
username
[
0
])
try
:
self
.
assertEquals
((
status
==
201
),
expectedstatus
)
...
...
@@ -441,3 +465,143 @@ class Register2WayDomainTestCase(TestCase):
try
:
self
.
assertEquals
((
status
==
201
),
expectedstatus
)
except
AssertionError
:
failures
.
append
({
field1
:
value1
,
field2
:
value2
})
print
(
failures
)
def
test_emails
(
self
):
failures
=
[]
field1
=
'
email
'
for
email
in
self
.
emails
:
value1
=
email
[
0
]
for
password
in
self
.
password
:
field2
=
'
password
'
value2
=
password
[
0
]
expectedstatus
=
email
[
1
]
and
password
[
1
]
status
=
self
.
get_status_for_posts_password
(
password
[
0
],
field1
,
email
[
0
])
try
:
self
.
assertEquals
((
status
==
201
),
expectedstatus
)
except
AssertionError
:
failures
.
append
({
field1
:
value1
,
field2
:
value2
})
for
number
in
self
.
number
:
field2
=
'
phone_number
'
value2
=
number
[
0
]
expectedstatus
=
email
[
1
]
and
number
[
1
]
status
=
self
.
get_status_for_posts
(
field1
,
value1
,
field2
,
value2
)
try
:
self
.
assertEquals
((
status
==
201
),
expectedstatus
)
except
AssertionError
:
failures
.
append
({
field1
:
value1
,
field2
:
value2
})
for
country
in
self
.
country
:
field2
=
'
country
'
value2
=
country
[
0
]
expectedstatus
=
email
[
1
]
and
country
[
1
]
status
=
self
.
get_status_for_posts
(
field1
,
value1
,
field2
,
value2
)
try
:
self
.
assertEquals
((
status
==
201
),
expectedstatus
)
except
AssertionError
:
failures
.
append
({
field1
:
value1
,
field2
:
value2
})
for
city
in
self
.
city
:
field2
=
'
city
'
value2
=
city
[
0
]
expectedstatus
=
email
[
1
]
and
city
[
1
]
status
=
self
.
get_status_for_posts
(
field1
,
value1
,
field2
,
value2
)
try
:
self
.
assertEquals
((
status
==
201
),
expectedstatus
)
except
AssertionError
:
failures
.
append
({
field1
:
value1
,
field2
:
value2
})
for
street_address
in
self
.
street_address
:
field2
=
'
street_address
'
value2
=
street_address
[
0
]
expectedstatus
=
email
[
1
]
and
street_address
[
1
]
status
=
self
.
get_status_for_posts
(
field1
,
value1
,
field2
,
value2
)
try
:
self
.
assertEquals
((
status
==
201
),
expectedstatus
)
except
AssertionError
:
failures
.
append
({
field1
:
value1
,
field2
:
value2
})
print
(
failures
)
def
test_passwords
(
self
):
failures
=
[]
field1
=
'
password
'
for
password
in
self
.
password
:
value1
=
password
[
0
]
for
number
in
self
.
number
:
field2
=
'
phone_number
'
value2
=
number
[
0
]
expectedstatus
=
password
[
1
]
and
number
[
1
]
status
=
self
.
get_status_for_posts_password
(
value1
,
field2
,
value2
)
try
:
self
.
assertEquals
((
status
==
201
),
expectedstatus
)
except
AssertionError
:
failures
.
append
({
field1
:
value1
,
field2
:
value2
})
for
country
in
self
.
country
:
field2
=
'
country
'
value2
=
country
[
0
]
expectedstatus
=
password
[
1
]
and
country
[
1
]
status
=
self
.
get_status_for_posts_password
(
value1
,
field2
,
value2
)
try
:
self
.
assertEquals
((
status
==
201
),
expectedstatus
)
except
AssertionError
:
failures
.
append
({
field1
:
value1
,
field2
:
value2
})
for
city
in
self
.
city
:
field2
=
'
city
'
value2
=
city
[
0
]
expectedstatus
=
password
[
1
]
and
city
[
1
]
status
=
self
.
get_status_for_posts_password
(
value1
,
field2
,
value2
)
try
:
self
.
assertEquals
((
status
==
201
),
expectedstatus
)
except
AssertionError
:
failures
.
append
({
field1
:
value1
,
field2
:
value2
})
for
street_address
in
self
.
street_address
:
field2
=
'
street_address
'
value2
=
street_address
[
0
]
expectedstatus
=
password
[
1
]
and
street_address
[
1
]
status
=
self
.
get_status_for_posts_password
(
value1
,
field2
,
value2
)
try
:
self
.
assertEquals
((
status
==
201
),
expectedstatus
)
except
AssertionError
:
failures
.
append
({
field1
:
value1
,
field2
:
value2
})
print
(
failures
)
def
test_numbers
(
self
):
failures
=
[]
field1
=
'
phone_number
'
for
number
in
self
.
number
:
value1
=
number
[
0
]
for
country
in
self
.
country
:
field2
=
'
country
'
value2
=
country
[
0
]
expectedstatus
=
number
[
1
]
and
country
[
1
]
status
=
self
.
get_status_for_posts
(
field1
,
value1
,
field2
,
value2
)
try
:
self
.
assertEquals
((
status
==
201
),
expectedstatus
)
except
AssertionError
:
failures
.
append
({
field1
:
value1
,
field2
:
value2
})
for
city
in
self
.
city
:
field2
=
'
city
'
value2
=
city
[
0
]
expectedstatus
=
number
[
1
]
and
city
[
1
]
status
=
self
.
get_status_for_posts
(
field1
,
value1
,
field2
,
value2
)
try
:
self
.
assertEquals
((
status
==
201
),
expectedstatus
)
except
AssertionError
:
failures
.
append
({
field1
:
value1
,
field2
:
value2
})
for
street_address
in
self
.
street_address
:
field2
=
'
street_address
'
value2
=
street_address
[
0
]
expectedstatus
=
number
[
1
]
and
street_address
[
1
]
status
=
self
.
get_status_for_posts
(
field1
,
value1
,
field2
,
value2
)
try
:
self
.
assertEquals
((
status
==
201
),
expectedstatus
)
except
AssertionError
:
failures
.
append
({
field1
:
value1
,
field2
:
value2
})
print
(
failures
)
def
test_countries
(
self
):
failures
=
[]
field1
=
'
country
'
for
country
in
self
.
country
:
value1
=
country
[
0
]
for
city
in
self
.
city
:
field2
=
'
city
'
value2
=
city
[
0
]
expectedstatus
=
country
[
1
]
and
city
[
1
]
status
=
self
.
get_status_for_posts
(
field1
,
value1
,
field2
,
value2
)
try
:
self
.
assertEquals
((
status
==
201
),
expectedstatus
)
except
AssertionError
:
failures
.
append
({
field1
:
value1
,
field2
:
value2
})
for
street_address
in
self
.
street_address
:
field2
=
'
street_address
'
value2
=
street_address
[
0
]
expectedstatus
=
country
[
1
]
and
street_address
[
1
]
status
=
self
.
get_status_for_posts
(
field1
,
value1
,
field2
,
value2
)
try
:
self
.
assertEquals
((
status
==
201
),
expectedstatus
)
except
AssertionError
:
failures
.
append
({
field1
:
value1
,
field2
:
value2
})
print
(
failures
)
def
test_city
(
self
):
failures
=
[]
field1
=
'
city
'
for
city
in
self
.
city
:
value1
=
city
[
0
]
for
street_address
in
self
.
street_address
:
field2
=
'
street_address
'
value2
=
street_address
[
0
]
expectedstatus
=
city
[
1
]
and
street_address
[
1
]
status
=
self
.
get_status_for_posts
(
field1
,
value1
,
field2
,
value2
)
try
:
self
.
assertEquals
((
status
==
201
),
expectedstatus
)
except
AssertionError
:
failures
.
append
({
field1
:
value1
,
field2
:
value2
})
print
(
failures
)
\ 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