Skip to content

Commit

Permalink
Did flake8, black, isort
Browse files Browse the repository at this point in the history
  • Loading branch information
rstorey authored and acj3rd committed Jul 17, 2018
1 parent b03d959 commit f6efac9
Show file tree
Hide file tree
Showing 24 changed files with 83 additions and 106 deletions.
4 changes: 2 additions & 2 deletions concordia/admin.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from django.contrib import admin
from django.contrib.auth.admin import UserAdmin

from .models import *
from .models import (Asset, Collection, Subcollection, Tag, Transcription,
UserAssetTagCollection)


@admin.register(Collection)
Expand Down
2 changes: 0 additions & 2 deletions concordia/celery.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
from __future__ import absolute_import, unicode_literals

import os

from celery import Celery

app = Celery("concordia")
Expand Down
47 changes: 21 additions & 26 deletions concordia/forms.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from logging import getLogger

from django import forms
from django.conf import settings
from django.contrib.auth import get_user_model
from registration.forms import RegistrationForm

Expand All @@ -12,38 +11,34 @@

class ConcordiaUserForm(RegistrationForm):
username = forms.CharField(
label="Username", required=True, widget=forms.TextInput(
attrs={
'class': 'form-control',
'placeholder': 'Username'
}
)
label="Username",
required=True,
widget=forms.TextInput(
attrs={"class": "form-control", "placeholder": "Username"}
),
)
email = forms.CharField(
label="Email", required=True, widget=forms.EmailInput(
attrs={
'class': 'form-control',
'placeholder': 'Email'
}
)
label="Email",
required=True,
widget=forms.EmailInput(
attrs={"class": "form-control", "placeholder": "Email"}
),
)
password1 = forms.CharField(
label="Password", required=True, widget=forms.PasswordInput(
attrs={
'class': 'form-control',
'placeholder': 'Password'
}
)
label="Password",
required=True,
widget=forms.PasswordInput(
attrs={"class": "form-control", "placeholder": "Password"}
),
)
password2 = forms.CharField(
label="Confirm", required=True, widget=forms.PasswordInput(
attrs={
'class': 'form-control',
'placeholder': 'Confirm'
}
)
label="Confirm",
required=True,
widget=forms.PasswordInput(
attrs={"class": "form-control", "placeholder": "Confirm"}
),
)

class Meta:
model = User
fields = ["username", "email"]
Expand Down
3 changes: 2 additions & 1 deletion concordia/settings_prod.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@

DJANGO_SECRET_KEY = "changeme"

# TODO: For final deployment to production, when we are running https, uncomment this next line
# TODO: For final deployment to production,
# when we are running https, uncomment this next line
# CSRF_COOKIE_SECURE = True

IMPORTER = {
Expand Down
8 changes: 5 additions & 3 deletions concordia/settings_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,10 +210,12 @@

LOGIN_URL = "/account/login/"

PASSWORD_VALIDATOR = (
"django.contrib.auth.password_validation.UserAttributeSimilarityValidator"
)

AUTH_PASSWORD_VALIDATORS = [
{
"NAME": "django.contrib.auth.password_validation.UserAttributeSimilarityValidator"
},
{"NAME": PASSWORD_VALIDATOR},
{
"NAME": "django.contrib.auth.password_validation.MinimumLengthValidator",
"OPTIONS": {"min_length": 8},
Expand Down
35 changes: 15 additions & 20 deletions concordia/tests/test_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,12 @@
import tempfile
from unittest.mock import Mock, patch


import views
from django.test import Client, TestCase
from PIL import Image

import views
from concordia.models import (
Asset,
Collection,
MediaType,
Status,
Tag,
Transcription,
User,
UserProfile,
UserAssetTagCollection,
)
from concordia.models import (Asset, Collection, MediaType, Status, Transcription, User,
UserAssetTagCollection, UserProfile)


class ViewTest_Concordia(TestCase):
Expand Down Expand Up @@ -46,7 +36,7 @@ def login_user(self):
self.user.set_password("top_secret")
self.user.save()

login = self.client.login(username="tester", password="top_secret")
self.client.login(username="tester", password="top_secret")

def test_concordia_api(self):
"""
Expand All @@ -56,7 +46,7 @@ def test_concordia_api(self):

# Arrange

relative_path = Mock()
Mock()

with patch("views.requests") as mock_requests:
mock_requests.get.return_value = mock_response = Mock()
Expand Down Expand Up @@ -151,7 +141,8 @@ def test_AccountProfileView_post(self):

def test_AccountProfileView_post_invalid_form(self):
"""
This unit test tests the post entry for the route account/profile but submits an invalid form
This unit test tests the post entry for the route
account/profile but submits an invalid form
:param self:
:return:
"""
Expand All @@ -171,7 +162,8 @@ def test_AccountProfileView_post_invalid_form(self):

def test_AccountProfileView_post_new_password(self):
"""
This unit test test the post entry for the route account/profile with new password
This unit test test the post entry for the
route account/profile with new password
:param self:
:return:
"""
Expand Down Expand Up @@ -200,14 +192,15 @@ def test_AccountProfileView_post_new_password(self):
self.assertEqual(updated_user.first_name, "Jimmy")

# logout and login with new password
logout = self.client.logout()
self.client.logout()
login2 = self.client.login(username="tester", password="aBc12345!")

self.assertTrue(login2)

def test_AccountProfileView_post_with_image(self):
"""
This unit test tests the post entry for the route account/profile with new image file
This unit test tests the post entry for the
route account/profile with new image file
:param self:
:return:
"""
Expand Down Expand Up @@ -355,7 +348,9 @@ def test_ExportCollectionView_get(self):
self.assertEqual(response.status_code, 200)
self.assertEqual(
str(response.content),
"b'Collection,Title,Description,MediaUrl,Transcription,Tags\\r\\nTextCollection,TestAsset,Asset Description,http://www.foo.com/1/2/3,,\\r\\n'",
"b'Collection,Title,Description,MediaUrl,Transcription,Tags\\r\\n"
"TextCollection,TestAsset,Asset Description,"
"http://www.foo.com/1/2/3,,\\r\\n'",
)

@patch("concordia.views.requests")
Expand Down
4 changes: 3 additions & 1 deletion concordia/tests/test_view_simple.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@

class ViewTest1(TestCase):
"""
This is a simple django TestCase that can be used to prove the django test environment is properly configured.
This is a simple django TestCase that
can be used to prove the django test
environment is properly configured.
It doesn't test any component of the concordia project.
"""
Expand Down
3 changes: 1 addition & 2 deletions concordia/trans_urls.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from django.urls import include, re_path
from rest_framework import routers
from django.urls import re_path
from rest_framework.documentation import include_docs_urls
from rest_framework.schemas import get_schema_view

Expand Down
6 changes: 1 addition & 5 deletions concordia/trans_views.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from logging import getLogger

from django.db.models import Count
from rest_framework import viewsets
from rest_framework.decorators import api_view
from rest_framework.response import Response
Expand All @@ -14,10 +13,7 @@
@api_view(["GET"])
def api_root(request, format=None):
return Response(
{
"collections": reverse("collection-list", request=request, format=format),
# 'collection': reverse('collection-detail', request=request, format=format),
}
{"collections": reverse("collection-list", request=request, format=format)}
)


Expand Down
12 changes: 3 additions & 9 deletions concordia/urls.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,15 @@

import os
import sys

from django.conf import settings
from django.conf.urls.static import static
from django.conf.urls import include, url
from django.contrib import admin
from django.contrib.auth import views as auth_views
from django.urls import include, re_path
from django.urls import re_path
from django.views.generic import TemplateView
from django.views.static import serve
from machina.app import board

from exporter import views as exporter_views
from faq.views import FAQView
from django.conf.urls import url, include

from . import trans_urls, views

Expand Down Expand Up @@ -128,6 +124,4 @@
re_path(r"^media/(?P<path>.*)$", serve, {"document_root": settings.MEDIA_ROOT})
]

urlpatterns += [
url('', include('django_prometheus_metrics.urls')),
]
urlpatterns += [url("", include("django_prometheus_metrics.urls"))]
6 changes: 4 additions & 2 deletions concordia/validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@
from django.core.exceptions import ValidationError
from django.utils.translation import ugettext_lazy as _

PASSWORD_COMPLEXITY = { # You can omit any or all of these for no limit for that particular set
PASSWORD_COMPLEXITY = {
# You can omit any or all of these for no limit for that particular set
"UPPER": 1, # Uppercase
"LOWER": 1, # Lowercase
"LETTERS": 1, # Either uppercase or lowercase letters
"DIGITS": 1, # Digits
"SPECIAL": 1, # Not alphanumeric, space or punctuation character
"WORDS": 1, # Words (alphanumeric sequences separated by a whitespace or punctuation character)
# Words (alphanumeric sequences separated by a whitespace or punctuation character)
"WORDS": 1,
}


Expand Down
10 changes: 2 additions & 8 deletions concordia/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,8 @@
from registration.backends.simple.views import RegistrationView

from concordia.forms import ConcordiaUserEditForm, ConcordiaUserForm
from concordia.models import (
Asset,
Collection,
Tag,
Transcription,
UserAssetTagCollection,
UserProfile,
)
from concordia.models import (Asset, Collection, Tag, Transcription,
UserAssetTagCollection, UserProfile)

logger = getLogger(__name__)

Expand Down
2 changes: 0 additions & 2 deletions concordia/wsgi.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
https://docs.djangoproject.com/en/2.0/howto/deployment/wsgi/
"""

import os

from django.core.wsgi import get_wsgi_application

application = get_wsgi_application()
2 changes: 1 addition & 1 deletion exporter/admin.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
from django.contrib import admin


# Register your models here.
1 change: 0 additions & 1 deletion exporter/models.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
from django.db import models

# Create your models here.
2 changes: 1 addition & 1 deletion exporter/tests.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
from django.test import TestCase


# Create your tests here.
7 changes: 3 additions & 4 deletions exporter/tests/test_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@
from django.conf import settings
from django.test import Client, TestCase

from concordia.models import (Asset, Collection, MediaType, Status,
Transcription, User)
from concordia.models import Asset, Collection, MediaType, Status, Transcription, User

PACKAGE_PARENT = ".."
SCRIPT_DIR = os.path.dirname(
Expand Down Expand Up @@ -97,7 +96,7 @@ def test_ExportCollectionToBagit_get(self):
collection_folder = build_folder + "/foocollection"
if not os.path.exists(collection_folder):
os.makedirs(collection_folder)
asset_folder = collection_folder +"/testasset"
asset_folder = collection_folder + "/testasset"
if not os.path.exists(asset_folder):
os.makedirs(asset_folder)

Expand Down Expand Up @@ -149,5 +148,5 @@ def test_ExportCollectionToBagit_get(self):
# Clean up temp folders
try:
shutil.rmtree(collection_folder)
except:
except Exception as e:
pass
6 changes: 3 additions & 3 deletions exporter/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ def get(self, request, *args, **kwargs):
writer.writerow(row)

# Turn Strucutre into bagit format
bag = bagit.make_bag(collection_folder, {"Contact-Name": request.user.username})
bagit.make_bag(collection_folder, {"Contact-Name": request.user.username})

# Build .zipfile of bagit formatted Collection Folder
archive_name = collection_folder
Expand All @@ -156,11 +156,11 @@ def get(self, request, *args, **kwargs):
# Clean up temp folders & zipfile once exported
try:
shutil.rmtree(collection_folder)
except:
except Exception as e:
pass
try:
os.remove("%s.zip" % collection_folder)
except:
except Exception as e:
pass

return response
2 changes: 1 addition & 1 deletion faq/tests.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
from django.test import TestCase


# Create your tests here.
2 changes: 1 addition & 1 deletion faq/views.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from django.shortcuts import render

from django.views.generic import TemplateView

from .models import FAQ
Expand Down
2 changes: 0 additions & 2 deletions importer/importer/celery.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
from __future__ import absolute_import, unicode_literals

import os

from celery import Celery

app = Celery("importer")
Expand Down
Loading

0 comments on commit f6efac9

Please sign in to comment.