PEP8 and code style cleanups.

This commit is contained in:
Roberto Rosario
2016-06-30 21:30:01 -04:00
parent aa56e8ae14
commit b6161e9d92
36 changed files with 38 additions and 84 deletions

View File

@@ -2,7 +2,7 @@ from __future__ import absolute_import, unicode_literals
from django.contrib.auth import get_user_model from django.contrib.auth import get_user_model
from django.core.exceptions import PermissionDenied from django.core.exceptions import PermissionDenied
from django.test import TestCase, override_settings from django.test import override_settings
from documents.models import Document, DocumentType from documents.models import Document, DocumentType
from documents.permissions import permission_document_view from documents.permissions import permission_document_view

View File

@@ -1,6 +1,5 @@
from __future__ import unicode_literals from __future__ import unicode_literals
from django.conf import settings
from django.contrib.auth import get_user_model from django.contrib.auth import get_user_model
from django.contrib.auth.backends import ModelBackend from django.contrib.auth.backends import ModelBackend

View File

@@ -3,7 +3,7 @@ from __future__ import absolute_import, unicode_literals
from django.conf import settings from django.conf import settings
from django.contrib.auth import get_user_model from django.contrib.auth import get_user_model
from django.core.urlresolvers import reverse from django.core.urlresolvers import reverse
from django.test import TestCase, override_settings from django.test import override_settings
from django.test.client import Client from django.test.client import Client
from organizations.tests.base import OrganizationTestCase from organizations.tests.base import OrganizationTestCase

View File

@@ -4,7 +4,7 @@ import datetime
import time import time
from django.contrib.auth import get_user_model from django.contrib.auth import get_user_model
from django.test import TestCase, override_settings from django.test import override_settings
from django.utils.timezone import now from django.utils.timezone import now
from documents.exceptions import NewDocumentVersionNotAllowed from documents.exceptions import NewDocumentVersionNotAllowed

View File

@@ -12,9 +12,15 @@ class Command(management.BaseCommand):
def handle(self, *args, **options): def handle(self, *args, **options):
management.call_command('createsettings', interactive=False) management.call_command('createsettings', interactive=False)
try: try:
result = management.call_command('migrate', interactive=False) management.call_command('migrate', interactive=False)
except OperationalError as exception: except OperationalError:
self.stderr.write(self.style.NOTICE('Unable to migrate the database. The initialsetup command is to be used only on new installations. To upgrade existing installations use the performupgrade command.')) self.stderr.write(
self.style.NOTICE(
'Unable to migrate the database. The initialsetup command '
'is to be used only on new installations. To upgrade '
'existing installations use the performupgrade command.'
)
)
raise raise
management.call_command('createautoadmin', interactive=False) management.call_command('createautoadmin', interactive=False)
management.call_command('createorganizationadmin', interactive=False) management.call_command('createorganizationadmin', interactive=False)

View File

@@ -1,5 +1,5 @@
def skip_file_descriptor_check(func): def skip_file_descriptor_check(func):
def func_wrapper(item): def func_wrapper(item):
item._skip_file_descriptor_test = True item._skip_file_descriptor_test = True
return func(item) return func(item)
return func_wrapper return func_wrapper

View File

@@ -5,7 +5,6 @@ from django.contrib.auth import get_user_model
from django.core.urlresolvers import clear_url_caches, reverse from django.core.urlresolvers import clear_url_caches, reverse
from django.http import HttpResponse from django.http import HttpResponse
from django.template import Context, Template from django.template import Context, Template
from django.test import TestCase
from organizations.tests.base import OrganizationTestCase from organizations.tests.base import OrganizationTestCase
from permissions import Permission from permissions import Permission

View File

@@ -6,12 +6,7 @@ from organizations.tests.test_organization_views import OrganizationViewTestCase
from ..models import Workflow from ..models import Workflow
from .literals import ( from .literals import TEST_WORKFLOW_LABEL, TEST_WORKFLOW_LABEL_EDITED
TEST_WORKFLOW_LABEL, TEST_WORKFLOW_LABEL_EDITED,
TEST_WORKFLOW_INITIAL_STATE_LABEL, TEST_WORKFLOW_INITIAL_STATE_COMPLETION,
TEST_WORKFLOW_STATE_LABEL, TEST_WORKFLOW_STATE_COMPLETION,
TEST_WORKFLOW_TRANSITION_LABEL
)
@override_settings(OCR_AUTO_OCR=False) @override_settings(OCR_AUTO_OCR=False)

View File

@@ -4,7 +4,6 @@ from datetime import timedelta
import logging import logging
from django.apps import apps from django.apps import apps
from django.conf import settings
from django.db import models from django.db import models
from django.utils.timezone import now from django.utils.timezone import now
@@ -182,8 +181,6 @@ class RecentDocumentManager(models.Manager):
class TrashedDocumentManager(models.Manager): class TrashedDocumentManager(models.Manager):
def get_queryset(self): def get_queryset(self):
DocumentType = apps.get_model('documents', 'DocumentType')
return super( return super(
TrashedDocumentManager, self TrashedDocumentManager, self
).get_queryset().filter(in_trash=True) ).get_queryset().filter(in_trash=True)

View File

@@ -11,9 +11,6 @@ from django.utils.six import BytesIO
from rest_framework import status from rest_framework import status
from rest_api.tests import GenericAPITestCase from rest_api.tests import GenericAPITestCase
from user_management.tests.literals import (
TEST_ADMIN_EMAIL, TEST_ADMIN_PASSWORD, TEST_ADMIN_USERNAME
)
from .literals import ( from .literals import (
TEST_DOCUMENT_FILENAME, TEST_DOCUMENT_PATH, TEST_DOCUMENT_TYPE, TEST_DOCUMENT_FILENAME, TEST_DOCUMENT_PATH, TEST_DOCUMENT_TYPE,

View File

@@ -3,8 +3,7 @@ from __future__ import unicode_literals
from datetime import timedelta from datetime import timedelta
import time import time
from common.tests import BaseTestCase from django.test import override_settings
from django.test import TestCase, override_settings
from organizations.tests.base import OrganizationTestCase from organizations.tests.base import OrganizationTestCase

View File

@@ -2,12 +2,10 @@ from __future__ import unicode_literals
from organizations.tests.test_organization_views import OrganizationViewTestCase from organizations.tests.test_organization_views import OrganizationViewTestCase
from ..models import Document,DocumentType from ..models import DocumentType
from .literals import ( from .literals import (
TEST_DOCUMENT_TYPE, TEST_DOCUMENT_TYPE_2_LABEL, TEST_DOCUMENT_TYPE, TEST_DOCUMENT_TYPE_2_LABEL, TEST_SMALL_DOCUMENT_PATH
TEST_DOCUMENT_TYPE_QUICK_LABEL, TEST_SMALL_DOCUMENT_CHECKSUM,
TEST_SMALL_DOCUMENT_PATH
) )

View File

@@ -367,7 +367,6 @@ class DocumentsViewsTestCase(GenericDocumentViewTestCase):
self.assertContains(response, text='queued', status_code=200) self.assertContains(response, text='queued', status_code=200)
self.assertEqual(self.document.pages.count(), page_count) self.assertEqual(self.document.pages.count(), page_count)
def test_document_multiple_update_page_count_view_no_permission(self): def test_document_multiple_update_page_count_view_no_permission(self):
self.login(username=TEST_USER_USERNAME, password=TEST_USER_PASSWORD) self.login(username=TEST_USER_USERNAME, password=TEST_USER_PASSWORD)

View File

@@ -1,15 +1,11 @@
from __future__ import unicode_literals from __future__ import unicode_literals
from django.contrib.auth import get_user_model
from django.core.urlresolvers import reverse from django.core.urlresolvers import reverse
from django.test import override_settings from django.test import override_settings
from documents.models import DocumentType from documents.models import DocumentType
from documents.tests import TEST_DOCUMENT_TYPE, TEST_SMALL_DOCUMENT_PATH from documents.tests import TEST_DOCUMENT_TYPE, TEST_SMALL_DOCUMENT_PATH
from rest_api.tests import GenericAPITestCase from rest_api.tests import GenericAPITestCase
from user_management.tests.literals import (
TEST_ADMIN_EMAIL, TEST_ADMIN_PASSWORD, TEST_ADMIN_USERNAME
)
from ..models import Folder from ..models import Folder

View File

@@ -11,7 +11,7 @@ class FolderOrganizationViewTestCase(OrganizationViewTestCase):
def test_folder_create_view(self): def test_folder_create_view(self):
# Create a folder for organization A # Create a folder for organization A
with self.settings(ORGANIZATION_ID=self.organization_a.pk): with self.settings(ORGANIZATION_ID=self.organization_a.pk):
response = self.post( self.post(
'folders:folder_create', data={ 'folders:folder_create', data={
'label': TEST_FOLDER_LABEL 'label': TEST_FOLDER_LABEL
} }

View File

@@ -1,15 +1,11 @@
from __future__ import unicode_literals from __future__ import unicode_literals
from django.contrib.auth import get_user_model
from django.core.urlresolvers import reverse from django.core.urlresolvers import reverse
from django.test import override_settings from django.test import override_settings
from documents.models import DocumentType from documents.models import DocumentType
from documents.tests import TEST_DOCUMENT_TYPE, TEST_SMALL_DOCUMENT_PATH from documents.tests import TEST_DOCUMENT_TYPE, TEST_SMALL_DOCUMENT_PATH
from rest_api.tests import GenericAPITestCase from rest_api.tests import GenericAPITestCase
from user_management.tests.literals import (
TEST_ADMIN_EMAIL, TEST_ADMIN_PASSWORD, TEST_ADMIN_USERNAME
)
from ..models import DocumentMetadata, DocumentTypeMetadataType, MetadataType from ..models import DocumentMetadata, DocumentTypeMetadataType, MetadataType

View File

@@ -5,9 +5,8 @@ from organizations.tests.test_organization_views import OrganizationViewTestCase
from ..models import MetadataType from ..models import MetadataType
from .literals import ( from .literals import (
TEST_DOCUMENT_METADATA_VALUE_2, TEST_METADATA_TYPE_LABEL, TEST_METADATA_TYPE_LABEL, TEST_METADATA_TYPE_LABEL_2,
TEST_METADATA_TYPE_LABEL_2, TEST_METADATA_TYPE_NAME, TEST_METADATA_TYPE_NAME,
TEST_METADATA_TYPE_NAME_2
) )

View File

@@ -11,7 +11,6 @@ import subprocess
from django.utils.translation import ugettext_lazy as _ from django.utils.translation import ugettext_lazy as _
from common.settings import setting_temporary_directory
from common.utils import copyfile, fs_cleanup, mkstemp from common.utils import copyfile, fs_cleanup, mkstemp
from .exceptions import ParserError, NoMIMETypeMatch from .exceptions import ParserError, NoMIMETypeMatch

View File

@@ -2,8 +2,6 @@
from __future__ import unicode_literals from __future__ import unicode_literals
from django.core.files.base import File
from documents.models import DocumentType from documents.models import DocumentType
from documents.settings import setting_language_choices from documents.settings import setting_language_choices
from documents.tests import ( from documents.tests import (

View File

@@ -1,10 +1,7 @@
from __future__ import unicode_literals from __future__ import unicode_literals
from django.core.files.base import File
from django.test import override_settings from django.test import override_settings
from common.settings import setting_temporary_directory
from common.tests import BaseTestCase
from documents.models import DocumentType from documents.models import DocumentType
from documents.tests import ( from documents.tests import (
TEST_DOCUMENT_PATH, TEST_DOCUMENT_TYPE, TEST_HYBRID_DOCUMENT_PATH TEST_DOCUMENT_PATH, TEST_DOCUMENT_TYPE, TEST_HYBRID_DOCUMENT_PATH

View File

@@ -1,12 +1,10 @@
from __future__ import unicode_literals from __future__ import unicode_literals
from django.apps import AppConfig
from django.utils.translation import ugettext_lazy as _ from django.utils.translation import ugettext_lazy as _
from common.apps import MayanAppConfig from common.apps import MayanAppConfig
class OrganizationApp(AppConfig): class OrganizationApp(MayanAppConfig):
name = 'organizations' name = 'organizations'
verbose_name = _('Organizations') verbose_name = _('Organizations')

View File

@@ -1,15 +1,10 @@
from __future__ import unicode_literals from __future__ import unicode_literals
import os
from django.conf import settings
from django.core import management from django.core import management
from django.utils.crypto import get_random_string
from ...models import Organization from ...models import Organization
class Command(management.BaseCommand): class Command(management.BaseCommand):
help = 'Creates an organization admin user with a secure random password and all permissions.' help = 'Creates an organization admin user with a secure random password and all permissions.'

View File

@@ -1,7 +1,7 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
from __future__ import unicode_literals from __future__ import unicode_literals
from django.db import migrations, models from django.db import migrations
from ..literals import DEFAULT_ORGANIZATION_LABEL from ..literals import DEFAULT_ORGANIZATION_LABEL
@@ -9,7 +9,7 @@ from ..literals import DEFAULT_ORGANIZATION_LABEL
def default_data(apps, schema_editor): def default_data(apps, schema_editor):
# We can't import the Organization model directly as it may be a newer # We can't import the Organization model directly as it may be a newer
# version than this migration expects. We use the historical version. # version than this migration expects. We use the historical version.
Organization = apps.get_model("organizations", "Organization") Organization = apps.get_model('organizations', 'Organization')
default_organization = Organization(label=DEFAULT_ORGANIZATION_LABEL) default_organization = Organization(label=DEFAULT_ORGANIZATION_LABEL)
default_organization.save() default_organization.save()

View File

@@ -1,16 +1,13 @@
from __future__ import absolute_import, unicode_literals from __future__ import absolute_import, unicode_literals
import logging import logging
import string
import warnings
from django.apps import apps from django.apps import apps
from django.conf import settings from django.conf import settings
from django.contrib.auth import get_user_model from django.contrib.auth import get_user_model
from django.core.exceptions import ImproperlyConfigured, ValidationError from django.core.exceptions import ImproperlyConfigured
from django.db import models from django.db import models
from django.db.models.signals import pre_save, pre_delete from django.db.models.signals import pre_save, pre_delete
from django.utils.deprecation import RemovedInDjango19Warning
from django.utils.encoding import python_2_unicode_compatible from django.utils.encoding import python_2_unicode_compatible
from django.utils.translation import ugettext_lazy as _ from django.utils.translation import ugettext_lazy as _
@@ -110,7 +107,7 @@ class Organization(models.Model):
) )
account = UserModel.objects.get( account = UserModel.objects.get(
**{UserModel.USERNAME_FIELD: username, 'organization': self,} **{UserModel.USERNAME_FIELD: username, 'organization': self}
) )
account.set_password(raw_password=password_value) account.set_password(raw_password=password_value)
account.save() account.save()

View File

@@ -1,7 +1,5 @@
from __future__ import unicode_literals from __future__ import unicode_literals
import tempfile
from django.utils.translation import ugettext_lazy as _ from django.utils.translation import ugettext_lazy as _
from smart_settings import Namespace from smart_settings import Namespace

View File

@@ -4,5 +4,5 @@ from django.apps import apps
def get_current_organization(): def get_current_organization():
from .models import Organization Organization = apps.get_model('organizations', 'Organizations')
return Organization.objects.get_current().pk return Organization.objects.get_current().pk

View File

@@ -1,4 +1,3 @@
from __future__ import absolute_import, unicode_literals from __future__ import absolute_import, unicode_literals
TEST_ORGANIZATION_LABEL = 'test organization label' TEST_ORGANIZATION_LABEL = 'test organization label'
TEST_ORGANIZATION_EDITED_LABEL = 'test organization edited label'

View File

@@ -4,7 +4,7 @@ import unittest
from django.apps import apps from django.apps import apps
from django.conf import settings from django.conf import settings
from django.core.exceptions import ObjectDoesNotExist, ValidationError from django.core.exceptions import ObjectDoesNotExist
from django.db import connections, router from django.db import connections, router
from django.http import HttpRequest from django.http import HttpRequest
from django.test import TestCase, modify_settings, override_settings from django.test import TestCase, modify_settings, override_settings

View File

@@ -4,7 +4,7 @@ from django.test import TestCase
from ..models import Organization from ..models import Organization
from .literals import TEST_ORGANIZATION_LABEL, TEST_ORGANIZATION_EDITED_LABEL from .literals import TEST_ORGANIZATION_LABEL
class OrganizationModelTestCase(TestCase): class OrganizationModelTestCase(TestCase):

View File

@@ -3,7 +3,6 @@ from __future__ import unicode_literals
from django.apps import apps from django.apps import apps
from django.core.management.color import no_style from django.core.management.color import no_style
from django.db import DEFAULT_DB_ALIAS, connections, router from django.db import DEFAULT_DB_ALIAS, connections, router
from django.db.models import signals
from .literals import DEFAULT_ORGANIZATION_LABEL from .literals import DEFAULT_ORGANIZATION_LABEL
@@ -28,12 +27,14 @@ def create_default_organization(verbosity=2, interactive=True, using=DEFAULT_DB_
# the next id will be 1, so we coerce it. See #15573 and #16353. This # the next id will be 1, so we coerce it. See #15573 and #16353. This
# can also crop up outside of tests - see #15346. # can also crop up outside of tests - see #15346.
if verbosity >= 2: if verbosity >= 2:
print("Creating default Organization object") print('Creating default Organization object')
Organization(pk=1, label=DEFAULT_ORGANIZATION_LABEL).save(using=using) Organization(pk=1, label=DEFAULT_ORGANIZATION_LABEL).save(using=using)
# We set an explicit pk instead of relying on auto-incrementation, # We set an explicit pk instead of relying on auto-incrementation,
# so we need to reset the database sequence. See #17415. # so we need to reset the database sequence. See #17415.
sequence_sql = connections[using].ops.sequence_reset_sql(no_style(), [Organization]) sequence_sql = connections[using].ops.sequence_reset_sql(
no_style(), [Organization]
)
if sequence_sql: if sequence_sql:
if verbosity >= 2: if verbosity >= 2:
print('Resetting sequence') print('Resetting sequence')

View File

@@ -9,7 +9,7 @@ from user_management.models import MayanGroup
from user_management.tests import TEST_GROUP, TEST_USER_USERNAME from user_management.tests import TEST_GROUP, TEST_USER_USERNAME
from ..classes import Permission from ..classes import Permission
from ..models import Role, StoredPermission from ..models import Role
from ..permissions import permission_role_view from ..permissions import permission_role_view
from .literals import TEST_ROLE_LABEL from .literals import TEST_ROLE_LABEL

View File

@@ -1 +1 @@
from .base import GenericAPITestCase #NOQA from .base import GenericAPITestCase # NOQA

View File

@@ -1,8 +1,5 @@
from __future__ import unicode_literals from __future__ import unicode_literals
from django.contrib.auth import get_user_model
from django.test import override_settings
from rest_framework.test import APITestCase from rest_framework.test import APITestCase
from organizations.models import Organization from organizations.models import Organization

View File

@@ -1,15 +1,11 @@
from __future__ import unicode_literals from __future__ import unicode_literals
from django.contrib.auth import get_user_model
from django.core.urlresolvers import reverse from django.core.urlresolvers import reverse
from django.test import override_settings from django.test import override_settings
from documents.models import DocumentType from documents.models import DocumentType
from documents.tests import TEST_DOCUMENT_TYPE, TEST_SMALL_DOCUMENT_PATH from documents.tests import TEST_DOCUMENT_TYPE, TEST_SMALL_DOCUMENT_PATH
from rest_api.tests.base import GenericAPITestCase from rest_api.tests.base import GenericAPITestCase
from user_management.tests.literals import (
TEST_ADMIN_EMAIL, TEST_ADMIN_PASSWORD, TEST_ADMIN_USERNAME
)
from ..models import Tag from ..models import Tag

View File

@@ -1,7 +1,7 @@
from __future__ import unicode_literals from __future__ import unicode_literals
from django.core.files.base import File from django.core.files.base import File
from django.test import TestCase, override_settings from django.test import override_settings
from documents.models import DocumentType from documents.models import DocumentType
from documents.tests import TEST_DOCUMENT_TYPE, TEST_SMALL_DOCUMENT_PATH from documents.tests import TEST_DOCUMENT_TYPE, TEST_SMALL_DOCUMENT_PATH

View File

@@ -2,7 +2,6 @@ from __future__ import unicode_literals
from django.contrib import admin from django.contrib import admin
from django.contrib.auth.admin import UserAdmin, GroupAdmin from django.contrib.auth.admin import UserAdmin, GroupAdmin
from django.utils.translation import ugettext_lazy as _
from organizations.admin import OrganizationAdminMixin from organizations.admin import OrganizationAdminMixin