From b19e33b8da0488278c9543900522f0ef314ba099 Mon Sep 17 00:00:00 2001 From: Tomislav R Date: Mon, 2 May 2016 02:00:38 +0200 Subject: [PATCH] added test --- digitalglarus/test_views.py | 30 +++++++++++++++- digitalglarus/urls.py | 4 +-- dynamicweb/settings-test/__init__.py | 5 --- .../migrations/0005_customuser_is_admin.py | 20 +++++++++++ membership/models.py | 14 ++++---- membership/tests.py | 36 ++++++++++++++----- .../ungleich_page/includes/_contact_us.html | 4 +-- 7 files changed, 86 insertions(+), 27 deletions(-) create mode 100644 membership/migrations/0005_customuser_is_admin.py diff --git a/digitalglarus/test_views.py b/digitalglarus/test_views.py index 1c5824f5..5658a73c 100644 --- a/digitalglarus/test_views.py +++ b/digitalglarus/test_views.py @@ -1,10 +1,13 @@ +import json + from django.test import TestCase from django.core.urlresolvers import reverse from django.core.urlresolvers import resolve +from cms.test_utils.testcases import CMSTestCase +from cms.api import create_page class ContactViewTest(TestCase): - def setUp(self): self.url = reverse('digitalglarus:contact') self.data = { @@ -21,3 +24,28 @@ class ContactViewTest(TestCase): def test_any_user_should_contact_us(self): response = self.client.post(self.url, self.data, follow=True) 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) diff --git a/digitalglarus/urls.py b/digitalglarus/urls.py index 51c397e0..da9f5926 100644 --- a/digitalglarus/urls.py +++ b/digitalglarus/urls.py @@ -10,8 +10,8 @@ urlpatterns = [ # url(_(r'about/?$'), AboutView.as_view(), name='about'), url(_(r'contact/?$'), ContactView.as_view(), name='contact'), url(_(r'supporters/?$'), views.supporters, name='supporters'), - url(r'calendar_api/(?P\d+)/(?P\d+)?$', views.CalendarApi.as_view()), - url(r'calendar_api/', views.CalendarApi.as_view()), + url(r'calendar_api/(?P\d+)/(?P\d+)?$', views.CalendarApi.as_view(),name='calendar_api_1'), + url(r'calendar_api/', views.CalendarApi.as_view(),name='calendar_api'), url(_(r'support-us/?$'), views.support, name='support'), url(r'^blog/(?P\w[-\w]*)/$', views.blog_detail, name='blog-detail'), url(r'blog/$', views.blog, name='blog'), diff --git a/dynamicweb/settings-test/__init__.py b/dynamicweb/settings-test/__init__.py index 752b949e..22ef8531 100644 --- a/dynamicweb/settings-test/__init__.py +++ b/dynamicweb/settings-test/__init__.py @@ -175,13 +175,8 @@ USE_L10N = True USE_TZ = True LANGUAGES = ( -<<<<<<< HEAD:dynamicweb/settings-test/__init__.py - ('en-us', _('English')), - ('de', _('Deutsch')), -======= ('en-us', _('US English')), ('de', _('German')), ->>>>>>> remotes/origin/feature/digital.glarus.german:dynamicweb/settings.py ) LANGUAGE_CODE = 'en-us' diff --git a/membership/migrations/0005_customuser_is_admin.py b/membership/migrations/0005_customuser_is_admin.py new file mode 100644 index 00000000..09bd5414 --- /dev/null +++ b/membership/migrations/0005_customuser_is_admin.py @@ -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'), + ), + ] diff --git a/membership/models.py b/membership/models.py index 3632e56a..a494fdec 100644 --- a/membership/models.py +++ b/membership/models.py @@ -29,6 +29,7 @@ class MyUserManager(BaseUserManager): name=name, validation_slug=make_password(None) ) + user.is_admin = False user.set_password(password) user.save(using=self._db) return user @@ -54,7 +55,7 @@ class CustomUser(AbstractBaseUser): validated = models.IntegerField(choices=VALIDATED_CHOICES, default=0) validation_slug = models.CharField(db_index=True, unique=True, max_length=50) - is_staff = models.BooleanField( + is_admin = models.BooleanField( _('staff status'), default=False, help_text=_('Designates whether the user can log into this admin site.'), @@ -92,9 +93,6 @@ class CustomUser(AbstractBaseUser): def is_superuser(self): return False - def is_admin(self): - return True - def get_full_name(self): # The user is identified by their email address return self.email @@ -109,12 +107,12 @@ class CustomUser(AbstractBaseUser): def has_perm(self, perm, obj=None): "Does the user have a specific permission?" # Simplest possible answer: Yes, always - return True + return self.is_admin def has_module_perms(self, app_label): "Does the user have permissions to view the app `app_label`?" # Simplest possible answer: Yes, always - return True + return self.is_admin @property def is_staff(self): @@ -137,8 +135,8 @@ class StripeCustomer(models.Model): try: stripe_utils = StripeUtils() stripe_customer = cls.objects.get(user__email=email) - #check if user is not in stripe but in database - stripe_utils.check_customer(stripe_customer.stripe_id,stripe_customer.user,token) + # check if user is not in stripe but in database + stripe_utils.check_customer(stripe_customer.stripe_id, stripe_customer.user, token) return stripe_customer except StripeCustomer.DoesNotExist: diff --git a/membership/tests.py b/membership/tests.py index f50049ee..42fd3ebe 100644 --- a/membership/tests.py +++ b/membership/tests.py @@ -1,13 +1,31 @@ -import unittest -from django.test import TestCase,Client +import re -# Create your tests here. -class LoginTestCase(unittest.TestCase): +from django.test import TestCase +from django.core.urlresolvers import reverse +from django.core import mail + + +class LoginTestCase(TestCase): def test_login(self): - client = Client() - response = client.get("/login") - - - + url = reverse('login_glarus') + 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) diff --git a/ungleich_page/templates/ungleich_page/includes/_contact_us.html b/ungleich_page/templates/ungleich_page/includes/_contact_us.html index b2c19f62..a791d053 100644 --- a/ungleich_page/templates/ungleich_page/includes/_contact_us.html +++ b/ungleich_page/templates/ungleich_page/includes/_contact_us.html @@ -1,4 +1,4 @@ -{% load static meta%} +{% load static meta cms_tags%} {% load i18n %}
@@ -13,7 +13,7 @@ {% endfor %}

{% trans "Contact Us" %}


-

{% trans "Join us at" %} {% trans "Digital Glarus" %}, +

{% trans "Join us at" %} {% trans "Digital Glarus" %}, {% trans "a great co-working space in the middle of Alps!" %}

{% trans "You can contact us at" %}

info@ungleich.ch

(044) 534-66-22