Skip to content

Commit

Permalink
fix other pep8 nuissances introduced in the latest version + ignore E123
Browse files Browse the repository at this point in the history
  • Loading branch information
iartarisi committed Jul 20, 2012
1 parent cb925c2 commit 258945c
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 31 deletions.
4 changes: 3 additions & 1 deletion .travis.yml
Expand Up @@ -12,5 +12,7 @@ before_script:
- psql -c "GRANT ALL PRIVILEGES ON DATABASE popcorn TO popcorn;" -U postgres

script:
- pep8 popcorn
# E123 closing bracket does not match indentation of opening bracket's line
# see https://github.com/jcrocholl/pep8/issues/103
- pep8 --ignore E123 popcorn
- python setup.py test
5 changes: 3 additions & 2 deletions popcorn/helpers.py
Expand Up @@ -29,8 +29,9 @@
def request_wants_json():
best = request.accept_mimetypes.best_match(['application/json',
'text/html'])
return best == 'application/json' and (request.accept_mimetypes[best] >
request.accept_mimetypes['text/html'])
return (best == 'application/json'
and (request.accept_mimetypes[best] >
request.accept_mimetypes['text/html']))


def render(template=None):
Expand Down
8 changes: 4 additions & 4 deletions popcorn/pagination.py
Expand Up @@ -61,10 +61,10 @@ def iter_pages(self, left_edge=2, left_current=2,
""" Generates page numbers for navigation """
last = 0
for num in xrange(1, self.pages + 1):
if (num <= left_edge or
(num > self.page - left_current - 1 and
num < self.page + right_current) or
num > self.pages - right_edge):
if (num <= left_edge
or (num > self.page - left_current - 1
and num < self.page + right_current)
or (num > self.pages - right_edge)):
if last + 1 != num:
yield None
yield num
Expand Down
9 changes: 4 additions & 5 deletions popcorn/test/test_models.py
Expand Up @@ -115,11 +115,10 @@ def test_submission_package_creation(self):

def test_system_last_submission(self):
sub1 = Submission('hw_uuid1', 'P1', date.today())
sub2 = Submission('hw_uuid2', 'P1', date.today() -
timedelta(days=31 * 2))
sub3 = Submission('hw_uuid1', 'P1', date.today() -
timedelta(days=31 * 3))

sub2 = Submission('hw_uuid2', 'P1',
date.today() - timedelta(days=31 * 2))
sub3 = Submission('hw_uuid1', 'P1',
date.today() - timedelta(days=31 * 3))
s1 = System.query.first()
self.assertIsNone(s1.last_submission)

Expand Down
27 changes: 16 additions & 11 deletions popcorn/test/test_views.py
Expand Up @@ -75,7 +75,7 @@ def submit(self, compress, header):
f_in = open(submission_file, 'rb')
if compress:
f = cStringIO.StringIO()
g = gzip.GzipFile(mode='wb', fileobj=f)
g = gzip.GzipFile(mode='wb', fileobj=f)
g.writelines(f_in)
g.close()
f_in.close()
Expand All @@ -84,7 +84,7 @@ def submit(self, compress, header):
f = f_in
if header:
return self.app.post('/', data=dict(popcorn=(f, 'popcorn.txt.gz')),
headers={'Content-Encoding': 'gzip', })
headers={'Content-Encoding': 'gzip', })
else:
return self.app.post('/', data=dict(popcorn=(f, 'popcorn.txt')))

Expand All @@ -103,7 +103,8 @@ def test_submission_plaintext_without_header(self):
def test_index_json(self):
self.submit(compress=False, header=False)
with app.test_request_context(
path='/', method='GET', headers=[('Accept', 'application/json')]):
path='/', method='GET',
headers=[('Accept', 'application/json')]):
response = app.dispatch_request()
self.assertEqual(json.loads(response.data), {
"distro_packages": "[[\"openSUSE\", 1285]]",
Expand All @@ -128,14 +129,14 @@ def test_index_json(self):
def test_vendor_json(self):
self.submit(compress=False, header=False)
with app.test_request_context(
path='/vendor/openSUSE', method='GET',
headers=[('Accept', 'application/json')]):
path='/vendor/openSUSE', method='GET',
headers=[('Accept', 'application/json')]):
response = app.dispatch_request()
self.assertEqual(json.loads(response.data), {
"vendor": {
"vendor_name": "openSUSE",
"vendor_url": "openSUSE"
}})
"vendor": {
"vendor_name": "openSUSE",
"vendor_url": "openSUSE"
}})
self.assertEqual(response.headers['Content-Type'],
'application/json')

Expand Down Expand Up @@ -164,7 +165,9 @@ def test_system_json(self):
def test_package_json(self):
self.submit(compress=False, header=False)
with app.test_request_context(path='/package/sed/4.2.1/5.1.2/x86_64',
method='GET', headers=[('Accept', 'application/json')]):
method='GET',
headers=[('Accept', 'application/json')]
):
response = app.dispatch_request()
self.assertEqual(json.loads(response.data), {
"packages": [{
Expand Down Expand Up @@ -197,7 +200,9 @@ def test_package_json(self):
def test_distro_json(self):
self.submit(compress=False, header=False)
with app.test_request_context(path='/distro/openSUSE_12.1',
method='GET', headers=[('Accept', 'application/json')]):
method='GET',
headers=[('Accept', 'application/json')]
):
response = app.dispatch_request()
self.assertEqual(json.loads(response.data), {
"distro": {
Expand Down
22 changes: 14 additions & 8 deletions popcorn/views.py
Expand Up @@ -50,8 +50,13 @@ def index():
# XXX think about moving this to the model
distro_packages = db_session.query(
Distro.distro_name, func.count(SubmissionPackage.pkg_name)
).select_from(SubmissionPackage).join(System).join(Distro
).group_by(Distro.distro_name).all()
).select_from(
SubmissionPackage
).join(
System
).join(
Distro
).group_by(Distro.distro_name).all()

# transform the list of tuples returned by SQLA into a nested JS array
distro_packages = json.dumps(distro_packages)
Expand Down Expand Up @@ -140,19 +145,20 @@ def package(name, version, release, arch, epoch=''):
abort(404)

pkg_statuses = db_session.query(
SubmissionPackage.pkg_status, func.count(SubmissionPackage.pkg_status)
).filter_by(
SubmissionPackage.pkg_status,
func.count(SubmissionPackage.pkg_status)
).filter_by(
pkg_name=name, pkg_version=version, pkg_release=release,
pkg_epoch=epoch, pkg_arch=arch
).group_by(
SubmissionPackage.pkg_status).all()
).group_by(
SubmissionPackage.pkg_status).all()
statuses = dict()
for k, v in pkg_statuses:
statuses[k] = v
print statuses

return dict(generic_package=pkgs[0].serialize, packages=[i.serialize
for i in pkgs], **statuses)
return dict(generic_package=pkgs[0].serialize,
packages=[i.serialize for i in pkgs], **statuses)


@app.route('/distro/<name>_<version>')
Expand Down

0 comments on commit 258945c

Please sign in to comment.