added test
This commit is contained in:
parent
45730e4eb1
commit
3b387d61db
7 changed files with 86 additions and 27 deletions
20
membership/migrations/0005_customuser_is_admin.py
Normal file
20
membership/migrations/0005_customuser_is_admin.py
Normal 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'),
|
||||
),
|
||||
]
|
||||
|
|
@ -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:
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue