Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
Jelle van der Waa
Archweb
Commits
bf3e96dc
Unverified
Commit
bf3e96dc
authored
Jun 17, 2018
by
Jelle van der Waa
🚧
Committed by
GitHub
Jun 17, 2018
Browse files
Merge pull request #123 from jelly/refactor_tests_json
test: use response.json()
parents
35512840
ed1f4ce0
Changes
5
Hide whitespace changes
Inline
Side-by-side
mirrors/tests/test_mirrorlocations.py
View file @
bf3e96dc
import
json
from
django.test
import
TestCase
from
mirrors.models
import
CheckLocation
...
...
@@ -14,7 +12,7 @@ def setUp(self):
def
test_mirrorlocations_json
(
self
):
response
=
self
.
client
.
get
(
'/mirrors/locations/json/'
)
self
.
assertEqual
(
response
.
status_code
,
200
)
data
=
json
.
loads
(
response
.
content
)
data
=
response
.
json
(
)
self
.
assertEqual
(
1
,
data
[
'version'
])
location
=
data
[
'locations'
][
0
][
'country_code'
]
self
.
assertEqual
(
'US'
,
location
)
mirrors/tests/test_mirrors.py
View file @
bf3e96dc
import
json
from
django.test
import
TestCase
from
mirrors.tests
import
create_mirror_url
...
...
@@ -28,7 +26,7 @@ def test_details_json(self):
response
=
self
.
client
.
get
(
url
+
'json/'
)
self
.
assertEqual
(
response
.
status_code
,
200
)
data
=
json
.
loads
(
response
.
content
)
data
=
response
.
json
(
)
self
.
assertNotEqual
(
data
[
'urls'
],
[])
def
test_url_details
(
self
):
...
...
mirrors/tests/test_mirrorstatus.py
View file @
bf3e96dc
import
json
from
django.test
import
TestCase
from
mirrors.tests
import
create_mirror_url
...
...
@@ -13,7 +11,7 @@ def test_status(self):
def
test_json_endpoint
(
self
):
response
=
self
.
client
.
get
(
'/mirrors/status/json/'
)
self
.
assertEqual
(
response
.
status_code
,
200
)
data
=
json
.
loads
(
response
.
content
)
data
=
response
.
json
(
)
self
.
assertEqual
(
data
[
'urls'
],
[])
mirror_url
=
create_mirror_url
()
...
...
@@ -21,13 +19,13 @@ def test_json_endpoint(self):
# Verify that the cache works
response
=
self
.
client
.
get
(
'/mirrors/status/json/'
)
self
.
assertEqual
(
response
.
status_code
,
200
)
data
=
json
.
loads
(
response
.
content
)
data
=
response
.
json
(
)
# Disables the cache_function's cache
with
self
.
settings
(
CACHES
=
{
'default'
:
{
'BACKEND'
:
'django.core.cache.backends.dummy.DummyCache'
}}):
response
=
self
.
client
.
get
(
'/mirrors/status/json/'
)
self
.
assertEqual
(
response
.
status_code
,
200
)
data
=
json
.
loads
(
response
.
content
)
data
=
response
.
json
(
)
self
.
assertEqual
(
len
(
data
[
'urls'
]),
1
)
mirror
=
data
[
'urls'
][
0
]
...
...
@@ -41,7 +39,7 @@ def test_json_tier(self):
response
=
self
.
client
.
get
(
'/mirrors/status/tier/1/json/'
)
self
.
assertEqual
(
response
.
status_code
,
200
)
data
=
json
.
loads
(
response
.
content
)
data
=
response
.
json
(
)
self
.
assertEqual
(
data
[
'urls'
],
[])
mirror_url
=
create_mirror_url
()
...
...
@@ -50,7 +48,7 @@ def test_json_tier(self):
with
self
.
settings
(
CACHES
=
{
'default'
:
{
'BACKEND'
:
'django.core.cache.backends.dummy.DummyCache'
}}):
response
=
self
.
client
.
get
(
'/mirrors/status/json/'
)
self
.
assertEqual
(
response
.
status_code
,
200
)
data
=
json
.
loads
(
response
.
content
)
data
=
response
.
json
(
)
self
.
assertNotEqual
(
data
[
'urls'
],
[])
mirror_url
.
delete
()
packages/tests.py
View file @
bf3e96dc
import
json
import
unittest
from
django.core
import
mail
...
...
@@ -67,7 +66,7 @@ class PackageSearchJson(TestCase):
def
test_invalid
(
self
):
response
=
self
.
client
.
get
(
'/packages/search/json/'
)
self
.
assertEqual
(
response
.
status_code
,
200
)
data
=
json
.
loads
(
response
.
content
)
data
=
response
.
json
(
)
self
.
assertEqual
(
data
[
'limit'
],
250
)
self
.
assertEqual
(
data
[
'results'
],
[])
self
.
assertEqual
(
data
[
'valid'
],
False
)
...
...
@@ -75,7 +74,7 @@ def test_invalid(self):
def
test_reponame
(
self
):
response
=
self
.
client
.
get
(
'/packages/search/json/?repository=core'
)
self
.
assertEqual
(
response
.
status_code
,
200
)
data
=
json
.
loads
(
response
.
content
)
data
=
response
.
json
(
)
self
.
assertEqual
(
len
(
data
[
'results'
]),
5
)
self
.
assertEqual
(
set
(
map
(
lambda
r
:
r
[
'pkgname'
],
data
[
'results'
])),
{
"coreutils"
,
"glibc"
,
"linux"
,
"pacman"
,
"systemd"
})
...
...
@@ -83,19 +82,19 @@ def test_reponame(self):
def
test_packagename
(
self
):
response
=
self
.
client
.
get
(
'/packages/search/json/?name=linux'
)
self
.
assertEqual
(
response
.
status_code
,
200
)
data
=
json
.
loads
(
response
.
content
)
data
=
response
.
json
(
)
self
.
assertEqual
(
len
(
data
[
'results'
]),
1
)
def
test_no_results
(
self
):
response
=
self
.
client
.
get
(
'/packages/search/json/?name=none'
)
self
.
assertEqual
(
response
.
status_code
,
200
)
data
=
json
.
loads
(
response
.
content
)
data
=
response
.
json
(
)
self
.
assertEqual
(
len
(
data
[
'results'
]),
0
)
def
test_limit_four
(
self
):
response
=
self
.
client
.
get
(
'/packages/search/json/?limit=4'
)
self
.
assertEqual
(
response
.
status_code
,
200
)
data
=
json
.
loads
(
response
.
content
)
data
=
response
.
json
(
)
self
.
assertEqual
(
data
[
'page'
],
1
)
self
.
assertEqual
(
data
[
'num_pages'
],
2
)
self
.
assertEqual
(
data
[
'limit'
],
4
)
...
...
@@ -104,7 +103,7 @@ def test_limit_four(self):
def
test_second_page
(
self
):
response
=
self
.
client
.
get
(
'/packages/search/json/?limit=4&page=2'
)
self
.
assertEqual
(
response
.
status_code
,
200
)
data
=
json
.
loads
(
response
.
content
)
data
=
response
.
json
(
)
self
.
assertEqual
(
data
[
'page'
],
2
)
self
.
assertEqual
(
data
[
'num_pages'
],
2
)
self
.
assertEqual
(
len
(
data
[
'results'
]),
1
)
...
...
@@ -206,7 +205,7 @@ def test_packages_detail(self):
def
test_packages_json
(
self
):
response
=
self
.
client
.
get
(
'/packages/core/x86_64/linux/json/'
)
self
.
assertEqual
(
response
.
status_code
,
200
)
data
=
json
.
loads
(
response
.
content
)
data
=
response
.
json
(
)
self
.
assertEqual
(
data
[
'pkgbase'
],
'linux'
)
# TODO verify more of the structure
...
...
@@ -217,7 +216,7 @@ def test_packages_files(self):
def
test_packages_files_json
(
self
):
response
=
self
.
client
.
get
(
'/packages/core/x86_64/linux/files/json/'
)
self
.
assertEqual
(
response
.
status_code
,
200
)
data
=
json
.
loads
(
response
.
content
)
data
=
response
.
json
(
)
self
.
assertEqual
(
data
[
'pkgname'
],
'linux'
)
# TODO verify more of the structure
...
...
releng/tests/test_views.py
View file @
bf3e96dc
import
json
from
django.test
import
TestCase
from
releng.models
import
Release
...
...
@@ -15,7 +13,7 @@ def test_release_json(self):
version
=
self
.
release
.
version
response
=
self
.
client
.
get
(
'/releng/releases/json/'
)
self
.
assertEqual
(
response
.
status_code
,
200
)
data
=
json
.
loads
(
response
.
content
)
data
=
response
.
json
(
)
self
.
assertEqual
(
data
[
'version'
],
1
)
release
=
data
[
'releases'
][
0
]
...
...
Write
Preview
Supports
Markdown
0%
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!
Cancel
Please
register
or
sign in
to comment