Commit fe6ab394 authored by luxcem's avatar luxcem

fix tests

parent bc86afd6
......@@ -23,8 +23,9 @@ project/settings/env.py
node_modules/
# Testing
static/media/
# Testing
htmlcov
.coverage
.tox
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
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
......@@ -41,8 +41,8 @@ class Profile(models.Model):
app_label = "userprofile"
def __str__(self):
"""Returns user full name"""
return self.username
"""Returns user username"""
return self.user.username
def delete(self, *args, **kwargs):
"""Deletes ``django.contrib.auth.models.User`` and
......
......@@ -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()
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment