Commit c9f9ff41 authored by Timothée Mazzucotelli's avatar Timothée Mazzucotelli

Merge branch '4-fix-check-test-environments' into 'master'

Resolve "Fix check test environments" (#4)

See merge request !4
parents 2522c504 354fb801
Pipeline #1587 passed with stages
in 8 minutes
......@@ -61,15 +61,22 @@ py37-django20:
script: tox -e py37-dev-django20
setup:
image: python:3.5
stage: lint
before_script:
- pip install tox
script: tox -e setup
safety:
image: python:3.5
stage: lint
before_script:
- pip install tox
script: tox -e safety
allow_failure: true
style:
image: python:3.5
stage: lint
before_script:
- pip install tox
......@@ -77,6 +84,7 @@ style:
allow_failure: true
docs:
image: python:3.5
stage: lint
before_script:
- pip install tox
......@@ -84,8 +92,6 @@ docs:
allow_failure: true
build:
image: docker:latest
services:
......
......@@ -13,10 +13,11 @@ include README.rst
include tox.ini
include *.yml
include requirements.txt
include .gitlab-ci.yml
include .prospector.yml
include runtests.py
recursive-include requirements *.txt
recursive-include scripts *.sh
global-exclude *.py[cod] __pycache__ *.so *.dylib
sphinx
sphinx-rtd-theme
Django
-r ../requirements.txt
sphinx==1.6.5
sphinx-rtd-theme==0.2.5b1
-e .
django-app-settings==0.2.5
django-cerberus-ac==0.2.1
-r base.txt
pytest
pytest-cov
django-fake-model
......@@ -64,7 +64,7 @@ setup(
'Topic :: Utilities',
],
keywords=[
'django-hope',
'django', 'hope', 'health', 'optimization', '4P', 'ecosystems'
],
install_requires=[
'django-cerberus-ac'
......
# -*- coding: utf-8 -*-
"""Django HOPE package."""
"""Forms module."""
from django import forms
from django.contrib.auth.forms import UserCreationForm
......@@ -5,8 +7,12 @@ from .models import User
class SignUpForm(UserCreationForm):
"""Simple sign-up form overriding the basic Django user creation form."""
email = forms.EmailField(label='Email', max_length=254)
class Meta:
"""Django meta-class."""
model = User
fields = ('username', 'email', 'password1', 'password2', )
from django.db import models
"""Models module."""
from django.contrib.auth.models import AbstractUser
from django.db import models
from cerberus_ac.models import RoleMixin
class User(AbstractUser, RoleMixin):
"""Simple User model derived from Django's abstract user."""
email_confirmed = models.BooleanField(default=False)
"""Tokens module."""
from django.contrib.auth.tokens import PasswordResetTokenGenerator
from django.utils import six
class AccountActivationTokenGenerator(PasswordResetTokenGenerator):
"""Class to generate account activation tokens."""
def _make_hash_value(self, user, timestamp):
return (
six.text_type(user.pk) + six.text_type(timestamp) +
......
"""URLs module."""
from django.conf.urls import url
from django.contrib.auth import views as auth_views
from django.views.generic import TemplateView
from . import views
......@@ -10,7 +13,8 @@ urlpatterns = [
url(r'^signout/$', auth_views.logout,
{'template_name': 'hope/signout.html'}, name='signout'),
url(r'^account_activation_sent/$',
views.account_activation_sent, name='account_activation_sent'),
TemplateView.as_view(template_name='hope/account_activation_sent.html'), # noqa
name='account_activation_sent'),
url(r'^activate/'
r'(?P<uidb64>[0-9A-Za-z_\-]+)/'
r'(?P<token>[0-9A-Za-z]{1,13}-[0-9A-Za-z]{1,20})/$',
......
"""Views module."""
from django.contrib.auth import login
from django.contrib.sites.shortcuts import get_current_site
from django.shortcuts import render, redirect
from django.shortcuts import redirect, render
from django.template.loader import render_to_string
from django.utils.encoding import force_bytes, force_text
from django.utils.http import urlsafe_base64_encode, urlsafe_base64_decode
from django.utils.http import urlsafe_base64_decode, urlsafe_base64_encode
from .forms import SignUpForm
from .models import User
......@@ -11,6 +13,7 @@ from .tokens import account_activation_token
def signup(request):
"""Sign-up view sending a mail to validation the account."""
if request.method == 'POST':
form = SignUpForm(request.POST)
if form.is_valid():
......@@ -19,7 +22,7 @@ def signup(request):
user.save()
current_site = get_current_site(request)
subject = 'Activate Your MySite Account'
message = render_to_string('account_activation_email.html', {
message = render_to_string('hope/account_activation_email.html', {
'user': user,
'domain': current_site.domain,
'uid': urlsafe_base64_encode(force_bytes(user.pk)),
......@@ -29,10 +32,11 @@ def signup(request):
return redirect('account_activation_sent')
else:
form = SignUpForm()
return render(request, '{{cookiecutter.package_name}}/signup.html', {'form': form})
return render(request, 'hope/signup.html', {'form': form})
def activate(request, uidb64, token):
"""Activate the account based on a token."""
try:
uid = force_text(urlsafe_base64_decode(uidb64))
user = User.objects.get(pk=uid)
......@@ -44,11 +48,6 @@ def activate(request, uidb64, token):
user.email_confirmed = True
user.save()
login(request, user)
# TODO: add a message with django message app
return redirect('home')
else:
return render(request, 'account_activation_invalid.html')
return render(request, 'hope/account_activated.html')
def account_activation_sent(request):
return render(request, 'account_activation_sent.html')
return render(request, 'hope/account_activation_invalid.html')
......@@ -22,7 +22,9 @@ commands = {posargs:pytest --cov --cov-report=term-missing -vv runtests.py tests
deps =
django111: Django>=1.11,<1.12
django20: Django>=2.0,<2.1
-r{toxinidir}/requirements/test.txt
pytest
pytest-cov
django-fake-model
passenv = *
usedevelop = false
whitelist_externals = tox
......@@ -79,12 +81,13 @@ deps =
bandit
safety
commands =
safety check -r {toxinidir}/requirements/base.txt
safety check -r {toxinidir}/requirements.txt
bandit -r {toxinidir}/src/hope
[testenv:style]
description = Check the code style.
deps =
-r{toxinidir}/requirements.txt
isort
prospector[with_everything]
commands =
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment