added test

This commit is contained in:
Tomislav R 2016-05-02 02:00:38 +02:00
parent 65e3cdeb94
commit b19e33b8da
7 changed files with 86 additions and 27 deletions

View file

@ -1,10 +1,13 @@
import json
from django.test import TestCase from django.test import TestCase
from django.core.urlresolvers import reverse from django.core.urlresolvers import reverse
from django.core.urlresolvers import resolve from django.core.urlresolvers import resolve
from cms.test_utils.testcases import CMSTestCase
from cms.api import create_page
class ContactViewTest(TestCase): class ContactViewTest(TestCase):
def setUp(self): def setUp(self):
self.url = reverse('digitalglarus:contact') self.url = reverse('digitalglarus:contact')
self.data = { self.data = {
@ -21,3 +24,28 @@ class ContactViewTest(TestCase):
def test_any_user_should_contact_us(self): def test_any_user_should_contact_us(self):
response = self.client.post(self.url, self.data, follow=True) response = self.client.post(self.url, self.data, follow=True)
self.assertEqual(response.status_code, 200) self.assertEqual(response.status_code, 200)
class ViewsTest(CMSTestCase):
def setUp(self):
self.page1 = create_page('home', 'home_digitalglarus.html', published=True, language='en-us')
self.page2 = create_page('about', 'about.html', published=True, language='en-us', slug='about')
def test_digitalglarus_templates(self):
res1 = self.client.get('/en-us/')
self.assertContains(res1, 'Digital Glarus', status_code=200)
res2 = self.client.get('/en-us/about/')
self.assertEqual(res2.status_code, 200)
class CalendarApiTestCase(TestCase):
def test_api_response(self):
calendar_api_url_1 = reverse('digitalglarus:calendar_api_1', kwargs={'month': '3', 'year': '2016'})
res1 = self.client.get(calendar_api_url_1)
pd = json.loads(res1.content.decode('utf-8'))
self.assertEqual(pd['month'], '3')
self.assertEqual(pd['year'], '2016')
# TODO:check post
# calendar_api_url = reverse('digitalglarus:calendar_api')
# res = self.client.get(calendar_api_url)

View file

@ -10,8 +10,8 @@ urlpatterns = [
# url(_(r'about/?$'), AboutView.as_view(), name='about'), # url(_(r'about/?$'), AboutView.as_view(), name='about'),
url(_(r'contact/?$'), ContactView.as_view(), name='contact'), url(_(r'contact/?$'), ContactView.as_view(), name='contact'),
url(_(r'supporters/?$'), views.supporters, name='supporters'), url(_(r'supporters/?$'), views.supporters, name='supporters'),
url(r'calendar_api/(?P<month>\d+)/(?P<year>\d+)?$', views.CalendarApi.as_view()), url(r'calendar_api/(?P<month>\d+)/(?P<year>\d+)?$', views.CalendarApi.as_view(),name='calendar_api_1'),
url(r'calendar_api/', views.CalendarApi.as_view()), url(r'calendar_api/', views.CalendarApi.as_view(),name='calendar_api'),
url(_(r'support-us/?$'), views.support, name='support'), url(_(r'support-us/?$'), views.support, name='support'),
url(r'^blog/(?P<slug>\w[-\w]*)/$', views.blog_detail, name='blog-detail'), url(r'^blog/(?P<slug>\w[-\w]*)/$', views.blog_detail, name='blog-detail'),
url(r'blog/$', views.blog, name='blog'), url(r'blog/$', views.blog, name='blog'),

View file

@ -175,13 +175,8 @@ USE_L10N = True
USE_TZ = True USE_TZ = True
LANGUAGES = ( LANGUAGES = (
<<<<<<< HEAD:dynamicweb/settings-test/__init__.py
('en-us', _('English')),
('de', _('Deutsch')),
=======
('en-us', _('US English')), ('en-us', _('US English')),
('de', _('German')), ('de', _('German')),
>>>>>>> remotes/origin/feature/digital.glarus.german:dynamicweb/settings.py
) )
LANGUAGE_CODE = 'en-us' LANGUAGE_CODE = 'en-us'

View file

@ -0,0 +1,20 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.9.4 on 2016-05-01 15:38
from __future__ import unicode_literals
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('membership', '0004_stripecustomer'),
]
operations = [
migrations.AddField(
model_name='customuser',
name='is_admin',
field=models.BooleanField(default=False, help_text='Designates whether the user can log into this admin site.', verbose_name='staff status'),
),
]

View file

@ -29,6 +29,7 @@ class MyUserManager(BaseUserManager):
name=name, name=name,
validation_slug=make_password(None) validation_slug=make_password(None)
) )
user.is_admin = False
user.set_password(password) user.set_password(password)
user.save(using=self._db) user.save(using=self._db)
return user return user
@ -54,7 +55,7 @@ class CustomUser(AbstractBaseUser):
validated = models.IntegerField(choices=VALIDATED_CHOICES, default=0) validated = models.IntegerField(choices=VALIDATED_CHOICES, default=0)
validation_slug = models.CharField(db_index=True, unique=True, max_length=50) validation_slug = models.CharField(db_index=True, unique=True, max_length=50)
is_staff = models.BooleanField( is_admin = models.BooleanField(
_('staff status'), _('staff status'),
default=False, default=False,
help_text=_('Designates whether the user can log into this admin site.'), help_text=_('Designates whether the user can log into this admin site.'),
@ -92,9 +93,6 @@ class CustomUser(AbstractBaseUser):
def is_superuser(self): def is_superuser(self):
return False return False
def is_admin(self):
return True
def get_full_name(self): def get_full_name(self):
# The user is identified by their email address # The user is identified by their email address
return self.email return self.email
@ -109,12 +107,12 @@ class CustomUser(AbstractBaseUser):
def has_perm(self, perm, obj=None): def has_perm(self, perm, obj=None):
"Does the user have a specific permission?" "Does the user have a specific permission?"
# Simplest possible answer: Yes, always # Simplest possible answer: Yes, always
return True return self.is_admin
def has_module_perms(self, app_label): def has_module_perms(self, app_label):
"Does the user have permissions to view the app `app_label`?" "Does the user have permissions to view the app `app_label`?"
# Simplest possible answer: Yes, always # Simplest possible answer: Yes, always
return True return self.is_admin
@property @property
def is_staff(self): def is_staff(self):

View file

@ -1,13 +1,31 @@
import unittest import re
from django.test import TestCase,Client
# Create your tests here. from django.test import TestCase
class LoginTestCase(unittest.TestCase): from django.core.urlresolvers import reverse
from django.core import mail
class LoginTestCase(TestCase):
def test_login(self): def test_login(self):
client = Client() url = reverse('login_glarus')
response = client.get("/login") res = self.client.post(url, data={'email': 'test@gmail.com', 'password': 'test', 'name': 'test'})
self.assertContains(res, "You\'re successfully registered!", 1, 200)
self.assertEqual(len(mail.outbox), 1)
validation_url = re.findall(r"http://.*?(/.*)", mail.outbox[0].body)
res1 = self.client.get(validation_url[0] + '/')
self.assertContains(res1, "Email verified!", 1, 200)
res2 = self.client.post(url, data={'email': 'test@gmail.com', 'password': 'test'})
self.assertEqual(res2.status_code, 302)
redirect_location = res2.get('Location')
res3 = self.client.get(redirect_location)
self.assertContains(res3, 'Pick coworking date.', 1, 200)
# check fail login
res4 = self.client.post(url, data={'email': 'test@gmail.com', 'password': 'falsepassword'})
self.assertContains(res4,'Sorry, that login was invalid.',1,200)

View file

@ -1,4 +1,4 @@
{% load static meta%} {% load static meta cms_tags%}
{% load i18n %} {% load i18n %}
<section id="contact"> <section id="contact">
@ -13,7 +13,7 @@
{% endfor %} {% endfor %}
<h2 class="section-heading">{% trans "Contact Us" %}</h2> <h2 class="section-heading">{% trans "Contact Us" %}</h2>
<br> <br>
<h3 class="intro-smallcap">{% trans "Join us at" %} <a href="{% url 'digitalglarus:home'%}">{% trans "Digital Glarus" %}</a>, <h3 class="intro-smallcap">{% trans "Join us at" %} <a href="{% page_url 'digital-glarus-page' %}">{% trans "Digital Glarus" %}</a>,
{% trans "a great co-working space in the middle of Alps!" %} <p></p> {% trans "You can contact us at" %} </h3> {% trans "a great co-working space in the middle of Alps!" %} <p></p> {% trans "You can contact us at" %} </h3>
<h3 class="intro-smallcap"><a href="mailto:info@ungleich.ch" ><i class="fa fa-envelope">info@ungleich.ch</i></a></h3> <h3 class="intro-smallcap"><a href="mailto:info@ungleich.ch" ><i class="fa fa-envelope">info@ungleich.ch</i></a></h3>
<h3 class="intro-smallcap"><i class="fa fa-phone"></i> (044) 534-66-22<p></p></h3> <h3 class="intro-smallcap"><i class="fa fa-phone"></i> (044) 534-66-22<p></p></h3>