Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

pep8 fixes

  • Loading branch information...
commit 2ac6e81b236e6549ea3ccf86d743cdaaeadd8395 1 parent d6ce93c
Miquel Torres authored
56 codespeed/api.py
View
@@ -23,29 +23,33 @@
PUT a full result:
curl --dump-header - -H "Content-Type: application/json" -X POST \
- --data '{"commitid": "4", "branch": "default", "project": "MyProject",\
- "executable": "myexe O3 64bits", "benchmark": "float", "environment": \
- "Quad Core", "result_value": 4000, "result": "4000"}' \
+ --data '{"commitid": "4", "branch": "default", \
+ "project": "MyProject", "executable": "myexe O3 64bits", \
+ "benchmark": "float", "environment": "Quad Core", \
+ "result_value": 4000, "result": "4000"}' \
http://127.0.0.1:8000/api/v1/benchmark-result/
See http://django-tastypie.readthedocs.org/en/latest/interacting.html
"""
import logging
from datetime import datetime
+
from django.contrib.auth.models import User
from django.db import models
-from tastypie.bundle import Bundle
from django.http import Http404
from django.shortcuts import get_object_or_404
from tastypie.bundle import Bundle
+from tastypie.bundle import Bundle
from tastypie.exceptions import ImmediateHttpResponse
from tastypie.http import HttpBadRequest, HttpCreated, HttpNotImplemented
from tastypie.resources import ModelResource, Resource
from tastypie import fields
from tastypie.authorization import Authorization, DjangoAuthorization
-from tastypie.authentication import Authentication, ApiKeyAuthentication, MultiAuthentication
+from tastypie.authentication import (Authentication, ApiKeyAuthentication,
+ MultiAuthentication)
from tastypie.models import create_api_key
from tastypie.utils.dict import dict_strip_unicode_keys
+
from codespeed.models import (Environment, Project, Result, Branch, Revision,
Executable, Benchmark, Report)
@@ -74,7 +78,8 @@ class Meta:
queryset = Project.objects.all()
authorization = DjangoAuthorization()
# Note, the order for MultiAuthentication matters!
- authentication = MultiAuthentication(ApiKeyAuthentication(), Authentication())
+ authentication = MultiAuthentication(ApiKeyAuthentication(),
+ Authentication())
class BranchResource(ModelResource):
@@ -85,7 +90,8 @@ class BranchResource(ModelResource):
class Meta:
queryset = Branch.objects.all()
authorization = DjangoAuthorization()
- authentication = MultiAuthentication(ApiKeyAuthentication(), Authentication())
+ authentication = MultiAuthentication(ApiKeyAuthentication(),
+ Authentication())
class RevisionResource(ModelResource):
@@ -97,7 +103,8 @@ class RevisionResource(ModelResource):
class Meta:
queryset = Revision.objects.all()
authorization = DjangoAuthorization()
- authentication = MultiAuthentication(ApiKeyAuthentication(), Authentication())
+ authentication = MultiAuthentication(ApiKeyAuthentication(),
+ Authentication())
class ExecutableResource(ModelResource):
@@ -108,7 +115,8 @@ class ExecutableResource(ModelResource):
class Meta:
queryset = Executable.objects.all()
authorization = DjangoAuthorization()
- authentication = MultiAuthentication(ApiKeyAuthentication(), Authentication())
+ authentication = MultiAuthentication(ApiKeyAuthentication(),
+ Authentication())
class BenchmarkResource(ModelResource):
@@ -117,7 +125,8 @@ class BenchmarkResource(ModelResource):
class Meta:
queryset = Benchmark.objects.all()
authorization = DjangoAuthorization()
- authentication = MultiAuthentication(ApiKeyAuthentication(), Authentication())
+ authentication = MultiAuthentication(ApiKeyAuthentication(),
+ Authentication())
class EnvironmentResource(ModelResource):
@@ -128,7 +137,8 @@ class Meta:
resource_name = 'environment'
authorization = DjangoAuthorization()
authentication = ApiKeyAuthentication()
- #authentication = MultiAuthentication(Authentication(), ApiKeyAuthentication())
+ #authentication = MultiAuthentication(Authentication(),
+ #ApiKeyAuthentication())
class ResultResource(ModelResource):
@@ -141,7 +151,8 @@ class ResultResource(ModelResource):
class Meta:
queryset = Result.objects.all()
authorization = DjangoAuthorization()
- authentication = MultiAuthentication(ApiKeyAuthentication(), Authentication())
+ authentication = MultiAuthentication(ApiKeyAuthentication(),
+ Authentication())
class ReportResource(ModelResource):
@@ -155,7 +166,8 @@ class Meta:
queryset = Report.objects.all()
allowed_methods = ['get']
authorization = DjangoAuthorization()
- authentication = MultiAuthentication(ApiKeyAuthentication(), Authentication())
+ authentication = MultiAuthentication(ApiKeyAuthentication(),
+ Authentication())
class ResultBundle(Bundle):
@@ -222,7 +234,7 @@ def populate(key):
'branch': lambda: BranchResource().get_via_uri(
self.data['branch']),
'revision': lambda: RevisionResource().get_via_uri(
- self.data['commitid']),}.get(key, None)()
+ self.data['commitid'])}.get(key, None)()
try:
self.obj.value = float(self.data['result_value'])
@@ -281,7 +293,8 @@ def _check_data(self):
elif not self.data[key]:
error_text = 'Value for key {0} is empty.'.format(key)
logging.error(error_text)
- raise ImmediateHttpResponse(response=HttpBadRequest(error_text))
+ raise ImmediateHttpResponse(
+ response=HttpBadRequest(error_text))
# Check that the Environment exists
try:
@@ -296,13 +309,10 @@ def _check_data(self):
error_text
))
except Exception as e:
- error_text = 'Error while looking up Environment: {0}, {1}.'.format(
- self.data['environment'], e)
+ error_text = ('Error while looking up Environment: '
+ '{0}, {1}.'.format(self.data['environment'], e))
logging.error(error_text)
- raise ImmediateHttpResponse(
- response=HttpBadRequest(
- error_text
- ))
+ raise ImmediateHttpResponse(response=HttpBadRequest(error_text))
# check optional data
for key in [k for k in self.optional_keys \
if k not in ('date',)]:
@@ -352,8 +362,8 @@ class ResultBundleResource(Resource):
'result_value',
not mandatory data
- 'notify' - Send notification to registered user if result varies from
- previous results, currently not implemented
+ 'notify' - Send notification to registered user if result varies
+ from previous results, currently not implemented
"""
revision = fields.ToOneField(RevisionResource, 'revision')
6 codespeed/git.py
View
@@ -68,8 +68,8 @@ def getlogs(endrev, startrev):
date = datetime.datetime.fromtimestamp(
int(date_t)).strftime("%Y-%m-%d %H:%M:%S")
- logs.append({'date': date, 'message': subject, 'body': body,
- 'author': author_name, 'author_email': author_email,
- 'commitid': commit_id, 'short_commit_id': short_commit_id})
+ logs.append({'date': date, 'message': subject, 'commitid': commit_id,
+ 'author': author_name, 'author_email': author_email,
+ 'body': body, 'short_commit_id': short_commit_id})
return logs
1  codespeed/tests/__init__.py
View
@@ -76,4 +76,3 @@ def get_suite(*names, **kwargs):
return suite
suite = lambda: get_suite(__name__)
-
39 codespeed/tests/tests.py
View
@@ -1,13 +1,16 @@
# -*- coding: utf-8 -*-
from datetime import datetime, timedelta
-import copy, json, os
+import copy
+import json
+import os
from django.test import TestCase
from django.test.client import Client
from django.core.urlresolvers import reverse
from django.conf import settings
-from codespeed.models import (Project, Benchmark, Revision, Branch,
- Executable, Environment, Result, Report)
+
+from codespeed.models import (Project, Benchmark, Revision, Branch, Executable,
+ Environment, Result, Report)
from codespeed.views import getbaselineexecutables
from codespeed import settings as default_settings
@@ -65,9 +68,9 @@ def test_add_non_default_result(self):
modified_data['revision_date'] = revision_date
result_date = self.cdate + timedelta(minutes=2)
modified_data['result_date'] = result_date
- modified_data['std_dev'] = 1.11111
- modified_data['max'] = 2
- modified_data['min'] = 1.0
+ modified_data['std_dev'] = 1.11111
+ modified_data['max'] = 2
+ modified_data['min'] = 1.0
response = self.client.post(self.path, modified_data)
self.assertEquals(response.status_code, 202)
self.assertEquals(response.content, "Result data saved successfully")
@@ -176,37 +179,39 @@ def setUp(self):
'executable': 'pypy-c',
'benchmark': 'Richards',
'environment': 'bigdog',
- 'result_value': 456,},
+ 'result_value': 456},
{'commitid': '456',
'project': 'pypy',
'branch': 'default',
'executable': 'pypy-c',
'benchmark': 'Richards',
'environment': 'bigdog',
- 'result_value': 457,},
+ 'result_value': 457},
{'commitid': '456',
'project': 'pypy',
'branch': 'default',
'executable': 'pypy-c',
'benchmark': 'Richards2',
'environment': 'bigdog',
- 'result_value': 34,},
+ 'result_value': 34},
{'commitid': '789',
'project': 'pypy',
'branch': 'default',
'executable': 'pypy-c',
'benchmark': 'Richards',
'environment': 'bigdog',
- 'result_value': 458,},
+ 'result_value': 458},
]
def test_add_correct_results(self):
"""Should add all results when the request data is valid"""
- response = self.client.post(self.path, {'json' : json.dumps(self.data)})
+ response = self.client.post(self.path,
+ {'json': json.dumps(self.data)})
# Check that we get a success response
self.assertEquals(response.status_code, 202)
- self.assertEquals(response.content, "All result data saved successfully")
+ self.assertEquals(response.content,
+ "All result data saved successfully")
# Check that the data was correctly saved
e = Environment.objects.get(name='bigdog')
@@ -254,7 +259,8 @@ def test_bad_environment(self):
data = self.data[0]
bad_name = 'bigdog1'
data['environment'] = bad_name
- response = self.client.post(self.path, {'json' : json.dumps(self.data)})
+ response = self.client.post(self.path,
+ {'json': json.dumps(self.data)})
self.assertEquals(response.status_code, 400)
self.assertEquals(response.content, "Environment " + bad_name + " not found")
@@ -267,7 +273,7 @@ def test_empty_argument(self):
backup = data[key]
data[key] = ""
response = self.client.post(self.path,
- {'json' : json.dumps(self.data)})
+ {'json': json.dumps(self.data)})
self.assertEquals(response.status_code, 400)
self.assertEquals(response.content, 'Value for key "' + key + '" empty in request')
data[key] = backup
@@ -279,7 +285,7 @@ def test_missing_argument(self):
backup = data[key]
del(data[key])
response = self.client.post(self.path,
- {'json' : json.dumps(self.data)})
+ {'json': json.dumps(self.data)})
self.assertEquals(response.status_code, 400)
self.assertEquals(response.content, 'Key "' + key + '" missing from request')
data[key] = backup
@@ -287,7 +293,8 @@ def test_missing_argument(self):
def test_report_is_created(self):
'''Should create a report when adding json results for two revisions
plus a third revision with one result less than the last one'''
- response = self.client.post(self.path, {'json' : json.dumps(self.data)})
+ response = self.client.post(self.path,
+ {'json': json.dumps(self.data)})
# Check that we get a success response
self.assertEquals(response.status_code, 202)
49 codespeed/tests/tests_api.py
View
@@ -3,9 +3,9 @@
"""
Tests related to RESTful API
"""
-
from datetime import datetime
-import copy, json
+import copy
+import json
import logging
import unittest
@@ -16,16 +16,17 @@
from django.core.urlresolvers import reverse
from django.conf import settings
from django.contrib.auth.models import User, Permission
-from tastypie.authorization import Authorization, ReadOnlyAuthorization, DjangoAuthorization
+from tastypie.authorization import (Authorization, ReadOnlyAuthorization,
+ DjangoAuthorization)
from tastypie.exceptions import ImmediateHttpResponse
from tastypie.models import ApiKey, create_api_key
from tastypie.http import HttpUnauthorized
from tastypie.authentication import ApiKeyAuthentication
+
from codespeed.api import EnvironmentResource, ProjectResource
from codespeed.models import (Project, Benchmark, Revision, Branch,
Executable, Environment, Result, Report)
from codespeed.api import ResultBundle
-
from codespeed import settings as default_settings
@@ -40,8 +41,8 @@ def setUp(self):
john_doe = User.objects.create_user(
username='johndoe', email='api@foo.bar', password='password')
john_doe.save()
- authorization='ApiKey {0}:{1}'.format(self.api_user.username,
- self.api_user.api_key.key)
+ authorization = 'ApiKey {0}:{1}'.format(self.api_user.username,
+ self.api_user.api_key.key)
self.post_auth = {'HTTP_AUTHORIZATION': authorization}
@@ -138,7 +139,8 @@ def test_api_key(self):
"""User should be authenticated by it's api key."""
auth = ApiKeyAuthentication()
request = HttpRequest()
- authorization='ApiKey %s:%s' % (self.api_user.username, self.api_user.api_key.key)
+ authorization = 'ApiKey %s:%s' % (self.api_user.username,
+ self.api_user.api_key.key)
request.META['HTTP_AUTHORIZATION'] = authorization
self.assertEqual(auth.is_authenticated(request), True)
@@ -522,12 +524,9 @@ class ExecutableTest(FixtureTestCase):
"""Test Executable() API"""
def setUp(self):
- self.data = dict(
- name="Fibo",
- description="Fibonacci the Lame",
- )
+ self.data = dict(name="Fibo", description="Fibonacci the Lame",)
# project is a ForeignKey and is not added automatically by tastypie
- self.project=Project.objects.get(pk=1)
+ self.project = Project.objects.get(pk=1)
self.executable = Executable(project=self.project, **self.data)
self.executable.save()
self.client = Client()
@@ -626,7 +625,7 @@ def test_get_branch_all_fields(self):
self.assertEquals(json.loads(response.content)['project'],
'/api/v1/project/1/')
self.assertEquals(json.loads(response.content)['resource_uri'],
- '/api/v1/branch/%s/' %(self.branch1.id,))
+ '/api/v1/branch/%s/' % (self.branch1.id,))
def test_post(self):
"""Should save a new branch"""
@@ -852,8 +851,8 @@ def setUp(self):
self.executable2_data = dict(
name="sleep",
description="Sleep benchmark",
- project= '/api/v1/project/{0}/'.format(self.project1.id),
- )
+ project='/api/v1/project/{0}/'.format(self.project1.id),
+ )
self.client = Client()
def test_get_executable(self):
@@ -966,13 +965,13 @@ def setUp(self):
self.benchmark1 = Benchmark.objects.get(pk=1)
self.benchmark2_data = dict(
name="sleep",
- benchmark_type = 'C',
- description = 'fast faster fastest',
- units_title = 'Time',
- units = 'seconds',
- lessisbetter = True,
- default_on_comparison = True,
- )
+ benchmark_type='C',
+ description='fast faster fastest',
+ units_title='Time',
+ units='seconds',
+ lessisbetter=True,
+ default_on_comparison=True,
+ )
self.benchmark2 = Benchmark(**self.benchmark2_data)
self.benchmark2.save()
self.client = Client()
@@ -1089,8 +1088,8 @@ def setUp(self):
self.executable2_data = dict(
name="Fibo",
description="Fibonacci the Lame",
- )
- self.project=Project.objects.get(pk=1)
+ )
+ self.project = Project.objects.get(pk=1)
self.executable2 = Executable(project=self.project,
**self.executable2_data)
self.executable2.save()
@@ -1281,8 +1280,8 @@ class ResultBundleResourceTestCase(FixtureTestCase):
"""Submitting new benchmark results"""
DATETIME_FORMAT = '%Y-%m-%d %H:%M:%S'
- def setUp(self):
+ def setUp(self):
super(ResultBundleResourceTestCase, self).setUp()
self.add = Permission.objects.get_by_natural_key(
Please sign in to comment.
Something went wrong with that request. Please try again.