More tests required - WiP

This commit is contained in:
Oliver Falk
2019-02-12 17:04:36 +01:00
parent 6468e9779e
commit 379e58392f
5 changed files with 246 additions and 0 deletions

View File

@@ -3,6 +3,7 @@ plugins =
django_coverage_plugin
omit =
node_modules/*
.virtualenv/*
[html]
extra_css = coverage_extra_style.css

View File

@@ -0,0 +1,80 @@
'''
Test our views in ivatar.ivataraccount.views and ivatar.views
'''
# pylint: disable=too-many-lines
from urllib.parse import urlsplit
from io import BytesIO
import io
import os
import django
from django.test import TestCase
from django.test import Client
from django.urls import reverse
from django.contrib.auth.models import User
from django.contrib.auth import authenticate
import hashlib
from libravatar import libravatar_url
from PIL import Image
os.environ['DJANGO_SETTINGS_MODULE'] = 'ivatar.settings'
django.setup()
# pylint: disable=wrong-import-position
from ivatar import settings
from ivatar.ivataraccount.forms import MAX_NUM_UNCONFIRMED_EMAILS_DEFAULT
from ivatar.ivataraccount.models import Photo, ConfirmedOpenId
from ivatar.utils import random_string
# pylint: enable=wrong-import-position
class Tester(TestCase): # pylint: disable=too-many-public-methods
'''
Main test class
'''
client = Client()
user = None
username = random_string()
password = random_string()
email = '%s@%s.%s' % (username, random_string(), random_string(2))
# Dunno why random tld doesn't work, but I'm too lazy now to investigate
openid = 'http://%s.%s.%s/' % (username, random_string(), 'org')
def login(self):
'''
Login as user
'''
self.client.login(username=self.username, password=self.password)
def setUp(self):
'''
Prepare for tests.
- Create user
'''
self.user = User.objects.create_user(
username=self.username,
password=self.password,
)
def test_contact_page(self):
"""
Test contact page
"""
response = self.client.get(reverse('contact'))
self.assertEqual(response.status_code, 200, 'no 200 ok?')
def test_description_page(self):
"""
Test description page
"""
response = self.client.get(reverse('description'))
self.assertEqual(response.status_code, 200, 'no 200 ok?')
def test_security_page(self):
"""
Test security page
"""
response = self.client.get(reverse('security'))
self.assertEqual(response.status_code, 200, 'no 200 ok?')

65
ivatar/test_views.py Normal file
View File

@@ -0,0 +1,65 @@
'''
Test our views in ivatar.ivataraccount.views and ivatar.views
'''
# pylint: disable=too-many-lines
from urllib.parse import urlsplit
from io import BytesIO
import io
import os
import django
from django.test import TestCase
from django.test import Client
from django.urls import reverse
from django.contrib.auth.models import User
from django.contrib.auth import authenticate
import hashlib
from libravatar import libravatar_url
from PIL import Image
os.environ['DJANGO_SETTINGS_MODULE'] = 'ivatar.settings'
django.setup()
# pylint: disable=wrong-import-position
from ivatar import settings
from ivatar.ivataraccount.forms import MAX_NUM_UNCONFIRMED_EMAILS_DEFAULT
from ivatar.ivataraccount.models import Photo, ConfirmedOpenId
from ivatar.utils import random_string
# pylint: enable=wrong-import-position
class Tester(TestCase): # pylint: disable=too-many-public-methods
'''
Main test class
'''
client = Client()
user = None
username = random_string()
password = random_string()
email = '%s@%s.%s' % (username, random_string(), random_string(2))
# Dunno why random tld doesn't work, but I'm too lazy now to investigate
openid = 'http://%s.%s.%s/' % (username, random_string(), 'org')
def login(self):
'''
Login as user
'''
self.client.login(username=self.username, password=self.password)
def setUp(self):
'''
Prepare for tests.
- Create user
'''
self.user = User.objects.create_user(
username=self.username,
password=self.password,
)
def test_incorrect_digest(self):
"""
Test incorrect digest
"""
response = self.client.get('/avatar/%s' % 'x'*65)
self.assertEqual(response.status_code, 200, 'no 200 ok?')

View File

@@ -0,0 +1,28 @@
{% extends 'base.html' %}
{% load i18n %}
{% load static %}
{% block title %}{% trans 'Check e-mail or openid' %}{% endblock title %}
{% block content %}
<h1>{% trans 'Check domain' %}</h1>
<div style="max-width:640px">
<form method="post" name="check">
{% csrf_token %}
<div class="form-group"><label for="id_mail">{% trans 'Domain' %}</label>
<input type="domain" name="domain" maxlength="254" minlength="6" class="form-control" placeholder="{% trans 'Domain' %}" {% if form.domain.value %} value="{{ form.domain.value }}" {% endif %} id="id_domain"></div>
<div class="form-group">
<button type="submit" class="btn btn-default">{% trans 'Check' %}</button>
</div>
</form>
</div>
{% if result %}
<hr/>
<h2>Domain check - TODO TODO</h2>
<p/>
{% endif %}
<div style="height:40px"></div>
{% endblock content %}

View File

@@ -0,0 +1,72 @@
'''
Test our views in ivatar.ivataraccount.views and ivatar.views
'''
# pylint: disable=too-many-lines
from urllib.parse import urlsplit
from io import BytesIO
import io
import os
import django
from django.test import TestCase
from django.test import Client
from django.urls import reverse
from django.contrib.auth.models import User
from django.contrib.auth import authenticate
import hashlib
from libravatar import libravatar_url
from PIL import Image
os.environ['DJANGO_SETTINGS_MODULE'] = 'ivatar.settings'
django.setup()
# pylint: disable=wrong-import-position
from ivatar import settings
from ivatar.ivataraccount.forms import MAX_NUM_UNCONFIRMED_EMAILS_DEFAULT
from ivatar.ivataraccount.models import Photo, ConfirmedOpenId
from ivatar.utils import random_string
# pylint: enable=wrong-import-position
class Tester(TestCase): # pylint: disable=too-many-public-methods
'''
Main test class
'''
client = Client()
user = None
username = random_string()
password = random_string()
email = '%s@%s.%s' % (username, random_string(), random_string(2))
# Dunno why random tld doesn't work, but I'm too lazy now to investigate
openid = 'http://%s.%s.%s/' % (username, random_string(), 'org')
def login(self):
'''
Login as user
'''
self.client.login(username=self.username, password=self.password)
def setUp(self):
'''
Prepare for tests.
- Create user
'''
self.user = User.objects.create_user(
username=self.username,
password=self.password,
)
def test_check(self):
"""
Test check page
"""
response = self.client.get(reverse('tools_check'))
self.assertEqual(response.status_code, 200, 'no 200 ok?')
def test_check_domain(self):
"""
Test check domain page
"""
response = self.client.get(reverse('tools_check_domain'))
self.assertEqual(response.status_code, 200, 'no 200 ok?')