Commit 490861c8 authored by Christos Stavrakakis's avatar Christos Stavrakakis
Browse files

Fix pep8 errors

parent 22e9bcc0
......@@ -83,20 +83,20 @@ class ActivationBackend(object):
ActivationBackend handles user verification/activation.
Example usage::
>>> # it is wise to not instantiate a backend class directly but use
>>> # get_backend method instead.
>>> backend = get_backend()
>>> formCls = backend.get_signup_form(request.POST)
>>> if form.is_valid():
>>> user = form.create_user()
>>> activation = backend.handle_registration(user)
>>> # activation.status is one of backend.Result.{*} activation result
>>> # types
>>>
>>> # sending activation notifications is not done automatically
>>> # we need to call send_result_notifications
>>> backend.send_result_notifications(activation)
>>> return HttpResponse(activation.message)
#>>> # it is wise to not instantiate a backend class directly but use
#>>> # get_backend method instead.
#>>> backend = get_backend()
#>>> formCls = backend.get_signup_form(request.POST)
#>>> if form.is_valid():
#>>> user = form.create_user()
#>>> activation = backend.handle_registration(user)
#>>> # activation.status is one of backend.Result.{*} activation result
#>>> # types
#>>>
#>>> # sending activation notifications is not done automatically
#>>> # we need to call send_result_notifications
#>>> backend.send_result_notifications(activation)
#>>> return HttpResponse(activation.message)
"""
verification_template_name = 'im/activation_email.txt'
......
......@@ -129,8 +129,8 @@ class Command(SynnefoCommand):
self.output_format, title="Expired projects")
if execute:
self.stderr.write('%d projects have been terminated.\n' % (
length,))
self.stderr.write('%d projects have been terminated.\n' %
(length,))
def expire(self, execute=False):
projects = check_expiration(execute=execute)
......
......@@ -190,8 +190,6 @@ def app_fields(app):
def project_fields(project):
app = project.last_application
d = OrderedDict([
('project id', project.uuid),
('name', project.realname),
......
......@@ -32,8 +32,6 @@
# or implied, of GRNET S.A.
from optparse import make_option
from django.db.models import Q
from astakos.im.models import AstakosUser, get_latest_terms, Project
from astakos.im.quotas import get_user_quotas
......
......@@ -1505,7 +1505,7 @@ class ProjectResourceGrant(models.Model):
return [self.project_capacity, self.member_capacity]
project_diff = \
self.project_capacity - project_resource.project_capacity
self.project_capacity - project_resource.project_capacity
member_diff = self.member_capacity - project_resource.member_capacity
return [project_diff, member_diff]
......
......@@ -96,7 +96,7 @@ class QuotaAPITest(TestCase):
r, _ = register.add_resource(resource21)
register.update_base_default(r, 3)
resource_names = [r['name'] for r in
resource_names = [res['name'] for res in
[resource11, resource12, resource21]]
# get resources
......@@ -221,7 +221,8 @@ class QuotaAPITest(TestCase):
assertIn('issue_time', body)
self.assertEqual(body["name"], u"ναμε")
provisions = sorted(body['provisions'], key=lambda p: p['resource'])
crp = sorted(commission_request['provisions'], key=lambda p: p['resource'])
crp = sorted(commission_request['provisions'],
key=lambda p: p['resource'])
self.assertEqual(provisions, crp)
self.assertEqual(body['name'], commission_request['name'])
......@@ -365,7 +366,6 @@ class QuotaAPITest(TestCase):
content_type='application/json', **s1_headers)
self.assertEqual(r.status_code, 200)
reject_data = {'reject': ""}
post_data = json.dumps(accept_data)
r = client.post(u('commissions/' + str(serial) + '/action'), post_data,
content_type='application/json', **s1_headers)
......@@ -760,7 +760,7 @@ class WrongPathAPITest(TestCase):
response = self.client.get(path)
self.assertEqual(response.status_code, 400)
try:
error = json.loads(response.content)
json.loads(response.content)
except ValueError:
self.assertTrue(False)
......
......@@ -100,7 +100,7 @@ class ProjectAPITest(TestCase):
dump = json.dumps(app)
kwargs = {"project_id": project_id}
r = self.client.put(reverse("api_project", kwargs=kwargs), dump,
content_type="application/json", **headers)
content_type="application/json", **headers)
body = json.loads(r.content)
return r.status_code, body
......@@ -605,13 +605,15 @@ class ProjectAPITest(TestCase):
status, body = self.create(ap, h_owner)
self.assertEqual(status, 400)
ap["resources"] = {u"σέρβις1.ρίσορς11": {
"member_capacity": 512}}
ap["resources"] = {u"σέρβις1.ρίσορς11": {"member_capacity": 512}}
status, body = self.create(ap, h_owner)
self.assertEqual(status, 400)
ap["resources"] = {u"σέρβις1.ρίσορς11": {"member_capacity": 512,
"project_capacity": 1024}}
ap["resources"] = {
u"σέρβις1.ρίσορς11": {
"member_capacity": 512,
"project_capacity": 1024}
}
status, body = self.create(ap, h_owner)
self.assertEqual(status, 201)
......@@ -630,10 +632,10 @@ class ProjectAPITest(TestCase):
functions.modify_project(self.user1.uuid,
{"description": "new description",
"member_join_policy":
functions.MODERATED_POLICY})
functions.MODERATED_POLICY})
functions.modify_project(self.user1.uuid,
{"member_join_policy":
functions.MODERATED_POLICY})
functions.MODERATED_POLICY})
r = client.get(reverse("api_project",
kwargs={"project_id": self.user1.uuid}),
**h_owner)
......@@ -740,9 +742,13 @@ class TestProjects(TestCase):
# let user have 2 pending applications
# TODO figure this out
request = {"resources": {"astakos.pending_app":
{"member_capacity": 2,
"project_capacity": 2}}}
request = {
"resources": {
"astakos.pending_app": {
"member_capacity": 2,
"project_capacity": 2}
}
}
functions.modify_project(self.user.uuid, request)
r = self.user_client.get(reverse('project_add'), follow=True)
......
......@@ -92,10 +92,10 @@ def network_action_demux(request, network_id):
try:
f = NETWORK_ACTIONS[action]
except KeyError:
raise faults.BadRequest("Action %s not supported." % action)
raise api.faults.BadRequest("Action %s not supported." % action)
action_args = req[action]
if not isinstance(action_args, dict):
raise faults.BadRequest("Invalid argument.")
raise api.faults.BadRequest("Invalid argument.")
return f(request, network, action_args)
......
......@@ -62,9 +62,10 @@ def id_from_network_name(name):
Strips the ganeti prefix atm. Needs a better name!
"""
if not smart_unicode(name).startswith(settings.BACKEND_PREFIX_ID):
raise Network.InvalidBackendIdError(smart_unicode(name))
ns = smart_unicode(name).replace(settings.BACKEND_PREFIX_ID + 'net-', "", 1)
name = smart_unicode(name)
if not name.startswith(settings.BACKEND_PREFIX_ID):
raise Network.InvalidBackendIdError(name)
ns = name.replace(settings.BACKEND_PREFIX_ID + 'net-', "", 1)
if not ns.isdigit():
raise Network.InvalidBackendIdError(smart_unicode(name))
......@@ -79,9 +80,10 @@ def id_from_nic_name(name):
"""Returns NIC's Django id, given a Ganeti's NIC name.
"""
if not smart_unicode(name).startswith(settings.BACKEND_PREFIX_ID):
name = smart_unicode(name)
if not name.startswith(settings.BACKEND_PREFIX_ID):
raise ValueError("Invalid NIC name: %s" % name)
ns = smart_unicode(name).replace(settings.BACKEND_PREFIX_ID + 'nic-', "", 1)
ns = name.replace(settings.BACKEND_PREFIX_ID + 'nic-', "", 1)
if not ns.isdigit():
raise ValueError("Invalid NIC name: %s" % name)
......
......@@ -77,7 +77,7 @@ def api_method(http_method=None, token_required=True, user_required=True,
try:
# Explicitly set request encoding to UTF-8 instead of relying
# to the DEFAULT_CHARSET setting. See:
# https://docs.djangoproject.com/en/1.4/ref/unicode/#form-submission
# https://docs.djangoproject.com/en/1.4/ref/unicode/#form-submission # flake8: noqa
request.encoding = 'utf-8'
# Get the requested serialization format
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment