From e7230b7391c180b7e5ba6d308a87d6e5060fdcd7 Mon Sep 17 00:00:00 2001 From: Oskar Hahn Date: Thu, 22 Jan 2015 18:29:12 +0100 Subject: [PATCH] New Test order. * seperate unittests and integration tests * moved old tests in seperat folder 'old' * created a testrunner that does not create a testdatabase, if only unittests are run * wrote some unit- and integration tests as examples * fixed user.get_short_name() to use the sort order from config * fixed wrong url_pattern in the user app --- .travis.yml | 10 +- make/commands.py | 29 +- openslides/agenda/templates/agenda/view.html | 2 +- .../assignment/assignment_detail.html | 2 +- openslides/global_settings.py | 2 + openslides/users/api.py | 5 +- openslides/users/models.py | 32 +- .../users/templates/users/user_detail.html | 3 +- .../users/templates/users/user_list.html | 10 +- openslides/users/urls.py | 8 +- openslides/users/views.py | 2 +- openslides/utils/test.py | 23 ++ openslides/utils/utils.py | 37 +- openslides/utils/views.py | 21 +- tests/{account => integration}/__init__.py | 0 .../{agenda => integration/users}/__init__.py | 0 tests/integration/users/test_views.py | 14 + tests/{assignment => old}/__init__.py | 0 tests/{config => old/account}/__init__.py | 0 tests/{ => old}/account/test_widgets.py | 0 tests/{core => old/agenda}/__init__.py | 0 tests/{ => old}/agenda/models.py | 0 .../{ => old}/agenda/test_list_of_speakers.py | 0 tests/{ => old}/agenda/tests.py | 0 tests/{forms => old/assignment}/__init__.py | 0 tests/{ => old}/assignment/test_models.py | 0 tests/{ => old}/assignment/test_pdf.py | 0 tests/{ => old}/assignment/test_views.py | 0 tests/{mediafile => old/config}/__init__.py | 0 tests/{ => old}/config/test_config.py | 0 tests/{motion => old/core}/__init__.py | 0 tests/{ => old}/core/models.py | 0 .../core/test_template_tags_filters.py | 0 tests/{ => old}/core/test_views.py | 0 tests/{plugin_api => old/forms}/__init__.py | 0 tests/{ => old}/forms/test_clean_html.py | 0 .../mediafile}/__init__.py | 0 tests/{ => old}/mediafile/tests.py | 0 tests/{projector => old/motion}/__init__.py | 0 tests/{ => old}/motion/test_csv_import.py | 6 +- tests/{ => old}/motion/test_models.py | 0 tests/{ => old}/motion/test_pdf.py | 0 tests/{ => old}/motion/test_views.py | 0 tests/{users => old/plugin_api}/__init__.py | 0 tests/{ => old}/plugin_api/test_plugin_api.py | 6 +- .../plugin_api/test_plugin_one/__init__.py | 0 .../plugin_api/test_plugin_two}/__init__.py | 0 tests/old/projector/__init__.py | 0 tests/{ => old}/projector/test_api.py | 0 tests/{ => old}/projector/test_overlays.py | 0 tests/{ => old}/projector/test_signals.py | 0 tests/{ => old}/projector/test_views.py | 0 tests/old/settings.py | 56 +++ tests/{ => old}/test_init.py | 0 tests/old/users/__init__.py | 0 tests/{ => old}/users/test_csv.py | 0 tests/{ => old}/users/test_umlaut_user.py | 0 tests/{ => old}/users/test_views.py | 6 +- tests/old/utils/__init__.py | 0 tests/{ => old}/utils/test_dispatch.py | 4 +- tests/{ => old}/utils/test_forms.py | 0 tests/{ => old}/utils/test_main.py | 0 tests/{ => old}/utils/test_main_menu.py | 0 tests/{ => old}/utils/test_personal_info.py | 0 tests/{ => old}/utils/test_widgets.py | 0 tests/settings.py | 13 +- tests/unit/__init__.py | 0 tests/unit/users/__init__.py | 0 tests/unit/users/test_api.py | 184 ++++++++++ tests/unit/users/test_auth.py | 140 ++++++++ tests/unit/users/test_models.py | 312 +++++++++++++++++ tests/unit/utils/__init__.py | 0 tests/unit/utils/test_models.py | 16 + tests/{ => unit}/utils/test_utils.py | 5 +- tests/unit/utils/test_views.py | 318 ++++++++++++++++++ tests/users/test_models.py | 65 ---- tests/users/test_utils.py | 26 -- .../templates/utils/dummymodel_detail.html | 5 - tests/utils/test_models.py | 26 -- tests/utils/test_views.py | 217 ------------ tests/utils/urls.py | 29 -- tests/utils/views.py | 47 --- 82 files changed, 1172 insertions(+), 509 deletions(-) rename tests/{account => integration}/__init__.py (100%) rename tests/{agenda => integration/users}/__init__.py (100%) create mode 100644 tests/integration/users/test_views.py rename tests/{assignment => old}/__init__.py (100%) rename tests/{config => old/account}/__init__.py (100%) rename tests/{ => old}/account/test_widgets.py (100%) rename tests/{core => old/agenda}/__init__.py (100%) rename tests/{ => old}/agenda/models.py (100%) rename tests/{ => old}/agenda/test_list_of_speakers.py (100%) rename tests/{ => old}/agenda/tests.py (100%) rename tests/{forms => old/assignment}/__init__.py (100%) rename tests/{ => old}/assignment/test_models.py (100%) rename tests/{ => old}/assignment/test_pdf.py (100%) rename tests/{ => old}/assignment/test_views.py (100%) rename tests/{mediafile => old/config}/__init__.py (100%) rename tests/{ => old}/config/test_config.py (100%) rename tests/{motion => old/core}/__init__.py (100%) rename tests/{ => old}/core/models.py (100%) rename tests/{ => old}/core/test_template_tags_filters.py (100%) rename tests/{ => old}/core/test_views.py (100%) rename tests/{plugin_api => old/forms}/__init__.py (100%) rename tests/{ => old}/forms/test_clean_html.py (100%) rename tests/{plugin_api/test_plugin_two => old/mediafile}/__init__.py (100%) rename tests/{ => old}/mediafile/tests.py (100%) rename tests/{projector => old/motion}/__init__.py (100%) rename tests/{ => old}/motion/test_csv_import.py (94%) rename tests/{ => old}/motion/test_models.py (100%) rename tests/{ => old}/motion/test_pdf.py (100%) rename tests/{ => old}/motion/test_views.py (100%) rename tests/{users => old/plugin_api}/__init__.py (100%) rename tests/{ => old}/plugin_api/test_plugin_api.py (83%) rename tests/{ => old}/plugin_api/test_plugin_one/__init__.py (100%) rename tests/{utils => old/plugin_api/test_plugin_two}/__init__.py (100%) create mode 100644 tests/old/projector/__init__.py rename tests/{ => old}/projector/test_api.py (100%) rename tests/{ => old}/projector/test_overlays.py (100%) rename tests/{ => old}/projector/test_signals.py (100%) rename tests/{ => old}/projector/test_views.py (100%) create mode 100644 tests/old/settings.py rename tests/{ => old}/test_init.py (100%) create mode 100644 tests/old/users/__init__.py rename tests/{ => old}/users/test_csv.py (100%) rename tests/{ => old}/users/test_umlaut_user.py (100%) rename tests/{ => old}/users/test_views.py (97%) create mode 100644 tests/old/utils/__init__.py rename tests/{ => old}/utils/test_dispatch.py (94%) rename tests/{ => old}/utils/test_forms.py (100%) rename tests/{ => old}/utils/test_main.py (100%) rename tests/{ => old}/utils/test_main_menu.py (100%) rename tests/{ => old}/utils/test_personal_info.py (100%) rename tests/{ => old}/utils/test_widgets.py (100%) create mode 100644 tests/unit/__init__.py create mode 100644 tests/unit/users/__init__.py create mode 100644 tests/unit/users/test_api.py create mode 100644 tests/unit/users/test_auth.py create mode 100644 tests/unit/users/test_models.py create mode 100644 tests/unit/utils/__init__.py create mode 100644 tests/unit/utils/test_models.py rename tests/{ => unit}/utils/test_utils.py (84%) create mode 100644 tests/unit/utils/test_views.py delete mode 100644 tests/users/test_models.py delete mode 100644 tests/users/test_utils.py delete mode 100644 tests/utils/templates/utils/dummymodel_detail.html delete mode 100644 tests/utils/test_models.py delete mode 100644 tests/utils/test_views.py delete mode 100644 tests/utils/urls.py delete mode 100644 tests/utils/views.py diff --git a/.travis.yml b/.travis.yml index 54b756b6d..54eef0c44 100644 --- a/.travis.yml +++ b/.travis.yml @@ -8,6 +8,12 @@ install: - "node_modules/.bin/bower install" - "node_modules/.bin/gulp --production" script: - - "DJANGO_SETTINGS_MODULE='tests.settings' coverage run ./manage.py test" - - "coverage report -m --fail-under=80" - "flake8 --max-line-length=150 --statistics openslides tests" + + - "DJANGO_SETTINGS_MODULE='tests.settings' coverage run ./manage.py test tests.unit" + - "coverage report --show-missing --fail-under=35" + + - "DJANGO_SETTINGS_MODULE='tests.settings' coverage run ./manage.py test tests.integration" + - "coverage report --show-missing --fail-under=45" + + - "DJANGO_SETTINGS_MODULE='tests.old.settings' ./manage.py test tests.old" diff --git a/make/commands.py b/make/commands.py index 01772ecfa..2676a6ff8 100644 --- a/make/commands.py +++ b/make/commands.py @@ -2,6 +2,10 @@ import re from parser import command, argument, call +FAIL = '\033[91m' +SUCCESS = '\033[92m' +RESET = '\033[0m' + @argument('module', nargs='?', default='') @command('test', help='runs the tests') @@ -10,8 +14,8 @@ def test(args=None): Runs the tests. """ module = getattr(args, 'module', '') - return call("DJANGO_SETTINGS_MODULE='tests.settings' coverage run " - "./manage.py test %s" % module) + return call("DJANGO_SETTINGS_MODULE='tests.integration.settings' coverage run " + "./manage.py test tests.%s" % module) @argument('--plain', action='store_true') @@ -51,11 +55,17 @@ def travis(args=None): if line == 'script:': script_lines = True continue - if not script_lines: + if not script_lines or not line: continue match = re.search(r'"(.*)"', line) - return_codes.append(call(match.group(1))) + print('Run: %s' % match.group(1)) + return_code = call(match.group(1)) + return_codes.append(return_code) + if return_code: + print(FAIL + 'fail!\n' + RESET) + else: + print(SUCCESS + 'success!\n' + RESET) # Retuns True if one command exited with a different statuscode then 1 return bool(list(filter(bool, return_codes))) @@ -81,3 +91,14 @@ def min_requirements(args=None): yield '%s==%s' % (line.req.key, line.req.specs[0][1]) print('pip install %s' % ' '.join(get_lowest_versions(args.requirements))) + + +@command('clear', + help='Deletes unneeded files and folders') +def clear(args=None): + """ + Deletes all .pyc and .orig files and empty folders. + """ + call('find -name "*.pyc" -delete') + call('find -name "*.orig" -delete') + call('find -type d -empty -delete') diff --git a/openslides/agenda/templates/agenda/view.html b/openslides/agenda/templates/agenda/view.html index 800f17825..d41c66ce2 100644 --- a/openslides/agenda/templates/agenda/view.html +++ b/openslides/agenda/templates/agenda/view.html @@ -159,7 +159,7 @@ {{ field }} {% if perms.users.can_see and perms.users.can_manage %} - + {% endif %} {% if field.errors %} {{ field.errors }} diff --git a/openslides/assignment/templates/assignment/assignment_detail.html b/openslides/assignment/templates/assignment/assignment_detail.html index e1a251461..51fff465e 100644 --- a/openslides/assignment/templates/assignment/assignment_detail.html +++ b/openslides/assignment/templates/assignment/assignment_detail.html @@ -149,7 +149,7 @@ {% if perms.users.can_see and perms.users.can_manage %} - diff --git a/openslides/global_settings.py b/openslides/global_settings.py index 39b22fc20..50a8f229a 100644 --- a/openslides/global_settings.py +++ b/openslides/global_settings.py @@ -173,3 +173,5 @@ CKEDITOR_CONFIGS = { # Use small alternative with tornado as frontend or big alternative with a # webserver as wsgi server. USE_TORNADO_AS_WSGI_SERVER = True + +TEST_RUNNER = 'openslides.utils.test.OpenSlidesDiscoverRunner' diff --git a/openslides/users/api.py b/openslides/users/api.py index 21b0ca0c4..ac299b692 100644 --- a/openslides/users/api.py +++ b/openslides/users/api.py @@ -162,6 +162,5 @@ def get_protected_perm(): Returns the permission to manage users. This function is a helper function used to protect manager users from locking out themselves. """ - return Permission.objects.get( - content_type=ContentType.objects.get(app_label='users', model='user'), - codename='can_manage') + return Permission.objects.get_by_natural_key( + app_label='users', model='user', codename='can_manage') diff --git a/openslides/users/models.py b/openslides/users/models.py index 295f5fa9f..fd4c01c81 100644 --- a/openslides/users/models.py +++ b/openslides/users/models.py @@ -9,12 +9,17 @@ from django.core.urlresolvers import reverse from django.db import models from django.utils.translation import ugettext_lazy, ugettext_noop +from openslides.config.api import config from openslides.projector.models import SlideMixin from openslides.utils.models import AbsoluteUrlMixin from openslides.utils.rest_api import RESTModelMixin class UserManager(BaseUserManager): + """ + UserManager that creates new users only with a password and a username. + """ + def create_user(self, username, password, **kwargs): user = self.model(username=username, **kwargs) user.set_password(password) @@ -87,9 +92,9 @@ class User(RESTModelMixin, SlideMixin, AbsoluteUrlMixin, PermissionsMixin, Abstr Returns the URL to the user. """ if link == 'detail': - url = reverse('user_view', args=[str(self.pk)]) + url = reverse('user_detail', args=[str(self.pk)]) elif link == 'update': - url = reverse('user_edit', args=[str(self.pk)]) + url = reverse('user_update', args=[str(self.pk)]) elif link == 'delete': url = reverse('user_delete', args=[str(self.pk)]) else: @@ -111,10 +116,7 @@ class User(RESTModelMixin, SlideMixin, AbsoluteUrlMixin, PermissionsMixin, Abstr E. g.: * Dr. Max Mustermann (Villingen) * Professor Dr. Enders, Christoph (Leipzig) """ - if self.structure_level: - structure = '(%s)' % self.structure_level - else: - structure = '' + structure = '(%s)' % self.structure_level if self.structure_level else '' return ' '.join((self.title, self.get_short_name(), structure)).strip() @@ -125,9 +127,21 @@ class User(RESTModelMixin, SlideMixin, AbsoluteUrlMixin, PermissionsMixin, Abstr E. g.: * Max Mustermann * Enders, Christoph """ - # TODO: Order of name. See config. - name = ('%s %s' % (self.first_name, self.last_name)).strip() - return name or self.username + # Strip white spaces from the name parts + first_name = self.first_name.strip() + last_name = self.last_name.strip() + + # The user has a last_name and a first_name + if first_name and last_name: + if config['users_sort_users_by_first_name']: + name = ' '.join((first_name, last_name)) + else: + name = ', '.join((last_name, first_name)) + + # The user has only a first_name or a last_name or no name + else: + name = first_name or last_name or self.username + return name def reset_password(self, password=None): """ diff --git a/openslides/users/templates/users/user_detail.html b/openslides/users/templates/users/user_detail.html index f1f38a33b..985862df5 100644 --- a/openslides/users/templates/users/user_detail.html +++ b/openslides/users/templates/users/user_detail.html @@ -1,6 +1,7 @@ {% extends "base.html" %} {% load i18n %} +{% load tags %} {% block title %}{{ shown_user }} – {{ block.super }}{% endblock %} @@ -29,7 +30,7 @@