diff --git a/client/cypress/integration/login-page-spec.js b/client/cypress/integration/login-page-spec.js index 7435078d..71ad2001 100644 --- a/client/cypress/integration/login-page-spec.js +++ b/client/cypress/integration/login-page-spec.js @@ -43,52 +43,5 @@ describe('The Login Page', () => { cy.login(username, password); cy.get('body').contains('Berufliche Grundbildung'); }); - // it('logs in programmatically without using the UI', () => { - // cy.visit('/accounts/login/'); // have to get a csrf token by getting the base page first - // - // const username = 'test'; - // const password = 'test'; - // - // cy.getCookie('csrftoken').then(token => { - // const options = { - // url: '/accounts/login/', - // method: 'POST', - // headers: { - // 'X-CSRFToken': token.value, - // 'content-type': 'multipart/form-data' - // }, - // from: true, - // body: { - // username: username, - // password: password, - // // csrfmiddlewaretoken: token.value - // } - // }; - // - // cy.request(options); - // cy.getCookie('sessionid').should('exist'); - // cy.visit('/'); - // - // cy.get('.start-page__title').should('contain', 'skillbox') - // - // - // // cy.visit('/'); - // // cy.getCookie('csrftoken') - // // .then((csrftoken) => { - // // const response = cy.request({ - // // method: 'POST', - // // url: '/login/', - // // form: true, - // // body: { - // // identification: username, - // // password: password, - // // csrfmiddlewaretoken: csrftoken.value - // // } - // // }); - // // }); - // - // }); - - // }) }) diff --git a/client/cypress/integration/registration-page-spec.js b/client/cypress/integration/registration-page-spec.js new file mode 100644 index 00000000..fa81b961 --- /dev/null +++ b/client/cypress/integration/registration-page-spec.js @@ -0,0 +1,76 @@ +describe('The Regstration Page', () => { + it('register user', () => { + + let timestamp = Math.round((new Date()).getTime() / 1000); + + const firstname = 'pesche'; + const lastname = 'peschemann'; + const email = `skillboxtest${timestamp}@iterativ.ch`; + const licenseKey = 'c1fa2e2a-2e27-480d-8469-2e88414c4ad8'; + + cy.visit('/register'); + cy.register(firstname, lastname, email, licenseKey); + cy.get('.reset__heading').contains('Schauen Sie in Ihr Postfach'); + }); + + it('user sees error message if firstname is omitted', () => { + let timestamp = Math.round((new Date()).getTime() / 1000); + const firstname = ''; + const lastname = 'peschemann'; + const email = `skillboxtest${timestamp}@iterativ.ch`; + const licenseKey = 'c1fa2e2a-2e27-480d-8469-2e88414c4ad8'; + + cy.visit('/register'); + cy.register(firstname, lastname, email, licenseKey); + cy.get('[data-cy="firstname-local-errors"]').contains('Vorname ist ein Pflichtfeld.'); + }); + + it('user sees error message if lastname is omitted', () => { + let timestamp = Math.round((new Date()).getTime() / 1000); + const firstname = 'pesche'; + const lastname = ''; + const email = `skillboxtest${timestamp}@iterativ.ch`; + const licenseKey = 'c1fa2e2a-2e27-480d-8469-2e88414c4ad8'; + + cy.visit('/register'); + cy.register(firstname, lastname, email, licenseKey); + cy.get('[data-cy="lastname-local-errors"]').contains('Nachname ist ein Pflichtfeld.'); + }); + + it('user sees error message if email is omitted', () => { + let timestamp = Math.round((new Date()).getTime() / 1000); + const firstname = 'pesche'; + const lastname = 'peschemann'; + const email = ``; + const licenseKey = 'c1fa2e2a-2e27-480d-8469-2e88414c4ad8'; + + cy.visit('/register'); + cy.register(firstname, lastname, email, licenseKey); + cy.get('[data-cy="email-local-errors"]').contains('E-Mail ist ein Pflichtfeld.'); + }); + + it('user sees error message if license is omitted', () => { + let timestamp = Math.round((new Date()).getTime() / 1000); + const firstname = 'pesche'; + const lastname = 'peschemann'; + const email = `skillboxtest${timestamp}@iterativ.ch`; + const licenseKey = ''; + + cy.visit('/register'); + cy.register(firstname, lastname, email, licenseKey); + cy.get('[data-cy="licenseKey-local-errors"]').contains('Lizenz ist ein Pflichtfeld.'); + }); + + it('user sees error message if license key is wrong', () => { + let timestamp = Math.round((new Date()).getTime() / 1000); + const firstname = 'pesche'; + const lastname = 'peschemann'; + const email = `skillboxtest${timestamp}@iterativ.ch`; + const licenseKey = 'asdsafsadfsadfasdf'; + + cy.visit('/register'); + cy.register(firstname, lastname, email, licenseKey); + cy.get('[data-cy="licenseKey-remote-errors"]').contains('Die angegebenen Lizenz ist unglültig'); + }); + +}) diff --git a/client/cypress/support/commands.js b/client/cypress/support/commands.js index faaebc76..f76b462c 100644 --- a/client/cypress/support/commands.js +++ b/client/cypress/support/commands.js @@ -82,3 +82,23 @@ Cypress.Commands.add('changePassword', (oldPassword, newPassword) => { } cy.get('[data-cy=change-password-button]').click(); }); + +Cypress.Commands.add('register', (firstname, lastname, email, licenseKey) => { + if (firstname != '') { + cy.get('[data-cy=firstname-input]').type(firstname); + } + + if (lastname != '') { + cy.get('[data-cy=lastname-input]').type(lastname); + } + + if (email != '') { + cy.get('[data-cy=email-input]').type(email); + } + + if (licenseKey != '') { + cy.get('[data-cy=licenseKey-input]').type(licenseKey); + } + + cy.get('[data-cy=register-button]').click(); +}); diff --git a/client/src/pages/registration.vue b/client/src/pages/registration.vue index 6860a5a8..69a80778 100644 --- a/client/src/pages/registration.vue +++ b/client/src/pages/registration.vue @@ -110,7 +110,7 @@ {{registrationError}}
- +
@@ -149,7 +149,7 @@ export default { ) { try { if (success) { - that.$router.push('/set-password/done/'); + window.location.href = '/set-password/done/'; } else { errors.forEach(function(error) { switch (error.field) { diff --git a/server/core/management/commands/dummy_data.py b/server/core/management/commands/dummy_data.py index 8680d88f..27b9798a 100644 --- a/server/core/management/commands/dummy_data.py +++ b/server/core/management/commands/dummy_data.py @@ -9,7 +9,6 @@ from django.core.management import BaseCommand from django.db import connection from wagtail.core.models import Page -from assignments.factories import AssignmentFactory from books.factories import BookFactory, TopicFactory, ModuleFactory, ChapterFactory, ContentBlockFactory from core.factories import UserFactory from objectives.factories import ObjectiveGroupFactory, ObjectiveFactory @@ -103,5 +102,10 @@ class Command(BaseCommand): # ContentBlockFactory.create(parent=chapter, **self.filter_data(content_block_data, 'contents')) ContentBlockFactory.create(parent=chapter, module=module, **content_block_data) + + # now create all and rooms management.call_command('dummy_rooms', verbosity=0) + + # create license + management.call_command('create_dummy_license', verbosity=0) diff --git a/server/core/tests/test_api.py b/server/core/tests/test_api.py index 643058d7..e5949e94 100644 --- a/server/core/tests/test_api.py +++ b/server/core/tests/test_api.py @@ -1,9 +1,6 @@ import json from django.test import TestCase, Client -from django.test.utils import override_settings - -from core import settings from core.factories import UserFactory diff --git a/server/registration/management/__init__.py b/server/registration/management/__init__.py new file mode 100644 index 00000000..7e9d57d8 --- /dev/null +++ b/server/registration/management/__init__.py @@ -0,0 +1,10 @@ +# -*- coding: utf-8 -*- +# +# ITerativ GmbH +# http://www.iterativ.ch/ +# +# Copyright (c) 2019 ITerativ GmbH. All rights reserved. +# +# Created on 2019-10-23 +# @author: chrigu +from django.conf import settings diff --git a/server/registration/management/commands/__init__.py b/server/registration/management/commands/__init__.py new file mode 100644 index 00000000..7e9d57d8 --- /dev/null +++ b/server/registration/management/commands/__init__.py @@ -0,0 +1,10 @@ +# -*- coding: utf-8 -*- +# +# ITerativ GmbH +# http://www.iterativ.ch/ +# +# Copyright (c) 2019 ITerativ GmbH. All rights reserved. +# +# Created on 2019-10-23 +# @author: chrigu +from django.conf import settings diff --git a/server/registration/management/commands/create_dummy_license.py b/server/registration/management/commands/create_dummy_license.py new file mode 100644 index 00000000..8ae4c88e --- /dev/null +++ b/server/registration/management/commands/create_dummy_license.py @@ -0,0 +1,30 @@ +# -*- coding: utf-8 -*- +# +# ITerativ GmbH +# http://www.iterativ.ch/ +# +# Copyright (c) 2019 ITerativ GmbH. All rights reserved. +# +# Created on 2019-10-23 +# @author: chrigu +from django.conf import settings +from django.core.management import BaseCommand + +from registration.models import LicenseType +from users.models import Role + + +class Command(BaseCommand): + + def handle(self, *args, **options): + + try: + role = Role.objects.get(key=Role.objects.TEACHER_KEY) + except Role.DoesNotExist: + print("LicenseType requires that a Teacher Role exsits") + + LicenseType.objects.create(name='dummy_license', + for_role=role, + active=True, + key='c1fa2e2a-2e27-480d-8469-2e88414c4ad8', + description='dummy license') diff --git a/server/registration/tests/test_registration.py b/server/registration/tests/test_registration.py index 0bc7aa63..c50c6c03 100644 --- a/server/registration/tests/test_registration.py +++ b/server/registration/tests/test_registration.py @@ -7,6 +7,7 @@ # # Created on 2019-10-08 # @author: chrigu +from django.core import mail from django.contrib.sessions.middleware import SessionMiddleware from django.test import TestCase, RequestFactory from graphene.test import Client @@ -82,6 +83,8 @@ class RegistrationTests(TestCase): self.assertEqual(len(school_classes), 1) user = User.objects.get(email=self.email) self.assertTrue(school_classes[0].is_user_in_schoolclass(user)) + self.assertEqual(len(mail.outbox), 1) + self.assertEqual(mail.outbox[0].subject, 'Myskillbox: E-Mail bestätigen und Passwort setzen') def test_user_can_register_as_student(self): self._assert_user_registration(0, self.email, RoleManager.STUDENT_KEY) diff --git a/server/users/models.py b/server/users/models.py index 805ccaa3..11ba360a 100644 --- a/server/users/models.py +++ b/server/users/models.py @@ -79,7 +79,7 @@ class SchoolClass(models.Model): prefix = 'Meine Gruppe' prefix_regex = r'Meine Gruppe (\d+)' initial_default_group = '{} 1'.format(prefix) - my_group_filter = cls.objects.filter(name__startswith=prefix).order_by('-name') + my_group_filter = cls.objects.filter(name__startswith=prefix).order_by('-pk') if len(my_group_filter) == 0: return initial_default_group diff --git a/server/users/mutations_public.py b/server/users/mutations_public.py index 85c5563f..cdf1e394 100644 --- a/server/users/mutations_public.py +++ b/server/users/mutations_public.py @@ -7,7 +7,6 @@ # # Created on 2019-10-01 # @author: chrigu -import re import graphene from django.contrib.auth import authenticate, login