Skip to content
This repository has been archived by the owner on Jul 3, 2019. It is now read-only.

Commit

Permalink
QA pass w/ test coverage, PEP8, etc
Browse files Browse the repository at this point in the history
  • Loading branch information
jwhitlock committed Oct 9, 2012
1 parent e7c1266 commit c1af717
Show file tree
Hide file tree
Showing 13 changed files with 71 additions and 38 deletions.
8 changes: 8 additions & 0 deletions .coveragerc
@@ -0,0 +1,8 @@
# .coveragerc to control coverage.py

[run]
branch = True
include = ./*

[report]
show_missing = True
3 changes: 3 additions & 0 deletions .gitignore
Expand Up @@ -29,3 +29,6 @@ validation-results.html
/ttgsite/ttg.sqlite
/ttgsite/media
!/ttgsite/media/.keep

# Generated by coverage
.coverage
1 change: 1 addition & 0 deletions mtta/models.py
Expand Up @@ -178,6 +178,7 @@ def copy_to_feed(self, feed):
feed.feedinfo_set.get_or_create(
publisher_name=self.name, publisher_url=self.url, lang=self.lang)


class DbfBase(models.Model):
'''Base class for models from .DBF data'''
attributes = JSONField(default=[])
Expand Down
4 changes: 4 additions & 0 deletions qa_check.sh
@@ -0,0 +1,4 @@
#!/bin/bash
./manage.py test --with-coverage
if [[ $? -ne 0 ]]; then exit 1; fi
flake8 .
9 changes: 5 additions & 4 deletions requirements-dev.txt
@@ -1,7 +1,8 @@
# Detect deviations from PEP8 standard formatting
pep8
# Detect missing or unused variables
pyflakes
# Detect deviations from PEP8 standard formatting, as well as unused
# and missing variables
flake8
# Show what lines are run by test suite
coverage

# Command-line interpreter and debugger with auto-completion
ipython
Expand Down
4 changes: 2 additions & 2 deletions ttg/forms.py
Expand Up @@ -2,12 +2,12 @@

from models import MediaFile


class UploadFileForm(forms.ModelForm):
'''Form for uploading a file'''

upload = forms.FileField()

class Meta:
model = MediaFile
fields = ('file_type',)

3 changes: 1 addition & 2 deletions ttg/management/commands/copymttatogtfs.py
@@ -1,4 +1,3 @@
from optparse import make_option
import logging

from django.core.management.base import BaseCommand, CommandError
Expand All @@ -15,7 +14,7 @@ def handle(self, *args, **options):
raise CommandError('You must pass in the ID of the MTTA signup.')
if len(args) > 1:
raise CommandError('You can only copy one signup at a time.')
signup_id = args[0]
signup_id = args[0]
try:
signup = SignUp.objects.get(id=signup_id)
except SignUp.DoesNotExist:
Expand Down
8 changes: 4 additions & 4 deletions ttg/models.py
Expand Up @@ -4,24 +4,25 @@
from django.db import models
from django.utils import timezone


class MediaFile(models.Model):
'''An uploaded or generated file'''
TYPE_CHOICES = (
#(u'I', 'Import .zip'),
(u'F', 'GTFS Feed .zip'),
)

TYPE_LOCAL_FORMATS = dict(
#I='import.%s.zip',
F='feed.%s.zip',
)

name = models.CharField(max_length=30)
added_at = models.DateField()
local_name = models.CharField(max_length=30)
file_type = models.CharField(max_length=2, choices=TYPE_CHOICES)
source = models.CharField(max_length=30)

def save_upload(self, request_file, file_type='I'):
if not self.added_at:
self.added_at = timezone.now()
Expand All @@ -39,4 +40,3 @@ def save_upload(self, request_file, file_type='I'):

def abspath(self):
return os.path.join(settings.MEDIA_ROOT, self.local_name)

6 changes: 4 additions & 2 deletions ttg/urls.py
@@ -1,8 +1,10 @@
from django.conf.urls.defaults import patterns, url

urlpatterns = patterns('ttg.views',
urlpatterns = patterns(
'ttg.views',
url(r'output/(?P<version>current)/feed.zip$', 'feed_zip',
name='feed_zip'),
url(r'output/(?P<version>current)/viewer/$', 'viewer', name='viewer'),
url(r'output/(?P<version>current)/viewer/$', 'viewer',
name='viewer'),
url(r'files/$', 'file_list', name='file_list'),
)
7 changes: 3 additions & 4 deletions ttg/views.py
@@ -1,7 +1,5 @@
from django.conf import settings
from django.contrib import messages
from django.core.cache import cache
from django.core.urlresolvers import reverse
from django.http import HttpResponse
from django.shortcuts import render_to_response
from django.template import RequestContext
Expand All @@ -10,6 +8,7 @@
from forms import UploadFileForm
from models import MediaFile


def home(request):
'''View for the home page'''
return render_to_response(
Expand All @@ -26,9 +25,9 @@ def feed_zip(request, version):
def viewer(request, version):
'''View for the schedule viewer'''
current_feed = MediaFile.objects.filter(file_type='F').latest('added_at')
schedule_key = 'schedule.%d' % current_feed.id
schedule_key = 'schedule.%d' % current_feed.id
schedule = cache.get(schedule_key)
if not schedule:
if not schedule:
schedule = transitfeed.Schedule(
problem_reporter=transitfeed.ProblemReporter())
current_feed = MediaFile.objects.filter(
Expand Down
1 change: 1 addition & 0 deletions ttgsite/local_settings.example.py
Expand Up @@ -39,6 +39,7 @@
except ImportError:
pass
else:
assert django_extensions
LOCAL_INSTALLED_APPS.append('django_extensions')

# To use nose to run tests, install django_nose and enable below
Expand Down
38 changes: 26 additions & 12 deletions ttgsite/settings.py
Expand Up @@ -16,12 +16,18 @@

DATABASES = {
'default': {
'ENGINE': 'django.db.backends.', # Add 'postgresql_psycopg2', 'mysql', 'sqlite3' or 'oracle'.
'NAME': '', # Or path to database file if using sqlite3.
'USER': '', # Not used with sqlite3.
'PASSWORD': '', # Not used with sqlite3.
'HOST': '', # Set to empty string for localhost. Not used with sqlite3.
'PORT': '', # Set to empty string for default. Not used with sqlite3.
# Add 'postgresql_psycopg2', 'mysql', 'sqlite3' or 'oracle'.
'ENGINE': 'django.db.backends.',
# Name or path to database file if using sqlite3.
'NAME': '',
# User for connection, not used with sqlite3
'USER': '',
# Password for connection, not used with sqlite3
'PASSWORD': '',
# Hostname for connection, empty for default, not used with sqlite3
'HOST': '',
# Port for connection, empty for default, not used with sqlite3
'PORT': '',
}
}

Expand Down Expand Up @@ -79,7 +85,7 @@
STATICFILES_FINDERS = (
'django.contrib.staticfiles.finders.FileSystemFinder',
'django.contrib.staticfiles.finders.AppDirectoriesFinder',
# 'django.contrib.staticfiles.finders.DefaultStorageFinder',
# 'django.contrib.staticfiles.finders.DefaultStorageFinder',
)

# Make this unique, and don't share it with anybody.
Expand All @@ -89,7 +95,7 @@
TEMPLATE_LOADERS = (
'django.template.loaders.filesystem.Loader',
'django.template.loaders.app_directories.Loader',
# 'django.template.loaders.eggs.Loader',
# 'django.template.loaders.eggs.Loader',
)

MIDDLEWARE_CLASSES = (
Expand All @@ -108,7 +114,8 @@
WSGI_APPLICATION = 'ttgsite.wsgi.application'

TEMPLATE_DIRS = (
# Put strings here, like "/home/html/django_templates" or "C:/www/django/templates".
# Put strings here, like "/home/html/django_templates" or
# "C:/www/django/templates".
# Always use forward slashes, even on Windows.
# Don't forget to use absolute paths, not relative paths.
)
Expand All @@ -130,9 +137,10 @@
try:
import docutils
except ImportError:
ENABLE_ADMIN_DOCS=False
ENABLE_ADMIN_DOCS = False
else:
ENABLE_ADMIN_DOCS=True
assert docutils
ENABLE_ADMIN_DOCS = True
INSTALLED_APPS.append('django.contrib.admindocs')

# A sample logging configuration. The only tangible logging
Expand Down Expand Up @@ -165,11 +173,17 @@
}

try:
from local_settings import *
from local_settings import * # NOQA
except ImportError:
pass

try:
INSTALLED_APPS.extend(LOCAL_INSTALLED_APPS)
except NameError:
pass

if 'test' in sys.argv:
DATABASES['default'] = {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': 'mydatabase'
}
17 changes: 9 additions & 8 deletions ttgsite/urls.py
Expand Up @@ -4,21 +4,22 @@

admin.autodiscover()

urlpatterns = patterns('',
urlpatterns = patterns(
'',
url(r'^$', 'ttg.views.home', name='home'),
url(r'^ttg/', include('ttg.urls')),
)

if settings.ENABLE_ADMIN_DOCS:
urlpatterns += patterns('',
url(r'^admin/doc/', include('django.contrib.admindocs.urls')))
urlpatterns += patterns(
'', url(r'^admin/doc/', include('django.contrib.admindocs.urls')))

urlpatterns += patterns('',
url(r'^admin/', include(admin.site.urls))
urlpatterns += patterns(
'', url(r'^admin/', include(admin.site.urls))
)

if settings.DEBUG:
urlpatterns += patterns('',
url(r'^media/(?P<path>.*)$', 'django.views.static.serve',
{'document_root': settings.MEDIA_ROOT,}),
urlpatterns += patterns(
'', url(r'^media/(?P<path>.*)$', 'django.views.static.serve',
{'document_root': settings.MEDIA_ROOT}),
)

0 comments on commit c1af717

Please sign in to comment.