Fakultas Ilmu Komputer UI

Commit 0a42171d authored by Farah Alhaniy's avatar Farah Alhaniy
Browse files

Merge branch 'exercise7'

parents 9cdac034 20db99bb
Pipeline #25386 failed with stages
in 1 minute and 28 seconds
......@@ -13,6 +13,7 @@ Test:
- python3 manage.py test lists
- python3 manage.py test accounts
- python3 manage.py muttest lists --modules lists.views
......@@ -14,6 +14,8 @@ Herokuapp : https://pmpl-farah.herokuapp.com/
- Exercise 6 :
- Pembuatan Mutant
- Mutation Testing Tool : Django-mutpy
- Exercise 7 :
- Spiking & De-Spiking
## Exercise 3
**Proses test isolation**
......@@ -115,4 +117,13 @@ Berikut adalah hasil dari mutation testing menggunakan django-mutpy. Tool ini di
- timeout: 0 (0.0%)
Destroying test database for alias 'default'...
Dari hasil tersebut dapat kita lihat bahwa semua mutant sudah berhasil di kill oleh test yang ada.
\ No newline at end of file
Dari hasil tersebut dapat kita lihat bahwa semua mutant sudah berhasil di kill oleh test yang ada.
## Exercise 6
Spiking adalah sebuah tahapan coding dimana kita mengeksplor suatu API baru atau solusi-solusi baru. Pada exercise, spiking dilakukan pada branch passwordless-spike dimana kita mengeksplor mengenai pengimplementasian paswordless auth.
De-spiking adalah tahapan dimana kita mengimplementasikan hasil di spiking dan menggunakannya di production codebase (master). Karena di spiking dapat dilakukan tanpa test, pada tahap De-spiking kita akan menggunakan TDD dalam implementasinya.
# Generated by Django 2.2.5 on 2019-11-13 05:33
# Generated by Django 2.2.5 on 2019-11-13 11:32
from django.db import migrations, models
......@@ -8,30 +8,13 @@ class Migration(migrations.Migration):
initial = True
dependencies = [
('auth', '0011_update_proxy_permissions'),
operations = [
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('email', models.EmailField(max_length=254)),
('uid', models.CharField(max_length=255)),
('password', models.CharField(max_length=128, verbose_name='password')),
('last_login', models.DateTimeField(blank=True, null=True, verbose_name='last login')),
('is_superuser', models.BooleanField(default=False, help_text='Designates that this user has all permissions without explicitly assigning them.', verbose_name='superuser status')),
('email', models.EmailField(max_length=254, primary_key=True, serialize=False)),
('groups', models.ManyToManyField(blank=True, help_text='The groups this user belongs to. A user will get all permissions granted to each of their groups.', related_name='user_set', related_query_name='user', to='auth.Group', verbose_name='groups')),
('user_permissions', models.ManyToManyField(blank=True, help_text='Specific permissions for this user.', related_name='user_set', related_query_name='user', to='auth.Permission', verbose_name='user permissions')),
'abstract': False,
# Generated by Django 2.2.5 on 2019-11-13 11:33
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('accounts', '0001_initial'),
operations = [
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('email', models.EmailField(max_length=254)),
('uid', models.CharField(max_length=40)),
from django.db import models
from django.contrib.auth.models import (
AbstractBaseUser, BaseUserManager, PermissionsMixin
import uuid
class Token(models.Model):
email = models.EmailField()
uid = models.CharField(max_length=255)
class ListUserManager(BaseUserManager):
def create_user(self, email):
def create_superuser(self, email, password):
uid = models.CharField(default=uuid.uuid4, max_length=40)
class ListUser(AbstractBaseUser, PermissionsMixin):
class User(models.Model):
email = models.EmailField(primary_key=True)
#REQUIRED_FIELDS = ['email', 'height']
objects = ListUserManager()
def is_staff(self):
return self.email == 'harry.percival@example.com'
def is_active(self):
return True
\ No newline at end of file
is_anonymous = False
is_authenticated = True
\ No newline at end of file
from django.test import TestCase
from django.contrib.auth import get_user_model
from accounts.models import Token
User = get_user_model()
class TokenModelTest(TestCase):
def test_links_user_with_auto_generated_uid(self):
token1 = Token.objects.create(email='a@b.com')
token2 = Token.objects.create(email='a@b.com')
self.assertNotEqual(token1.uid, token2.uid)
class UserModelTest(TestCase):
def test_user_is_valid_with_email_only(self):
user = User(email='a@b.com')
user.full_clean() # should not raise
def test_email_is_primary_key(self):
user = User(email='a@b.com')
self.assertEqual(user.pk, 'a@b.com')
\ No newline at end of file
from django.shortcuts import render
# Create your views here.
import uuid
import sys
from django.contrib.auth import authenticate
from django.contrib.auth import login as auth_login, logout as auth_logout
from django.core.mail import send_mail
from django.shortcuts import redirect, render
from accounts.models import Token
def send_login_email(request):
email = request.POST['email']
uid = str(uuid.uuid4())
Token.objects.create(email=email, uid=uid)
print('saving uid', uid, 'for email', email, file=sys.stderr)
url = request.build_absolute_uri(f'/accounts/login?uid={uid}')
'Your login link for Superlists',
f'Use this link to log in:\n\n{url}',
return render(request, 'login_email_sent.html')
def login(request):
print('login view', file=sys.stderr)
uid = request.GET.get('uid')
user = authenticate(uid=uid)
if user is not None:
auth_login(request, user)
return redirect('/')
def logout(request):
return redirect('/')
\ No newline at end of file
# Create your views here.
\ No newline at end of file
from django.core import mail
from selenium.webdriver.common.keys import Keys
import re
from unittest import skip
from .base import FunctionalTest
TEST_EMAIL = 'edith@example.com'
......@@ -10,6 +10,7 @@ SUBJECT = 'Your login link for Superlists'
class LoginTest(FunctionalTest):
def test_can_get_email_link_to_log_in(self):
# Edith goes to the awesome superlists site
# and notices a "Log in" section in the navbar for the first time
......@@ -16,19 +16,14 @@
<nav class="navbar navbar-default" role="navigation">
<div class="container-fluid">
<a class="navbar-brand" href="/">Superlists</a>
{% if user.is_authenticated %}
<p>Logged in as {{ user.email }}</p>
<p><a id="id_logout" href="{% url 'logout' %}">Log out</a></p>
{% else %}
<form class="navbar-form navbar-right" method="POST" action="{% url 'send_login_email' %}">
<form class="navbar-form navbar-right" method="POST" action="#">
<span>Enter email to log in:</span>
<input class="form-control" name="email" type="text" />
{% csrf_token %}
{% endif %}
<div class="row">
<div class="col-md-6 col-md-offset-3 jumbotron">
<div class="text-center">
......@@ -40,14 +40,11 @@ INSTALLED_APPS = [
AUTH_USER_MODEL = 'accounts.ListUser'
AUTH_USER_MODEL = 'accounts.User'
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