Fakultas Ilmu Komputer UI

Commit 2241cac7 authored by I Gusti Putu Agastya Indrayana's avatar I Gusti Putu Agastya Indrayana Committed by igor lestin sianipar
Browse files

Pbi 2 login admin

parent 9f34fd33
......@@ -38,7 +38,8 @@
<div class="container-login100">
<div class="wrap-login100">
<form class="login100-form validate-form">
<form class="login100-form validate-form" method="POST">
{% csrf_token %}
<div class="login100-form-title p-b-43">
Halo, kontributor
......@@ -70,7 +71,7 @@
<div class="container-login100-form-btn">
<button class="login100-form-btn">
<button class="login100-form-btn" type="submit">
Login
</button>
</div>
......
......@@ -52,33 +52,35 @@
</div>
<div class="work_info">
<div class="login100-form-title p-b-43">
Halo, Admin
</div>
<div class="wrap-input100 validate-input" data-validate="Valid email is required: ex@abc.xyz">
<input class="input100" type="text" name="email">
<span class="focus-input100"></span>
<span class="label-input100">Email</span>
</div>
<div class="wrap-input100 validate-input" data-validate="Password is required">
<input class="input100" type="password" name="pass">
<span class="focus-input100"></span>
<span class="label-input100">Kata Sandi</span>
</div>
<br>
</br>
<div class="container-login100-form-btn">
<button class="login100-form-btn">
Login
</button>
</div>
<form class="login100-form validate-form" method="POST">
{% csrf_token %}
<div class="login100-form-title p-b-43">
Halo, Admin
</div>
<div class="wrap-input100 validate-input" data-validate="Valid email is required: ex@abc.xyz">
<input class="input100" type="text" name="email">
<span class="focus-input100"></span>
<span class="label-input100">Email</span>
</div>
<div class="wrap-input100 validate-input" data-validate="Password is required">
<input class="input100" type="password" name="pass">
<span class="focus-input100"></span>
<span class="label-input100">Kata Sandi</span>
</div>
<br>
</br>
<div class="container-login100-form-btn">
<button class="login100-form-btn" type="submit">
Login
</button>
</div>
</form>
</div>
</div>
</div>
......
......@@ -2,17 +2,16 @@ from django.test import TestCase, Client, RequestFactory
from django.urls import resolve
from authentication.views import Login
from authentication.models import User
from .views import login_admin
class LoginPageTest(TestCase):
class LoginPageContributorTest(TestCase):
def setUp(self):
User.objects._create_user(email="alice@acme.com", password="acmecorp")
User.objects._create_user(email="alice@acme.com", password="acmecorp", is_contributor=True)
def test_login_using_login_func(self):
def test_login_contributor_using_login_func(self):
found = resolve('/login/')
self.assertEqual(found.func.__name__, Login.as_view().__name__)
def test_login_url_is_exist(self):
def test_login_contributor_url_is_exist(self):
# Positive tests
response = Client().get('/login/')
self.assertEqual(response.status_code, 200)
......@@ -21,6 +20,12 @@ class LoginPageTest(TestCase):
response = Client().get('/fake/')
self.assertEqual(response.status_code, 404)
def test_login_contributor_template(self):
url = "/login/"
response = Client().get(url)
expected_template_name = "login.html"
self.assertTemplateUsed(response, expected_template_name)
def test_register_title(self):
response = Client().get('/login/')
......@@ -129,42 +134,72 @@ class UserModelTest(TestCase):
self.assertTrue(superuser.is_superuser)
class Login_AdminPageTest(TestCase):
def test_register_url_is_exist(self):
# Positive tests
response = Client().get('/login_admin/')
self.assertEqual(response.status_code, 200)
# Negative tests
response = Client().get('/fake/')
self.assertEqual(response.status_code, 404)
class LoginPageAdminTest(TestCase):
def setUp(self):
User.objects._create_user(email="alice@acme.com", password="acmecorp", is_admin=True)
def test_status_using_index_func(self):
# Positive tests
def test_login_admin_using_login_func(self):
found = resolve('/login_admin/')
self.assertEqual(found.func, login_admin)
self.assertEqual(found.func.__name__, Login.as_view().__name__)
# Negative tests
found = resolve('/admin/')
self.assertNotEqual(found.func, login_admin)
def test_login_admin_template(self):
url = "/login_admin/"
response = Client().get(url)
expected_template_name = "login_admin.html"
self.assertTemplateUsed(response, expected_template_name)
def test_login_admin_url_is_exist(self):
# Positive tests
response = Client().get('/login_admin/')
self.assertEqual(response.status_code, 200)
def test_register_title(self):
response = Client().get('/login_admin/')
# Positive tests
self.assertContains(response, 'Login Admin')
self.assertContains(response, 'Halo, Admin')
# Negative tests
self.assertNotContains(response, 'Fake Title')
def test_register_form_field(self):
def test_login_admin_form_field(self):
response = Client().get('/login_admin/')
# Positive tests
self.assertContains(response, 'Email')
self.assertContains(response, 'Password')
self.assertContains(response, 'Kata Sandi')
# Negative tests
self.assertNotContains(response, 'Jenis Kelamin')
def test_user_login_missing_email_or_password(self):
response = Client().post('/login_admin/', {'email': 'alice@acme.com'})
self.assertIn('error_message', response.context_data)
self.assertIn("Email atau Password anda kosong.",
response.context_data['error_message'])
response = Client().post('/login_admin/', {'pass': 'acmecorp'})
self.assertIn('error_message', response.context_data)
self.assertIn("Email atau Password anda kosong.",
response.context_data['error_message'])
def test_user_login_wrong_email_or_password(self):
# Wrong password
response = Client().post(
'/login_admin/', {'email': 'alice@acme.com', 'pass': 'acmeindustry'})
self.assertIn('error_message', response.context_data)
self.assertIn("Email atau Password anda salah.",
response.context_data['error_message'])
# Wrong email
response = Client().post(
'/login_admin/', {'email': 'alice@acme.co.id', 'pass': 'acmecorp'})
self.assertIn('error_message', response.context_data)
self.assertIn("Email atau Password anda salah.",
response.context_data['error_message'])
# Wrong email and password
response = Client().post(
'/login_admin/', {'email': 'alice@acme.co.id', 'pass': 'acmeindustry'})
self.assertIn('error_message', response.context_data)
self.assertIn("Email atau Password anda salah.",
response.context_data['error_message'])
def test_user_login(self):
# 302 meaning successful login and redirected
response = Client().post(
'/login_admin/', {'email': 'alice@acme.com', 'pass': 'acmecorp'})
self.assertEqual(302, response.status_code)
\ No newline at end of file
from django.urls import path
from authentication.views import Login, login_admin
from authentication.views import Login
from django.contrib.auth.views import LogoutView
urlpatterns = [
path('login/', Login.as_view()),
path('login_admin/', login_admin, name='login_admin'),
path('login/', Login.as_view(), name='login_admin'),
path('login_admin/', Login.as_view(), name='login_admin'),
path('logout/', LogoutView.as_view()),
]
\ No newline at end of file
......@@ -6,7 +6,13 @@ from django.contrib.auth.views import LogoutView
class Login(TemplateView):
template_name = 'login.html'
def get_template_names(self):
if self.request.path == '/login_admin/':
template_name = 'login_admin.html'
else:
template_name = 'login.html'
return template_name
def get_context_data(self, *args, **kwargs):
context = super().get_context_data(**kwargs)
......@@ -33,7 +39,3 @@ class Login(TemplateView):
context = self.get_context_data(*args, **kwargs)
context["error_message"] = "Email atau Password anda salah."
return self.render_to_response(context=context)
# Create your views here.
def login_admin(request):
return render(request, 'login_admin.html')
......@@ -260,7 +260,7 @@ iframe {
min-height: 100vh;
display: block;
background-color: #f7f7f7;
padding: 100px 55px 55px 55px;
padding: 173px 55px 55px 55px;
}
.login100-form-title {
......
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