make 'python setup.py test' working

This commit is contained in:
Mateusz Sikora 2014-05-02 23:47:28 +02:00
parent 2faaa3d5c5
commit 02b1f3aa20
4 changed files with 52 additions and 19 deletions

View File

@ -2,7 +2,6 @@ import django
import os, sys import os, sys
# PROJECT_ROOT = os.path.abspath(os.path.split(os.path.split(__file__)[0])[0]) # 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' # ROOT_URLCONF = 'urls'
# STATIC_URL = '/static/' # STATIC_URL = '/static/'
@ -32,8 +31,12 @@ else:
INSTALLED_APPS = [ INSTALLED_APPS = [
'django.contrib.admin', 'django.contrib.admin',
'django.contrib.auth', 'django.contrib.auth',
'django.contrib.humanize',
'django.contrib.contenttypes', 'django.contrib.contenttypes',
'django.contrib.sessions', 'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.sitemaps',
'django.contrib.staticfiles',
'rest_framework', 'rest_framework',
'rest_framework.authtoken', 'rest_framework.authtoken',
@ -43,18 +46,5 @@ INSTALLED_APPS = [
] ]
SECRET_KEY = "38dh*skf8sjfhs287dh&^hd8&3hdg*j2&sd" 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 ACCOUNT_ACTIVATION_DAYS = 1
SITE_ID = 1

View File

@ -1,18 +1,61 @@
import json import json
import os import os
import sys
from datetime import datetime, date, time 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.conf import settings
from django.core.urlresolvers import reverse
from django.test.client import Client, MULTIPART_CONTENT from django.test.client import Client, MULTIPART_CONTENT
from django.test import TestCase from django.test import TestCase
from django.core.urlresolvers import reverse
from django.contrib.auth.models import User from django.contrib.auth.models import User
from registration.models import RegistrationProfile
from django.contrib.auth import get_user_model 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 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): class APIClient(Client):
def patch(self, path, data='', content_type=MULTIPART_CONTENT, follow=False, **extra): def patch(self, path, data='', content_type=MULTIPART_CONTENT, follow=False, **extra):

View File

@ -1,7 +1,7 @@
from django.conf import settings from django.conf import settings
from django.conf.urls import patterns, url, include 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 PasswordChange, PasswordReset, VerifyEmail, PasswordResetConfirm

View File

@ -32,7 +32,7 @@ setup(
'django-registration>=1.0', 'django-registration>=1.0',
'djangorestframework>=2.3.13', 'djangorestframework>=2.3.13',
], ],
test_suite='rest_auth.tests', test_suite='rest_auth.runtests.runtests',
include_package_data=True, include_package_data=True,
# cmdclass={}, # cmdclass={},
classifiers=[ classifiers=[