From 379e58392f36941ec5f7b55bc77fd32a363c1528 Mon Sep 17 00:00:00 2001 From: Oliver Falk Date: Tue, 12 Feb 2019 17:04:36 +0100 Subject: [PATCH] More tests required - WiP --- .coveragerc | 1 + ivatar/test_static_pages.py | 80 ++++++++++++++++++++++++ ivatar/test_views.py | 65 +++++++++++++++++++ ivatar/tools/templates/check_domain.html | 28 +++++++++ ivatar/tools/test_views.py | 72 +++++++++++++++++++++ 5 files changed, 246 insertions(+) create mode 100644 ivatar/test_static_pages.py create mode 100644 ivatar/test_views.py create mode 100644 ivatar/tools/templates/check_domain.html create mode 100644 ivatar/tools/test_views.py diff --git a/.coveragerc b/.coveragerc index 33e6d5b..58ddbe7 100644 --- a/.coveragerc +++ b/.coveragerc @@ -3,6 +3,7 @@ plugins = django_coverage_plugin omit = node_modules/* + .virtualenv/* [html] extra_css = coverage_extra_style.css diff --git a/ivatar/test_static_pages.py b/ivatar/test_static_pages.py new file mode 100644 index 0000000..5191509 --- /dev/null +++ b/ivatar/test_static_pages.py @@ -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?') + diff --git a/ivatar/test_views.py b/ivatar/test_views.py new file mode 100644 index 0000000..dbed347 --- /dev/null +++ b/ivatar/test_views.py @@ -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?') diff --git a/ivatar/tools/templates/check_domain.html b/ivatar/tools/templates/check_domain.html new file mode 100644 index 0000000..f7e8db4 --- /dev/null +++ b/ivatar/tools/templates/check_domain.html @@ -0,0 +1,28 @@ +{% extends 'base.html' %} +{% load i18n %} +{% load static %} + +{% block title %}{% trans 'Check e-mail or openid' %}{% endblock title %} + +{% block content %} + +

{% trans 'Check domain' %}

+ +
+
+{% csrf_token %} +
+
+
+ +
+
+
+ +{% if result %} +
+

Domain check - TODO TODO

+

+{% endif %} +

+{% endblock content %} diff --git a/ivatar/tools/test_views.py b/ivatar/tools/test_views.py new file mode 100644 index 0000000..4520efb --- /dev/null +++ b/ivatar/tools/test_views.py @@ -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?')