Skip to content
GitLab
Menu
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
b3475381
Unverified
Commit
b3475381
authored
Apr 08, 2018
by
Jelle van der Waa
🚧
Committed by
GitHub
Apr 08, 2018
Browse files
Merge pull request #92 from jelly/extended_tests
Extended tests
parents
843c9a43
b63ebfe7
Changes
10
Hide whitespace changes
Inline
Side-by-side
devel/tests/test_reports.py
0 → 100644
View file @
b3475381
from
django.test
import
TransactionTestCase
from
django.contrib.auth.models
import
User
class
DeveloperReport
(
TransactionTestCase
):
fixtures
=
[
'main/fixtures/arches.json'
,
'main/fixtures/repos.json'
,
'main/fixtures/package.json'
]
def
setUp
(
self
):
password
=
'test'
self
.
user
=
User
.
objects
.
create_superuser
(
'admin'
,
'admin@archlinux.org'
,
password
)
self
.
client
.
post
(
'/login/'
,
{
'username'
:
self
.
user
.
username
,
'password'
:
password
})
def
tearDown
(
self
):
self
.
user
.
delete
()
def
test_overview
(
self
):
response
=
self
.
client
.
get
(
'/devel/'
)
self
.
assertEqual
(
response
.
status_code
,
200
)
def
test_reports_old
(
self
):
response
=
self
.
client
.
get
(
'/devel/reports/old'
,
follow
=
True
)
self
.
assertEqual
(
response
.
status_code
,
200
)
def
test_reports_outofdate
(
self
):
response
=
self
.
client
.
get
(
'/devel/reports/long-out-of-date'
,
follow
=
True
)
self
.
assertEqual
(
response
.
status_code
,
200
)
def
test_reports_big
(
self
):
response
=
self
.
client
.
get
(
'/devel/reports/big'
,
follow
=
True
)
self
.
assertEqual
(
response
.
status_code
,
200
)
def
test_reports_badcompression
(
self
):
response
=
self
.
client
.
get
(
'/devel/reports/badcompression'
,
follow
=
True
)
self
.
assertEqual
(
response
.
status_code
,
200
)
def
test_reports_uncompressed_man
(
self
):
response
=
self
.
client
.
get
(
'/devel/reports/uncompressed-man'
,
follow
=
True
)
self
.
assertEqual
(
response
.
status_code
,
200
)
def
test_reports_uncompressed_info
(
self
):
response
=
self
.
client
.
get
(
'/devel/reports/uncompressed-info'
,
follow
=
True
)
self
.
assertEqual
(
response
.
status_code
,
200
)
def
test_reports_unneeded_orphans
(
self
):
response
=
self
.
client
.
get
(
'/devel/reports/unneeded-orphans'
,
follow
=
True
)
self
.
assertEqual
(
response
.
status_code
,
200
)
def
test_reports_mismatched_signature
(
self
):
response
=
self
.
client
.
get
(
'/devel/reports/mismatched-signature'
,
follow
=
True
)
self
.
assertEqual
(
response
.
status_code
,
200
)
def
test_reports_signature_time
(
self
):
response
=
self
.
client
.
get
(
'/devel/reports/signature-time'
,
follow
=
True
)
self
.
assertEqual
(
response
.
status_code
,
200
)
main/management/commands/donor_import.py
View file @
b3475381
...
...
@@ -23,7 +23,7 @@
from
parse
import
parse
from
django.db.utils
import
Error
as
DBError
from
django.core.management.base
import
BaseCommand
from
django.core.management.base
import
BaseCommand
,
CommandError
from
main.models
import
Donor
...
...
@@ -91,8 +91,7 @@ def handle(self, *args, **options):
directory
=
options
[
'maildir'
]
maildir
=
mailbox
.
Maildir
(
directory
,
create
=
False
)
except
mailbox
.
Error
:
logger
.
error
(
u
"Failed to open maildir: '%s'"
,
directory
)
return
0
raise
CommandError
(
u
"Failed to open maildir"
)
for
msg
in
maildir
:
subject
=
msg
.
get
(
'subject'
,
''
)
...
...
main/tests/test_donor_import.py
View file @
b3475381
# -*- coding: utf-8 -*-
from
email.header
import
Header
from
django.test
import
SimpleTestCase
from
django.core.management
import
call_command
from
django.core.management.base
import
CommandError
from
main.management.commands.donor_import
import
Command
...
...
@@ -20,9 +26,23 @@ def test_parse_subject(self):
output
=
self
.
command
.
parse_subject
(
valid
)
self
.
assertEqual
(
output
,
u
'John Doe'
)
def
test_parse_name
(
self
):
self
.
assertEqual
(
self
.
command
.
sanitize_name
(
u
'1244'
),
u
''
)
self
.
assertEqual
(
self
.
command
.
sanitize_name
(
u
'John Doe'
),
u
'John Doe'
)
self
.
assertEqual
(
self
.
command
.
sanitize_name
(
u
' John Doe '
),
u
'John Doe'
)
self
.
assertEqual
(
self
.
command
.
sanitize_name
(
u
'John Doe 23'
),
u
'John Doe'
)
def
test_decode_subject
(
self
):
text
=
u
'メイル'
subject
=
str
(
Header
(
text
,
'utf-8'
))
self
.
assertEqual
(
self
.
command
.
decode_subject
(
subject
),
text
)
def
test_invalid_args
(
self
):
with
self
.
assertRaises
(
CommandError
)
as
e
:
call_command
(
'donor_import'
)
self
.
assertIn
(
'Error: too few arguments'
,
str
(
e
.
exception
))
def
test_invalid_path
(
self
):
with
self
.
assertRaises
(
CommandError
)
as
e
:
call_command
(
'donor_import'
,
'/tmp/non-existant'
)
self
.
assertIn
(
'Failed to open maildir'
,
str
(
e
.
exception
))
main/tests/test_templatetags_pgp.py
View file @
b3475381
...
...
@@ -21,8 +21,8 @@ def test_format_key(self):
pgp_key_len
=
len
(
pgp_key
)
+
len
(
'0x'
)
self
.
assertEqual
(
pgp_key_len
,
len
(
format_key
(
pgp_key
)))
# 8
-
20 len case
pgp_key
=
'3E2C81117BFB1108D'
# 8
,
20 len case
pgp_key
=
'3E2C81117BFB1108D
EFF
'
pgp_key_len
=
len
(
pgp_key
)
+
len
(
'0x'
)
self
.
assertEqual
(
pgp_key_len
,
len
(
format_key
(
pgp_key
)))
...
...
@@ -31,6 +31,11 @@ def test_format_key(self):
pgp_key_len
=
len
(
pgp_key
)
+
len
(
'0x'
)
self
.
assertEqual
(
pgp_key_len
,
len
(
format_key
(
pgp_key
)))
def
assert_pgp_key_link
(
self
,
pgp_key
):
output
=
pgp_key_link
(
int
(
pgp_key
,
16
))
self
.
assertIn
(
pgp_key
[
2
:],
output
)
self
.
assertIn
(
"https"
,
output
)
def
test_pgp_key_link
(
self
):
self
.
assertEqual
(
pgp_key_link
(
""
),
"Unknown"
)
...
...
@@ -43,6 +48,15 @@ def test_pgp_key_link(self):
self
.
assertIn
(
"test"
,
output
)
self
.
assertIn
(
"https"
,
output
)
# Numeric key_id <= 8
self
.
assert_pgp_key_link
(
'0x0023BDC7'
)
# Numeric key_id <= 16
self
.
assert_pgp_key_link
(
'0xBDC7FF5E34A12F'
)
# Numeric key_id <= 40
self
.
assert_pgp_key_link
(
'0xA10E234343EA8BDC7FF5E34A12F'
)
pgp_key
=
'423423fD9004FB063E2C81117BFB1108D234DAFZ'
server
=
getattr
(
settings
,
'PGP_SERVER'
)
...
...
mirrors/tests/test_mirrorlist.py
View file @
b3475381
...
...
@@ -14,10 +14,6 @@ def test_mirrorlist(self):
response
=
self
.
client
.
get
(
'/mirrorlist/'
)
self
.
assertEqual
(
response
.
status_code
,
200
)
def
test_mirrorlist
(
self
):
response
=
self
.
client
.
get
(
'/mirrorlist/'
)
self
.
assertEqual
(
response
.
status_code
,
200
)
def
test_mirrorlist_all
(
self
):
response
=
self
.
client
.
get
(
'/mirrorlist/all/'
)
self
.
assertEqual
(
response
.
status_code
,
200
)
...
...
mirrors/tests/test_mirrors.py
0 → 100644
View file @
b3475381
import
json
from
django.test
import
TestCase
from
mirrors.tests
import
create_mirror_url
class
MirrorTest
(
TestCase
):
def
test_details
(
self
):
response
=
self
.
client
.
get
(
'/mirrors/nothing/'
)
self
.
assertEqual
(
response
.
status_code
,
404
)
mirror_url
=
create_mirror_url
()
url
=
mirror_url
.
mirror
.
get_absolute_url
()
response
=
self
.
client
.
get
(
url
)
self
.
assertEqual
(
response
.
status_code
,
200
)
# FIXME: request as mirror admin
def
test_details_json
(
self
):
response
=
self
.
client
.
get
(
'/mirrors/nothing/json/'
)
self
.
assertEqual
(
response
.
status_code
,
404
)
mirror_url
=
create_mirror_url
()
url
=
mirror_url
.
mirror
.
get_absolute_url
()
response
=
self
.
client
.
get
(
url
+
'json/'
)
self
.
assertEqual
(
response
.
status_code
,
200
)
data
=
json
.
loads
(
response
.
content
)
self
.
assertNotEqual
(
data
[
'urls'
],
[])
def
test_url_details
(
self
):
mirror_url
=
create_mirror_url
()
url
=
mirror_url
.
mirror
.
get_absolute_url
()
response
=
self
.
client
.
get
(
url
+
'{}/'
.
format
(
mirror_url
.
id
))
self
.
assertEqual
(
response
.
status_code
,
200
)
mirrors/tests/test_mirrorstatus.py
View file @
b3475381
...
...
@@ -34,3 +34,23 @@ def test_json_endpoint(self):
self
.
assertEqual
(
mirror
[
'url'
],
mirror_url
.
url
)
mirror_url
.
delete
()
def
test_json_tier
(
self
):
response
=
self
.
client
.
get
(
'/mirrors/status/tier/99/json/'
)
self
.
assertEqual
(
response
.
status_code
,
404
)
response
=
self
.
client
.
get
(
'/mirrors/status/tier/1/json/'
)
self
.
assertEqual
(
response
.
status_code
,
200
)
data
=
json
.
loads
(
response
.
content
)
self
.
assertEqual
(
data
[
'urls'
],
[])
mirror_url
=
create_mirror_url
()
# 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
)
self
.
assertNotEqual
(
data
[
'urls'
],
[])
mirror_url
.
delete
()
todolists/tests/__init__.py
0 → 100644
View file @
b3475381
todolists/tests/test_templatetags_todolists.py
0 → 100644
View file @
b3475381
from
django.contrib.auth.models
import
User
from
django.test
import
TestCase
from
main.models
import
Package
from
todolists.models
import
Todolist
,
TodolistPackage
from
todolists.templatetags.todolists
import
todopkg_details_link
class
TestTodolist
(
TestCase
):
fixtures
=
[
'main/fixtures/arches.json'
,
'main/fixtures/repos.json'
,
'main/fixtures/package.json'
]
def
setUp
(
self
):
self
.
user
=
User
.
objects
.
create
(
username
=
"joeuser"
,
first_name
=
"Joe"
,
last_name
=
"User"
,
email
=
"user1@example.com"
)
self
.
todolist
=
Todolist
.
objects
.
create
(
name
=
'Boost rebuild'
,
description
=
'Boost 1.66 rebuid'
,
creator
=
self
.
user
,
raw
=
'linux'
)
def
test_details_link
(
self
):
pkg
=
Package
.
objects
.
first
()
todopkg
=
TodolistPackage
.
objects
.
create
(
pkg
=
pkg
,
pkgname
=
pkg
.
pkgname
,
pkgbase
=
pkg
.
pkgbase
,
arch
=
pkg
.
arch
,
repo
=
pkg
.
repo
,
user
=
self
.
user
,
todolist
=
self
.
todolist
)
link
=
todopkg_details_link
(
todopkg
)
self
.
assertIn
(
'View package details for {}'
.
format
(
todopkg
.
pkg
.
pkgname
),
link
)
todolists/tests/test_views.py
0 → 100644
View file @
b3475381
from
django.contrib.auth.models
import
User
from
django.test
import
TestCase
from
todolists.models
import
Todolist
class
TestTodolist
(
TestCase
):
fixtures
=
[
'main/fixtures/arches.json'
,
'main/fixtures/repos.json'
,
'main/fixtures/package.json'
]
def
setUp
(
self
):
self
.
user
=
User
.
objects
.
create
(
username
=
"joeuser"
,
first_name
=
"Joe"
,
last_name
=
"User"
,
email
=
"user1@example.com"
)
self
.
todolist
=
Todolist
.
objects
.
create
(
name
=
'Boost rebuild'
,
description
=
'Boost 1.66 rebuid'
,
creator
=
self
.
user
,
slug
=
'boost-rebuild'
,
raw
=
'linux'
)
def
test_todolist_overview
(
self
):
response
=
self
.
client
.
get
(
'/todo/'
)
self
.
assertEqual
(
response
.
status_code
,
200
)
self
.
assertIn
(
self
.
todolist
.
name
,
response
.
content
)
def
test_todolist_detail
(
self
):
response
=
self
.
client
.
get
(
self
.
todolist
.
get_absolute_url
())
self
.
assertEqual
(
response
.
status_code
,
200
)
self
.
assertIn
(
self
.
todolist
.
name
,
response
.
content
)
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a 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