Fakultas Ilmu Komputer UI

Commit 79c4c0c3 authored by Syahrul Ardiansyah's avatar Syahrul Ardiansyah
Browse files

Fix test

parent ad5f4849
Pipeline #25792 passed with stage
in 1 minute and 40 seconds
from django.test import TestCase from django.test import TestCase
from django.contrib.auth import get_user_model from django.contrib import auth
from accounts.models import Token from accounts.models import Token
User = get_user_model() User = auth.get_user_model()
class UserModelTest(TestCase): class UserModelTest(TestCase):
......
...@@ -11,19 +11,17 @@ from accounts.models import Token ...@@ -11,19 +11,17 @@ from accounts.models import Token
def send_login_email(request): def send_login_email(request):
email = request.POST['email'] email = request.POST['email']
# uid = str(uuid.uuid4())
token = Token.objects.create(email=email) token = Token.objects.create(email=email)
url = request.build_absolute_uri( url = request.build_absolute_uri(
reverse('login') + '?token=' + str(token.uid) reverse('login') + '?token=' + str(token.uid)
) )
message_body = f'Use this link to log in:\n\n{url}' message_body = 'Use this link to log in:\n\n%s' % url
send_mail( send_mail(
'Your login link for Superlists', 'Your login link for Superlists',
message_body, message_body,
'noreply@superlists', 'noreply@superlists',
[email], [email],
) )
# return render(request, 'login_email_sent.html')
messages.success( messages.success(
request, request,
"Check your email, we've sent you a link you can use to log in." "Check your email, we've sent you a link you can use to log in."
...@@ -35,10 +33,6 @@ def login(request): ...@@ -35,10 +33,6 @@ def login(request):
user = auth.authenticate(uid=request.GET.get('token')) user = auth.authenticate(uid=request.GET.get('token'))
if user: if user:
auth.login(request, user) auth.login(request, user)
# uid = request.GET.get('uid')
# user = authenticate(uid=uid)
# if user is not None:
# auth_login(request, user)
return redirect('/') return redirect('/')
......
...@@ -31,7 +31,7 @@ class LoginTest(FunctionalTest): ...@@ -31,7 +31,7 @@ class LoginTest(FunctionalTest):
self.assertIn('Use this link to log in', email.body) self.assertIn('Use this link to log in', email.body)
url_search = re.search(r'http://.+/.+$', email.body) url_search = re.search(r'http://.+/.+$', email.body)
if not url_search: if not url_search:
self.fail(f'Could not find url in email body:\n{email.body}') self.fail('Could not find url in email body:\n%s' % email.body)
url = url_search.group(0) url = url_search.group(0)
self.assertIn(self.live_server_url, url) self.assertIn(self.live_server_url, url)
......
Supports Markdown
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