From 02b1f3aa20530210a5b6a71e61c6c9bd03e1a720 Mon Sep 17 00:00:00 2001 From: Mateusz Sikora Date: Fri, 2 May 2014 23:47:28 +0200 Subject: [PATCH] make 'python setup.py test' working --- rest_auth/test_settings.py | 20 ++++------------ rest_auth/tests.py | 47 ++++++++++++++++++++++++++++++++++++-- rest_auth/urls.py | 2 +- setup.py | 2 +- 4 files changed, 52 insertions(+), 19 deletions(-) diff --git a/rest_auth/test_settings.py b/rest_auth/test_settings.py index 6578e55..99239af 100644 --- a/rest_auth/test_settings.py +++ b/rest_auth/test_settings.py @@ -2,7 +2,6 @@ import django import os, sys # PROJECT_ROOT = os.path.abspath(os.path.split(os.path.split(__file__)[0])[0]) -# sys.path.append(os.path.join(PROJECT_ROOT, 'django-rest-registration-auth/apps/')) # ROOT_URLCONF = 'urls' # STATIC_URL = '/static/' @@ -32,8 +31,12 @@ else: INSTALLED_APPS = [ 'django.contrib.admin', 'django.contrib.auth', + 'django.contrib.humanize', 'django.contrib.contenttypes', 'django.contrib.sessions', + 'django.contrib.sites', + 'django.contrib.sitemaps', + 'django.contrib.staticfiles', 'rest_framework', 'rest_framework.authtoken', @@ -43,18 +46,5 @@ INSTALLED_APPS = [ ] SECRET_KEY = "38dh*skf8sjfhs287dh&^hd8&3hdg*j2&sd" - - -from django.db import models -from django.contrib.auth.models import User - -class UserProfile(models.Model): - user = models.ForeignKey(User, unique=True) - newsletter_subscribe = models.BooleanField(default=False) - - class Meta: - app_label = 'rest_auth' - -REST_PROFILE_MODULE = UserProfile -REST_REGISTRATION_BACKEND = 'registration.backends.default.views.RegistrationView' ACCOUNT_ACTIVATION_DAYS = 1 +SITE_ID = 1 diff --git a/rest_auth/tests.py b/rest_auth/tests.py index e8ed8e5..e2d2c3c 100644 --- a/rest_auth/tests.py +++ b/rest_auth/tests.py @@ -1,18 +1,61 @@ import json import os +import sys from datetime import datetime, date, time +os.environ['DJANGO_SETTINGS_MODULE'] = 'test_settings' +test_dir = os.path.dirname(__file__) +sys.path.insert(0, test_dir) + from django.conf import settings +from django.core.urlresolvers import reverse from django.test.client import Client, MULTIPART_CONTENT from django.test import TestCase -from django.core.urlresolvers import reverse from django.contrib.auth.models import User -from registration.models import RegistrationProfile 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): diff --git a/rest_auth/urls.py b/rest_auth/urls.py index 4d36448..ca2cefe 100644 --- a/rest_auth/urls.py +++ b/rest_auth/urls.py @@ -1,7 +1,7 @@ from django.conf import settings from django.conf.urls import patterns, url, include -from .views import Login, Logout, Register, UserDetails, \ +from rest_auth.views import Login, Logout, Register, UserDetails, \ PasswordChange, PasswordReset, VerifyEmail, PasswordResetConfirm diff --git a/setup.py b/setup.py index 0bd1cc5..aaf3100 100644 --- a/setup.py +++ b/setup.py @@ -32,7 +32,7 @@ setup( 'django-registration>=1.0', 'djangorestframework>=2.3.13', ], - test_suite='rest_auth.tests', + test_suite='rest_auth.runtests.runtests', include_package_data=True, # cmdclass={}, classifiers=[