From 1cf6052a31657ffabe6d8a8fb3681bef4a8c3bbe Mon Sep 17 00:00:00 2001 From: Mateusz Sikora Date: Mon, 5 May 2014 17:57:47 +0200 Subject: [PATCH] move definition of registration view and user profile model to runtest script --- rest_auth/runtests.py | 42 ++++++++++++++++++++++++++++++++++++++++++ rest_auth/tests.py | 38 -------------------------------------- 2 files changed, 42 insertions(+), 38 deletions(-) diff --git a/rest_auth/runtests.py b/rest_auth/runtests.py index 88a0126..cec36c6 100644 --- a/rest_auth/runtests.py +++ b/rest_auth/runtests.py @@ -6,6 +6,48 @@ sys.path.insert(0, test_dir) from django.test.utils import get_runner from django.conf import settings +from django.contrib.auth.models import User +from django.contrib.sites.models import RequestSite +from django.contrib.sites.models import Site +from django.db import models + +from registration.models import RegistrationProfile +from registration.backends.default.views import RegistrationView as BaseRegistrationView +from registration import signals + +""" +create user profile model +""" +class UserProfile(models.Model): + user = models.ForeignKey(User, unique=True) + newsletter_subscribe = models.BooleanField(default=False) + + class Meta: + app_label = 'rest_auth' + +settings.REST_PROFILE_MODULE = UserProfile + + +""" +overwrite register to avoid sending email +""" +class RegistrationView(BaseRegistrationView): + def register(self, request, **cleaned_data): + username, email, password = cleaned_data['username'], cleaned_data['email'], cleaned_data['password1'] + if Site._meta.installed: + site = Site.objects.get_current() + else: + site = RequestSite(request) + new_user = RegistrationProfile.objects.create_inactive_user(username, email, + password, site, send_email=False) + signals.user_registered.send(sender=self.__class__, + user=new_user, + request=request) + return new_user + +settings.REST_REGISTRATION_BACKEND = 'rest_auth.runtests.RegistrationView' + + def runtests(): TestRunner = get_runner(settings) diff --git a/rest_auth/tests.py b/rest_auth/tests.py index e2d2c3c..26e11cf 100644 --- a/rest_auth/tests.py +++ b/rest_auth/tests.py @@ -13,49 +13,11 @@ from django.test.client import Client, MULTIPART_CONTENT from django.test import TestCase from django.contrib.auth.models import User from django.contrib.auth import get_user_model -from django.contrib.sites.models import RequestSite -from django.contrib.sites.models import Site -from django.db import models from registration.models import RegistrationProfile -from registration.backends.default.views import RegistrationView as BaseRegistrationView -from registration import signals from rest_framework.serializers import _resolve_model -""" -create user profile model -""" -class UserProfile(models.Model): - user = models.ForeignKey(User, unique=True) - newsletter_subscribe = models.BooleanField(default=False) - - class Meta: - app_label = 'rest_auth' - -settings.REST_PROFILE_MODULE = UserProfile - - -""" -overwrite register to avoid sending email -""" -class RegistrationView(BaseRegistrationView): - def register(self, request, **cleaned_data): - username, email, password = cleaned_data['username'], cleaned_data['email'], cleaned_data['password1'] - if Site._meta.installed: - site = Site.objects.get_current() - else: - site = RequestSite(request) - new_user = RegistrationProfile.objects.create_inactive_user(username, email, - password, site, send_email=False) - signals.user_registered.send(sender=self.__class__, - user=new_user, - request=request) - return new_user - -settings.REST_REGISTRATION_BACKEND = 'rest_auth.tests.RegistrationView' - - class APIClient(Client): def patch(self, path, data='', content_type=MULTIPART_CONTENT, follow=False, **extra):