Skip to content

Commit

Permalink
Merge pull request #24 from uw-it-aca/qa
Browse files Browse the repository at this point in the history
Qa
  • Loading branch information
abztrakt committed Apr 12, 2016
2 parents 34c48e4 + af109c6 commit 580a1da
Show file tree
Hide file tree
Showing 89 changed files with 6,537 additions and 2,340 deletions.
14 changes: 12 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,16 @@ python:
# command to install dependencies
install:
- pip install .
- pip install -r requirements/requirements.txt
- pip install pep8
- pip install coverage
- pip install python-coveralls
before_script:
- cp travis_ci/manage.py manage.py
- python manage.py syncdb --noinput
- python manage.py migrate
# command to run tests
script: python manage.py test
script:
- pep8 spotseeker_server/ --exclude=migrations
- coverage run --source=spotseeker_server/ --omit=spotseeker_server/migrations/* manage.py test spotseeker_server
after_script:
- coveralls
3 changes: 2 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,6 @@
'pytz',
'South',
'simplejson>=2.1',
'django-oauth-plus<=2.2.5'],
'django-oauth-plus<=2.2.5'
],
)
1 change: 1 addition & 0 deletions spotseeker_server/auth/all_ok.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
from django.conf import settings
from django.contrib.auth.models import User


def authenticate_application(*args, **kwargs):
""" This always allows requests through """
return
Expand Down
3 changes: 2 additions & 1 deletion spotseeker_server/auth/fake_oauth.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,13 @@
SPOTSEEKER_AUTH_MODULE = spotseeker_server.auth.fake_oauth
You can specify a user with a request header of
You can specify a user with a request header of
"""

from django.contrib import auth


def authenticate_application(*args, **kwargs):
""" This always allows requests through """
return
Expand Down
14 changes: 9 additions & 5 deletions spotseeker_server/auth/oauth.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,15 +62,19 @@ def authenticate_user(*args, **kwargs):
try:
trusted_client = TrustedOAuthClient.objects.get(consumer=consumer)
if trusted_client and trusted_client.is_trusted:
user = request.META["HTTP_XOAUTH_USER"]
user = request.META["HTTP_X_OAUTH_USER"]
except Exception as e:
pass


if not user:
access_token = store.get_access_token(request, oauth_request, consumer, oauth_request[u'oauth_token'])
user = store.get_user_for_access_token(request, oauth_request, access_token).username

access_token = store.get_access_token(request,
oauth_request,
consumer,
oauth_request[
u'oauth_token'])
user = store.get_user_for_access_token(request,
oauth_request,
access_token).username

request.META['SS_OAUTH_CONSUMER_NAME'] = consumer.name
request.META['SS_OAUTH_CONSUMER_PK'] = consumer.pk
Expand Down
15 changes: 10 additions & 5 deletions spotseeker_server/default_forms/spot.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,22 +24,27 @@
from spotseeker_server.models import Spot, SpotExtendedInfo
import re

LATITUDE_MAX = Decimal('90')
LATITUDE_MIN = Decimal('-90')
LONGITUDE_MAX = Decimal('180')
LONGITUDE_MIN = Decimal('-180')
LATITUDE_MAX = Decimal('90')
LATITUDE_MIN = Decimal('-90')
LONGITUDE_MAX = Decimal('180')
LONGITUDE_MIN = Decimal('-180')


class DefaultSpotExtendedInfoForm(forms.ModelForm):

class Meta:
model = SpotExtendedInfo

def clean_key(self):
key = self.cleaned_data['key'].strip()
if not re.match(r'^[a-z0-9_-]+$', key, re.I):
raise forms.ValidationError("Key must be only alphanumerics, underscores, and hyphens")
raise forms.ValidationError(
"Key must be only alphanumerics, underscores, and hyphens")
return key


class DefaultSpotForm(forms.ModelForm):

class Meta:
model = Spot
exclude = ('etag', 'last_modified')
Expand Down
8 changes: 6 additions & 2 deletions spotseeker_server/default_forms/spot_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,9 @@

class DefaultSpotSearchForm(forms.Form):
distance = forms.FloatField(required=False)
center_latitude = forms.FloatField(required=False, max_value=90, min_value=-90)
center_longitude = forms.FloatField(required=False, max_value=180, min_value=-180)
center_latitude = forms.FloatField(required=False,
max_value=90,
min_value=-90)
center_longitude = forms.FloatField(required=False,
max_value=180,
min_value=-180)
9 changes: 6 additions & 3 deletions spotseeker_server/extras/delimage.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,14 @@
Usage:
Deleting a range of image_ids: python delimage.py [path] [range] [ext]
Deleting a named range of images: python delimage.py [path] [name-prefix] [range] [ext]
Deleting a named range of images: python delimage.py [path] [name-prefix]
[range] [ext]
Deleting a single file: python delimage.py [path] [name]
Example: python delimage.py --path="/home/foo/bar/" --range="12-35" --ext=".jpg"
Example: python delimage.py --path="/home/foo/bar/" --name-prefix="image-" --range="12-35" --ext=".jpg"
Example: python delimage.py --path="/home/foo/bar/" --range="12-35"
--ext=".jpg"
Example: python delimage.py --path="/home/foo/bar/" --name-prefix="image-"
--range="12-35" --ext=".jpg"
Example: python delimage.py --path="test/" --name="foobar.jpg"
[path] is the relative or absolute path to the folder. Note: The arguments
Expand Down
14 changes: 8 additions & 6 deletions spotseeker_server/forms/spot.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@
breaks our unit tests.
"""

from spotseeker_server.default_forms.spot import DefaultSpotForm, DefaultSpotExtendedInfoForm
from spotseeker_server.default_forms.spot import \
DefaultSpotForm, DefaultSpotExtendedInfoForm
from django.utils.importlib import import_module
from django.conf import settings
from django.core.exceptions import ImproperlyConfigured
Expand All @@ -34,7 +35,8 @@ class SpotExtendedInfoForm(object):
def implementation():
if hasattr(settings, 'SPOTSEEKER_SPOTEXTENDEDINFO_FORM'):
# This is all taken from django's static file finder
module, attr = settings.SPOTSEEKER_SPOTEXTENDEDINFO_FORM.rsplit('.', 1)
module, attr = \
settings.SPOTSEEKER_SPOTEXTENDEDINFO_FORM.rsplit('.', 1)
try:
mod = import_module(module)
except ImportError, e:
Expand All @@ -43,8 +45,8 @@ def implementation():
try:
SpotExtendedInfoForm = getattr(mod, attr)
except AttributeError:
raise ImproperlyConfigured('Module "%s" does not define a "%s" '
'class.' % (module, attr))
raise ImproperlyConfigured('Module "%s" does not define '
'a "%s" class.' % (module, attr))
return SpotExtendedInfoForm
else:
return DefaultSpotExtendedInfoForm
Expand All @@ -67,8 +69,8 @@ def implementation():
try:
SpotForm = getattr(mod, attr)
except AttributeError:
raise ImproperlyConfigured('Module "%s" does not define a "%s" '
'class.' % (module, attr))
raise ImproperlyConfigured('Module "%s" does not define '
'a "%s" class.' % (module, attr))
return SpotForm
else:
return DefaultSpotForm
Expand Down
5 changes: 3 additions & 2 deletions spotseeker_server/forms/spot_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
from django.conf import settings
from django.core.exceptions import ImproperlyConfigured


class SpotSearchForm(object):
def __new__(*args, **named_args):

Expand All @@ -37,8 +38,8 @@ def __new__(*args, **named_args):
try:
FormModule = getattr(mod, attr)
except AttributeError:
raise ImproperlyConfigured('Module "%s" does not define a "%s" '
'class.' % (module, attr))
raise ImproperlyConfigured('Module "%s" does not define '
'a "%s" class.' % (module, attr))

return FormModule(args[1])
else:
Expand Down
18 changes: 12 additions & 6 deletions spotseeker_server/logger/oauth.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,12 @@
limitations under the License.
This creates a log along the lines of the apache common log format, but with
info about the OAuth apps. This is the format:
This creates a log along the lines of the apache
common log format, but with info about the OAuth apps.
This is the format:
[timestamp] app_pk\t"app_name"\tuser_name\t"METHOD URI" response_status response_size
[timestamp] app_pk\t"app_name"\tuser_name\t"METHOD URI"
response_status response_size
"""

from datetime import datetime
Expand All @@ -33,8 +35,9 @@ def process_response(self, request, response):

response_status = response.status_code

# response.content will empty out the FileWrapper object on file downloads -
# those views need to correctly set their own content length
# response.content will empty out the FileWrapper object
# on file downloads - those views need to correctly set
# their own content length
if 'Content-Length' in response:
response_length = response["Content-Length"]
else:
Expand All @@ -53,7 +56,10 @@ def process_response(self, request, response):

timestamp = datetime.now().strftime("%d/%b/%Y %H:%M:%S")

log_message = "[{0}] {1}\t\"{2}\"\t{3}\t\"{4} {5}\" {6} {7}".format(timestamp, oauth_app_pk, oauth_app_name, oauth_user, request_method, request_uri, response_status, response_length)
log_message = "[{0}] {1}\t\"{2}\"\t{3}\t\"{4} {5}\" "\
"{6} {7}".format(timestamp, oauth_app_pk, oauth_app_name,
oauth_user, request_method, request_uri,
response_status, response_length)

self.logger.info(log_message)

Expand Down
22 changes: 15 additions & 7 deletions spotseeker_server/management/commands/create_consumer.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@


class Command(BaseCommand):
help = 'Creates a unique key and secret for clients connecting to the server'
help = 'Creates a unique key and secret for clients ' \
'connecting to the server'

option_list = BaseCommand.option_list + (
make_option('--name',
Expand All @@ -38,13 +39,15 @@ class Command(BaseCommand):
make_option('--trusted',
dest='trusted',
default=False,
help="Set to 'yes' if you want this client to be trusted to act for others"),
help="Set to 'yes' if you want this client to be "
"trusted to act for others"),

make_option('--silent',
dest='silent',
action='store_true',
default=False,
help="With silent set, the command will generate no output"),
help="With silent set, the command will "
"generate no output"),
)

def handle(self, *args, **options):
Expand All @@ -53,13 +56,18 @@ def handle(self, *args, **options):
else:
consumer_name = raw_input('Enter consumer name: ')

key = hashlib.sha1("{0} - {1}".format(random.random(), time.time())).hexdigest()
secret = hashlib.sha1("{0} - {1}".format(random.random(), time.time())).hexdigest()
key = hashlib.sha1("{0} - {1}".format(random.random(),
time.time())).hexdigest()
secret = hashlib.sha1("{0} - {1}".format(random.random(),
time.time())).hexdigest()

consumer = Consumer.objects.create(name=consumer_name, key=key, secret=secret)
consumer = Consumer.objects.create(name=consumer_name,
key=key,
secret=secret)

if options['trusted'] and options['trusted'] == 'yes':
trusted = TrustedOAuthClient.objects.create(consumer=consumer, is_trusted=1)
trusted = TrustedOAuthClient.objects.create(consumer=consumer,
is_trusted=1)

if not options['silent']:
self.stdout.write("Key: %s\n" % key)
Expand Down
Loading

0 comments on commit 580a1da

Please sign in to comment.