Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
La Quadrature du Net
rpteam
Revue de Press
Commits
fe6ab394
Commit
fe6ab394
authored
Apr 22, 2017
by
luxcem
Browse files
fix tests
parent
bc86afd6
Changes
7
Hide whitespace changes
Inline
Side-by-side
.gitignore
View file @
fe6ab394
...
...
@@ -23,8 +23,9 @@ project/settings/env.py
node_modules/
# Testing
static/media/
# Testing
htmlcov
.coverage
.tox
apps/core/tests.py
View file @
fe6ab394
from
django.test
import
TestCase
from
django.test
import
Client
from
django_factory_boy
import
auth
as
auth_factories
# Create your tests here.
AUTHENTICATION_BACKENDS
=
[
# Default
"django.contrib.auth.backends.ModelBackend"
,
# Email or Username for login
"core.auth_backends.EmailOrUsernameModelBackend"
]
class
ApiTest
(
TestCase
):
def
setUp
(
self
):
self
.
client
=
Client
()
self
.
user
=
auth_factories
.
UserFactory
(
password
=
"dummypassword"
)
def
test_authenticate
(
self
):
with
self
.
settings
(
AUTHENTICATION_BACKENDS
=
AUTHENTICATION_BACKENDS
):
# username, wrong password
login_status
=
self
.
client
.
login
(
username
=
self
.
user
.
username
,
password
=
"notthepassword"
)
assert
not
login_status
# username, correct password
login_status
=
self
.
client
.
login
(
username
=
self
.
user
.
username
,
password
=
"dummypassword"
)
assert
login_status
# email, wrong password
login_status
=
self
.
client
.
login
(
username
=
self
.
user
.
email
,
password
=
"notthepassowrd"
)
assert
not
login_status
# email, correct password
login_status
=
self
.
client
.
login
(
username
=
self
.
user
.
email
,
password
=
"dummypassword"
)
assert
login_status
# username, wrong user
login_status
=
self
.
client
.
login
(
username
=
"{}-2"
.
format
(
self
.
user
.
username
),
password
=
"dummypassword"
)
assert
not
login_status
# email, wrong user
login_status
=
self
.
client
.
login
(
username
=
"{}-2"
.
format
(
self
.
user
.
email
),
password
=
"dummypassword"
)
assert
not
login_status
apps/core/tests/test_authbackends.py
deleted
100644 → 0
View file @
bc86afd6
from
django.test
import
TestCase
from
django.test
import
Client
from
django_factory_boy
import
auth
as
auth_factories
AUTHENTICATION_BACKENDS
=
[
# Default
"django.contrib.auth.backends.ModelBackend"
,
# Email or Username for login
"core.auth_backends.EmailOrUsernameModelBackend"
]
class
ApiTest
(
TestCase
):
def
setUp
(
self
):
self
.
client
=
Client
()
self
.
user
=
auth_factories
.
UserFactory
(
password
=
"dummypassword"
)
def
test_authenticate
(
self
):
with
self
.
settings
(
AUTHENTICATION_BACKENDS
=
AUTHENTICATION_BACKENDS
):
# username, wrong password
login_status
=
self
.
client
.
login
(
username
=
self
.
user
.
username
,
password
=
"notthepassword"
)
assert
not
login_status
# username, correct password
login_status
=
self
.
client
.
login
(
username
=
self
.
user
.
username
,
password
=
"dummypassword"
)
assert
login_status
# email, wrong password
login_status
=
self
.
client
.
login
(
username
=
self
.
user
.
email
,
password
=
"notthepassowrd"
)
assert
not
login_status
# email, correct password
login_status
=
self
.
client
.
login
(
username
=
self
.
user
.
email
,
password
=
"dummypassword"
)
assert
login_status
# username, wrong user
login_status
=
self
.
client
.
login
(
username
=
"{}-2"
.
format
(
self
.
user
.
username
),
password
=
"dummypassword"
)
assert
not
login_status
# email, wrong user
login_status
=
self
.
client
.
login
(
username
=
"{}-2"
.
format
(
self
.
user
.
email
),
password
=
"dummypassword"
)
assert
not
login_status
apps/
core/
tests/__init__.py
→
apps/tests/__init__.py
View file @
fe6ab394
File moved
apps/tests/test_authbackends.py
0 → 100644
View file @
fe6ab394
apps/userprofile/models.py
View file @
fe6ab394
...
...
@@ -41,8 +41,8 @@ class Profile(models.Model):
app_label
=
"userprofile"
def
__str__
(
self
):
"""Returns user
full
name"""
return
self
.
username
"""Returns user
user
name"""
return
self
.
user
.
username
def
delete
(
self
,
*
args
,
**
kwargs
):
"""Deletes ``django.contrib.auth.models.User`` and
...
...
apps/userprofile/tests.py
View file @
fe6ab394
...
...
@@ -14,9 +14,7 @@ def test_profile():
profile
=
ProfileFactory
()
assert
type
(
profile
.
user
)
==
User
assert
type
(
profile
)
==
Profile
assert
type
(
profile
.
full_name
)
==
str
assert
profile
.
slug
==
slugify
(
profile
.
user
.
username
)
assert
type
(
profile
.
identity
)
==
str
assert
str
(
profile
)
==
profile
.
full_name
assert
str
(
profile
)
==
profile
.
user
.
username
profile
.
delete
()
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