From 37e6ff0d6e359ded679424c09083ea5b9cdb6177 Mon Sep 17 00:00:00 2001 From: Mike Taylor Date: Mon, 14 Dec 2015 16:14:54 -0600 Subject: [PATCH 1/7] Issue #860. eslint fixes for Gruntfile.js --- Gruntfile.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Gruntfile.js b/Gruntfile.js index 8bd1ab808..90de471a3 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -2,7 +2,7 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -module.exports = function (grunt) { +module.exports = function(grunt) { grunt.initConfig({ pkg: grunt.file.readJSON('package.json'), jsPath: 'webcompat/static/js', @@ -19,7 +19,7 @@ module.exports = function (grunt) { grunt.loadTasks('grunt-tasks'); // load all grunt tasks - require('load-grunt-tasks')(grunt) + require('load-grunt-tasks')(grunt); // Default task. grunt.registerTask('default', [ From 1a6d060dc7c2ccf82d316a33b130cfedcaacb53e Mon Sep 17 00:00:00 2001 From: Mike Taylor Date: Mon, 14 Dec 2015 16:23:21 -0600 Subject: [PATCH 2/7] Issue #860. eslint fixes for grunt-tasks/* --- grunt-tasks/cmq.js | 16 ++--- grunt-tasks/concat.js | 128 ++++++++++++++++++++-------------------- grunt-tasks/cssmin.js | 24 ++++---- grunt-tasks/cssnext.js | 12 ++-- grunt-tasks/eslint.js | 11 ++-- grunt-tasks/imagemin.js | 4 +- grunt-tasks/uglify.js | 50 ++++++++-------- grunt-tasks/watch.js | 18 +++--- 8 files changed, 132 insertions(+), 131 deletions(-) diff --git a/grunt-tasks/cmq.js b/grunt-tasks/cmq.js index 0f4fbc636..171fdffec 100644 --- a/grunt-tasks/cmq.js +++ b/grunt-tasks/cmq.js @@ -4,13 +4,13 @@ module.exports = function(grunt) { grunt.config('cmq', { - options: { - log: true - }, - your_target: { - files: { - '<%= cssPath %>' : ['<%= cssPath %>/webcompat.dev.css'] - } + options: { + log: true + }, + your_target: { + files: { + '<%= cssPath %>' : ['<%= cssPath %>/webcompat.dev.css'] } - }); + } + }); }; diff --git a/grunt-tasks/concat.js b/grunt-tasks/concat.js index 3763801c5..5e14c6a65 100644 --- a/grunt-tasks/concat.js +++ b/grunt-tasks/concat.js @@ -4,68 +4,68 @@ module.exports = function(grunt) { grunt.config('concat', { - options: { - banner: '<%= banner %>', - stripBanners: false - }, - dist: { - src: [ - '<%= jsPath %>/vendor/jquery-1.11.2.min.js', - '<%= jsPath %>/vendor/lodash.custom.min.js', - '<%= jsPath %>/vendor/backbone-min.js', - '<%= jsPath %>/vendor/moment-min.js', - '<%= jsPath %>/vendor/prism.js', - '<%= jsPath %>/vendor/markdown-it.js', - '<%= jsPath %>/vendor/markdown-it-emoji-1.0.0.js', - '<%= jsPath %>/vendor/markdown-it-sanitizer-0.4.1.js', - '<%= jsPath %>/vendor/mousetrap-min.js', - '<%= jsPath %>/vendor/backbone.mousetrap.js', - '<%= jsPath %>/lib/flash-message.js', - '<%= jsPath %>/lib/homepage.js', - '<%= jsPath %>/lib/bugform.js' - ], - dest: '<%= jsPath %>/<%= pkg.name %>.js' - }, - diagnose: { - src: [ - '<%= jsPath %>/lib/models/label-list.js', - '<%= jsPath %>/lib/labels.js', - '<%= jsPath %>/lib/models/issue.js', - '<%= jsPath %>/lib/diagnose.js' - ], - dest: '<%= jsPath %>/diagnose.js' - }, - issues: { - src: [ - '<%= jsPath %>/vendor/qr.min.js', - '<%= jsPath %>/lib/models/label-list.js', - '<%= jsPath %>/lib/labels.js', - '<%= jsPath %>/lib/models/issue.js', - '<%= jsPath %>/lib/models/comment.js', - '<%= jsPath %>/lib/comments.js', - '<%= jsPath %>/lib/qrcode.js', - '<%= jsPath %>/lib/issues.js', - ], - dest: '<%= jsPath %>/issues.js' - }, - issueList: { - src: [ - '<%= jsPath %>/lib/models/label-list.js', - '<%= jsPath %>/lib/labels.js', - '<%= jsPath %>/lib/models/issue.js', - '<%= jsPath %>/lib/mixins/pagination.js', - '<%= jsPath %>/lib/issue-list.js' - ], - dest: '<%= jsPath %>/issue-list.js' - }, - userActivity: { - src: [ - '<%= jsPath %>/lib/models/label-list.js', - '<%= jsPath %>/lib/models/issue.js', - '<%= jsPath %>/lib/mixins/pagination.js', - '<%= jsPath %>/lib/user-activity.js' - ], - dest: '<%= jsPath %>/user-activity.js' - } - }); + options: { + banner: '<%= banner %>', + stripBanners: false + }, + dist: { + src: [ + '<%= jsPath %>/vendor/jquery-1.11.2.min.js', + '<%= jsPath %>/vendor/lodash.custom.min.js', + '<%= jsPath %>/vendor/backbone-min.js', + '<%= jsPath %>/vendor/moment-min.js', + '<%= jsPath %>/vendor/prism.js', + '<%= jsPath %>/vendor/markdown-it.js', + '<%= jsPath %>/vendor/markdown-it-emoji-1.0.0.js', + '<%= jsPath %>/vendor/markdown-it-sanitizer-0.4.1.js', + '<%= jsPath %>/vendor/mousetrap-min.js', + '<%= jsPath %>/vendor/backbone.mousetrap.js', + '<%= jsPath %>/lib/flash-message.js', + '<%= jsPath %>/lib/homepage.js', + '<%= jsPath %>/lib/bugform.js' + ], + dest: '<%= jsPath %>/<%= pkg.name %>.js' + }, + diagnose: { + src: [ + '<%= jsPath %>/lib/models/label-list.js', + '<%= jsPath %>/lib/labels.js', + '<%= jsPath %>/lib/models/issue.js', + '<%= jsPath %>/lib/diagnose.js' + ], + dest: '<%= jsPath %>/diagnose.js' + }, + issues: { + src: [ + '<%= jsPath %>/vendor/qr.min.js', + '<%= jsPath %>/lib/models/label-list.js', + '<%= jsPath %>/lib/labels.js', + '<%= jsPath %>/lib/models/issue.js', + '<%= jsPath %>/lib/models/comment.js', + '<%= jsPath %>/lib/comments.js', + '<%= jsPath %>/lib/qrcode.js', + '<%= jsPath %>/lib/issues.js', + ], + dest: '<%= jsPath %>/issues.js' + }, + issueList: { + src: [ + '<%= jsPath %>/lib/models/label-list.js', + '<%= jsPath %>/lib/labels.js', + '<%= jsPath %>/lib/models/issue.js', + '<%= jsPath %>/lib/mixins/pagination.js', + '<%= jsPath %>/lib/issue-list.js' + ], + dest: '<%= jsPath %>/issue-list.js' + }, + userActivity: { + src: [ + '<%= jsPath %>/lib/models/label-list.js', + '<%= jsPath %>/lib/models/issue.js', + '<%= jsPath %>/lib/mixins/pagination.js', + '<%= jsPath %>/lib/user-activity.js' + ], + dest: '<%= jsPath %>/user-activity.js' + } + }); }; diff --git a/grunt-tasks/cssmin.js b/grunt-tasks/cssmin.js index e1ad3b61a..f84828c46 100644 --- a/grunt-tasks/cssmin.js +++ b/grunt-tasks/cssmin.js @@ -4,17 +4,17 @@ module.exports = function(grunt) { grunt.config('cssmin', { - options: { - banner: '<%= banner %>' - }, - combine: { - files: { - // output - '<%= cssPath %>/webcompat.min.css': [ - // input - '<%= cssPath %>/webcompat.dev.css' - ] - } + options: { + banner: '<%= banner %>' + }, + combine: { + files: { + // output + '<%= cssPath %>/webcompat.min.css': [ + // input + '<%= cssPath %>/webcompat.dev.css' + ] } - }); + } + }); }; diff --git a/grunt-tasks/cssnext.js b/grunt-tasks/cssnext.js index 92f92d75b..1874b5283 100644 --- a/grunt-tasks/cssnext.js +++ b/grunt-tasks/cssnext.js @@ -8,12 +8,12 @@ module.exports = function(grunt) { sourcemap: true, url : false, browsers: ['ff >= 4', 'ie >= 8', 'safari >= 5.1', 'opera >= 12', 'chrome >=10'], - import: { path: ["node_modules"] } + import: { path: ['node_modules'] } }, - dist: { - files: { - '<%= cssPath %>/webcompat.dev.css': '<%= cssPath %>/development/main.css' - } + dist: { + files: { + '<%= cssPath %>/webcompat.dev.css': '<%= cssPath %>/development/main.css' } - }); + } + }); }; diff --git a/grunt-tasks/eslint.js b/grunt-tasks/eslint.js index 096a7fd0f..0a7d6c32d 100644 --- a/grunt-tasks/eslint.js +++ b/grunt-tasks/eslint.js @@ -4,9 +4,10 @@ module.exports = function(grunt) { grunt.config('eslint', { - target: [ - '<%= jsPath %>/lib/*.js', - 'tests/functional/*.js' - ] - }); + target: [ + '<%= jsPath %>/lib/*.js', + 'grunt-tasks/*.js', + 'tests/functional/*.js' + ] + }); }; \ No newline at end of file diff --git a/grunt-tasks/imagemin.js b/grunt-tasks/imagemin.js index 78fdf0f79..b404b394b 100644 --- a/grunt-tasks/imagemin.js +++ b/grunt-tasks/imagemin.js @@ -24,7 +24,7 @@ module.exports = function(grunt) { cwd: '<%= imgPath %>/', src: ['*.jpg'], dest: '<%= imgPath %>/' - }] - } + }] + } }); }; diff --git a/grunt-tasks/uglify.js b/grunt-tasks/uglify.js index 13f7a5758..7411a2363 100644 --- a/grunt-tasks/uglify.js +++ b/grunt-tasks/uglify.js @@ -4,29 +4,29 @@ module.exports = function(grunt) { grunt.config('uglify', { - options: { - banner: '<%= banner %>', - mangle: false - }, - dist: { - src: '<%= concat.dist.dest %>', - dest: '<%= jsPath %>/<%= pkg.name %>.min.js' - }, - issues: { - src: '<%= concat.issues.dest %>', - dest: '<%= jsPath %>/issues.min.js' - }, - issueList: { - src: '<%= concat.issueList.dest %>', - dest: '<%= jsPath %>/issue-list.min.js' - }, - userActivity: { - src: '<%= concat.userActivity.dest %>', - dest: '<%= jsPath %>/user-activity.min.js' - }, - diagnose: { - src: '<%= concat.diagnose.dest %>', - dest: '<%= jsPath %>/diagnose.min.js' - } - }); + options: { + banner: '<%= banner %>', + mangle: false + }, + dist: { + src: '<%= concat.dist.dest %>', + dest: '<%= jsPath %>/<%= pkg.name %>.min.js' + }, + issues: { + src: '<%= concat.issues.dest %>', + dest: '<%= jsPath %>/issues.min.js' + }, + issueList: { + src: '<%= concat.issueList.dest %>', + dest: '<%= jsPath %>/issue-list.min.js' + }, + userActivity: { + src: '<%= concat.userActivity.dest %>', + dest: '<%= jsPath %>/user-activity.min.js' + }, + diagnose: { + src: '<%= concat.diagnose.dest %>', + dest: '<%= jsPath %>/diagnose.min.js' + } + }); }; diff --git a/grunt-tasks/watch.js b/grunt-tasks/watch.js index 244d5f8df..bbe3232d8 100644 --- a/grunt-tasks/watch.js +++ b/grunt-tasks/watch.js @@ -4,13 +4,13 @@ module.exports = function(grunt) { grunt.config('watch', { - css:{ - files: '<%= cssPath %>/development/**/*.css', - tasks: ['cssnext'] - }, - script:{ - files: '<%= jshint.beforeconcat %>', - tasks: ['jshint:beforeconcat'] - } - }); + css:{ + files: '<%= cssPath %>/development/**/*.css', + tasks: ['cssnext'] + }, + script:{ + files: '<%= jshint.beforeconcat %>', + tasks: ['jshint:beforeconcat'] + } + }); }; From 7e721f5ef4a6f9141eacbc3b0e9a36dc4c250dcd Mon Sep 17 00:00:00 2001 From: Mike Taylor Date: Mon, 14 Dec 2015 16:23:43 -0600 Subject: [PATCH 3/7] Issue #860. Add missing require/module global to eslintrc. --- .eslintrc | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.eslintrc b/.eslintrc index 2dd381448..24f654f5d 100644 --- a/.eslintrc +++ b/.eslintrc @@ -14,12 +14,14 @@ markdownitEmoji: true, markdownitSanitizer: true, md: true, + module: true, moment: true, Mousetrap: true, PaginationMixin: true, Prism: true, qr: true, repoPath: true, + require: true, wcEvents: true }, "rules": { From e3d4ed4b2a34ff89e90124bf4ba6a46ef5f56f83 Mon Sep 17 00:00:00 2001 From: Mike Taylor Date: Mon, 14 Dec 2015 16:31:56 -0600 Subject: [PATCH 4/7] Issue #860. Fixes for adding mixins to eslint task. --- grunt-tasks/eslint.js | 1 + webcompat/static/js/lib/mixins/pagination.js | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/grunt-tasks/eslint.js b/grunt-tasks/eslint.js index 0a7d6c32d..a1445814e 100644 --- a/grunt-tasks/eslint.js +++ b/grunt-tasks/eslint.js @@ -6,6 +6,7 @@ module.exports = function(grunt) { grunt.config('eslint', { target: [ '<%= jsPath %>/lib/*.js', + '<%= jsPath %>/lib/mixins/*.js', 'grunt-tasks/*.js', 'tests/functional/*.js' ] diff --git a/webcompat/static/js/lib/mixins/pagination.js b/webcompat/static/js/lib/mixins/pagination.js index 2f150be94..0179aa841 100644 --- a/webcompat/static/js/lib/mixins/pagination.js +++ b/webcompat/static/js/lib/mixins/pagination.js @@ -57,6 +57,7 @@ updateModelParams() Check out issueList.IssueView for an example. */ +/* exported PaginationMixin */ function PaginationMixin() { this.initMixin = function(hostView, hostModel, parentContainerEl) { this.view = hostView; @@ -159,4 +160,4 @@ function PaginationMixin() { }; return this; -}; \ No newline at end of file +} \ No newline at end of file From 908cebefdac2ea3bc6475e43c9d5f7021dc8204b Mon Sep 17 00:00:00 2001 From: Mike Taylor Date: Mon, 14 Dec 2015 16:36:53 -0600 Subject: [PATCH 5/7] Issue #860. eslint fixes for adding models directory to grunt task. --- grunt-tasks/eslint.js | 1 + webcompat/static/js/lib/models/issue.js | 3 +- webcompat/static/js/lib/models/label-list.js | 30 ++++++++++---------- 3 files changed, 18 insertions(+), 16 deletions(-) diff --git a/grunt-tasks/eslint.js b/grunt-tasks/eslint.js index a1445814e..bcca993b0 100644 --- a/grunt-tasks/eslint.js +++ b/grunt-tasks/eslint.js @@ -7,6 +7,7 @@ module.exports = function(grunt) { target: [ '<%= jsPath %>/lib/*.js', '<%= jsPath %>/lib/mixins/*.js', + '<%= jsPath %>/lib/models/*.js', 'grunt-tasks/*.js', 'tests/functional/*.js' ] diff --git a/webcompat/static/js/lib/models/issue.js b/webcompat/static/js/lib/models/issue.js index d92af88c3..81a23adc4 100644 --- a/webcompat/static/js/lib/models/issue.js +++ b/webcompat/static/js/lib/models/issue.js @@ -164,7 +164,8 @@ issueList.IssueCollection = Backbone.Collection.extend({ if (rels) { var keys = rels[1].match(keysRegExp); var source = sourceRegExp.exec(entry)[1]; - var k, kLength = keys.length; + var k; + var kLength = keys.length; for (k = 0; k < kLength; k += 1) { result[keys[k]] = source; } diff --git a/webcompat/static/js/lib/models/label-list.js b/webcompat/static/js/lib/models/label-list.js index 6ef37afe5..c308b97fe 100644 --- a/webcompat/static/js/lib/models/label-list.js +++ b/webcompat/static/js/lib/models/label-list.js @@ -2,7 +2,7 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - var issues = issues || {}; +var issues = issues || {}; /** * A LabelList is a list of labels. @@ -31,17 +31,17 @@ issues.LabelList = Backbone.Model.extend({ // The templating engine needs objects that have JS properties, it won't call // get('labels'). Setting a property here makes sure we can pass the model // directly to a template() method - this.on('change:labels', function(){ + this.on('change:labels', function() { this.labels = this.get('labels'); }); // if we're initialized with {labels:array-of-objects}, process the data var inputLabelData = this.get('labels'); this.set('labels', []); - if(inputLabelData) { + if (inputLabelData) { this.parse(inputLabelData); } else { // No input data, let's fetch it from a URL - if(!this.get('url')) { + if (!this.get('url')) { // default to "all labels" URL this.set('url', this.get('defaultLabelURL')); } @@ -49,23 +49,23 @@ issues.LabelList = Backbone.Model.extend({ this.fetch(headersBag); // This will trigger parse() on response } }, - parse: function(labelsArray){ + parse: function(labelsArray) { var list = []; var namespaceMap = {}; - for(var i = 0, matches, theLabel; i < labelsArray.length; i++){ + for (var i = 0, matches, theLabel; i < labelsArray.length; i++) { // We assume we either have an object with .name or an array of strings theLabel = labelsArray[i].name || labelsArray[i]; matches = theLabel.match(this.get('namespaceRegex')); - if(matches) { + if (matches) { namespaceMap[matches[2]] = matches[1]; list[i] = { 'name': matches[2], 'url': labelsArray[i].url, 'color': labelsArray[i].color, 'remoteName': matches[0] - }; - }else { - if(typeof theLabel === 'object') { + }; + } else { + if (typeof theLabel === 'object') { list[i] = labelsArray[i]; list[i].remoteName = list[i].name; } else { @@ -79,15 +79,15 @@ issues.LabelList = Backbone.Model.extend({ // toPrefixed takes a local label name and maps it // to the prefixed repository form. Also handles an array // of label names (Note: not arrays of objects) - toPrefixed: function (input) { + toPrefixed: function(input) { if (typeof input === 'string') { - if(issues.allLabels.get('namespaceMap')[input]) { + if (issues.allLabels.get('namespaceMap')[input]) { return issues.allLabels.get('namespaceMap')[input] + '-' + input; } return input; } else { // This is not a string, we assume it's an array - return input.map(function(label){ + return input.map(function(label) { return issues.allLabels.toPrefixed(label); }); } @@ -96,13 +96,13 @@ issues.LabelList = Backbone.Model.extend({ return this.get('url'); }, // Returns a simple array of unprefixed labels - strings only - toArray: function(){ + toArray: function() { return _.pluck(this.get('labels'), 'name'); }, // To save the model to the server, we need to make // sure we apply the prefixes the server expects. // The JSON serialization will take care of it. - toJSON: function(){ + toJSON: function() { var labelsArray = _.pluck(this.get('labels'), 'name'); return issues.allLabels.toPrefixed(labelsArray); } From 7c0a864fffd65684e73b84a3a5558c9274a26bcb Mon Sep 17 00:00:00 2001 From: Mike Taylor Date: Mon, 14 Dec 2015 17:10:29 -0600 Subject: [PATCH 6/7] Issue #860. Minor style tweaks to make pep8 happy. --- config.py.example | 8 ++++---- requirements.txt | 1 + tests/test_api_urls.py | 6 ++++-- tests/test_helpers.py | 13 ++++++------- tests/test_uploads.py | 2 +- tests/test_urls.py | 2 +- webcompat/db/__init__.py | 14 +++++++------- webcompat/form.py | 10 +++++----- webcompat/helpers.py | 18 ++++++++++-------- webcompat/issues.py | 2 +- webcompat/webhooks/helpers.py | 1 + 11 files changed, 41 insertions(+), 36 deletions(-) diff --git a/config.py.example b/config.py.example index e256495eb..ad1bc10d3 100644 --- a/config.py.example +++ b/config.py.example @@ -64,8 +64,8 @@ if not PRODUCTION: LOG_FILE = '/tmp/webcompat.log' LOG_FMT = '%(asctime)s %(levelname)s: %(message)s [in %(pathname)s:%(lineno)d]' -# Get the client id and client secret from GitHub if you're part of the webcompat -# organization. Otherwise, create your own test and production applications, +# Get the client id and client secret from GitHub if you're part of the +# webcompat org. Otherwise, create your own test and production applications, # and take note of the client id and client secret GitHub gives you. # # [1] @@ -84,7 +84,7 @@ elif DEVELOPMENT: else: # We're running on localhost, use the test application GITHUB_CLIENT_ID = os.environ.get('FAKE_ID') or "" - GITHUB_CLIENT_SECRET = os.environ.get('FAKE_SECRET') or "" + GITHUB_CLIENT_SECRET = os.environ.get('FAKE_SECRET') or "" GITHUB_CALLBACK_URL = "http://localhost:5000/callback" # GiHub Issues repo URI @@ -93,7 +93,7 @@ if PRODUCTION: else: # Development and Local instances use the same test repo # Expects a string like "//issues", e.g., - # ISSUES_REPO_URI = os.environ.get('ISSUES_REPO_URI') or "miketaylr/test-repo/issues" + # ISSUES_REPO_URI = os.environ.get('ISSUES_REPO_URI') or "foo/bar/issues" ISSUES_REPO_URI = os.environ.get('ISSUES_REPO_URI') or "" # This is the oauth token we use to report issues on behalf of people diff --git a/requirements.txt b/requirements.txt index 91ad51e5e..77dde230a 100644 --- a/requirements.txt +++ b/requirements.txt @@ -9,3 +9,4 @@ WTForms==2.0.2 ua-parser==0.5.0 nose==1.3.1 blinker==1.3 +pep8==1.6.2 diff --git a/tests/test_api_urls.py b/tests/test_api_urls.py index ec4c1d582..206a3ee4a 100644 --- a/tests/test_api_urls.py +++ b/tests/test_api_urls.py @@ -73,12 +73,14 @@ def test_api_labels_without_auth(self): def test_api_set_labels_without_auth(self): '''API setting labels without auth returns JSON 403 error code.''' - rv = self.app.post('/api/issues/1/labels', environ_base=headers, data='[]') + rv = self.app.post('/api/issues/1/labels', + environ_base=headers, data='[]') self.assertEqual(rv.status_code, 403) def test_api_user_activity_without_auth(self): '''API access to user activity without auth returns JSON 401.''' - rv = self.app.get('/api/issues/miketaylr/creator', environ_base=headers) + rv = self.app.get('/api/issues/miketaylr/creator', + environ_base=headers) json_body = json.loads(rv.data) self.assertEqual(rv.status_code, 401) self.assertEqual(rv.content_type, 'application/json') diff --git a/tests/test_helpers.py b/tests/test_helpers.py index 5ed271ae0..95c638290 100644 --- a/tests/test_helpers.py +++ b/tests/test_helpers.py @@ -22,13 +22,12 @@ from webcompat.helpers import sanitize_link - -ACCESS_TOKEN_LINK = '; rel="next", ; rel="last", ; rel="first", ; rel="prev"' -GITHUB_ISSUES_LINK_HEADER = '; rel="next", ; rel="last", ; rel="first", ; rel="prev"' -GITHUB_SEARCH_LINK_HEADER = '; rel="next", ; rel="last"' -REWRITTEN_ISSUES_LINK_HEADER = '; rel="next", ; rel="last", ; rel="first", ; rel="prev"' -REWRITTEN_SEARCH_LINK_HEADER = '; rel="next", ; rel="last"' -PARSED_LINKED_HEADERS = [{'link': 'https://api.github.com/repositories/17839063/issues?per_page=50&page=3', 'rel': 'next'}, {'link': 'https://api.github.com/repositories/17839063/issues?per_page=50&page=4', 'rel': 'last'}, {'link': 'https://api.github.com/repositories/17839063/issues?per_page=50&page=1', 'rel': 'first'}, {'link': 'https://api.github.com/repositories/17839063/issues?per_page=50&page=1', 'rel': 'prev'}] +ACCESS_TOKEN_LINK = '; rel="next", ; rel="last", ; rel="first", ; rel="prev"' # nopep8 +GITHUB_ISSUES_LINK_HEADER = '; rel="next", ; rel="last", ; rel="first", ; rel="prev"' # nopep8 +GITHUB_SEARCH_LINK_HEADER = '; rel="next", ; rel="last"' # nopep8 +REWRITTEN_ISSUES_LINK_HEADER = '; rel="next", ; rel="last", ; rel="first", ; rel="prev"' # nopep8 +REWRITTEN_SEARCH_LINK_HEADER = '; rel="next", ; rel="last"' # nopep8 +PARSED_LINKED_HEADERS = [{'link': 'https://api.github.com/repositories/17839063/issues?per_page=50&page=3', 'rel': 'next'}, {'link': 'https://api.github.com/repositories/17839063/issues?per_page=50&page=4', 'rel': 'last'}, {'link': 'https://api.github.com/repositories/17839063/issues?per_page=50&page=1', 'rel': 'first'}, {'link': 'https://api.github.com/repositories/17839063/issues?per_page=50&page=1', 'rel': 'prev'}] # nopep8 class TestHelpers(unittest.TestCase): diff --git a/tests/test_uploads.py b/tests/test_uploads.py index 9a61556ce..ebf54b358 100644 --- a/tests/test_uploads.py +++ b/tests/test_uploads.py @@ -23,7 +23,7 @@ class TestUploads(unittest.TestCase): - # modified from http://prschmid.blogspot.com/2013/05/unit-testing-flask-file-uploads-without.html + # modified from http://prschmid.blogspot.com/2013/05/unit-testing-flask-file-uploads-without.html # nopep8 def setUp(self): app.config['TESTING'] = True self.app = app diff --git a/tests/test_urls.py b/tests/test_urls.py index 56247f4d7..cdd128fec 100644 --- a/tests/test_urls.py +++ b/tests/test_urls.py @@ -107,7 +107,7 @@ def test_issues_new(self): {u'labels': [{u'name': u'status-sitewait'}], u'title': u"fake bug 5", u'id': 5}] - result = '[{"labels": [{"name": "bug"}, {"name": "help wanted"}], "id": 0, "title": "fake bug 0"}, {"labels": [], "id": 1, "title": "fake bug 1"}]' + result = '[{"labels": [{"name": "bug"}, {"name": "help wanted"}], "id": 0, "title": "fake bug 0"}, {"labels": [], "id": 1, "title": "fake bug 1"}]' # nopep8 self.assertEqual(filter_new(issues), result) def test_labeler_webhook(self): diff --git a/webcompat/db/__init__.py b/webcompat/db/__init__.py index 1708d91da..a614d07bb 100644 --- a/webcompat/db/__init__.py +++ b/webcompat/db/__init__.py @@ -18,21 +18,21 @@ from webcompat import app -session_engine = create_engine('sqlite:///' + os.path.join(app.config['BASE_DIR'], - 'session.db')) - +session_engine = create_engine('sqlite:///' + os.path.join( + app.config['BASE_DIR'], 'session.db')) session_db = scoped_session(sessionmaker(autocommit=False, autoflush=False, bind=session_engine)) -issue_engine = create_engine('sqlite:///' + os.path.join(app.config['BASE_DIR'], - 'issues.db')) +issue_engine = create_engine('sqlite:///' + os.path.join( + app.config['BASE_DIR'], 'issues.db')) issue_db = scoped_session(sessionmaker(autocommit=False, - autoflush=False, - bind=issue_engine)) + autoflush=False, + bind=issue_engine)) IssueBase = declarative_base() IssueBase.query = issue_db.query_property() + class WCIssue(IssueBase): __tablename__ = 'webcompat_issues' diff --git a/webcompat/form.py b/webcompat/form.py index fbb82cbe7..bf5a76dd8 100644 --- a/webcompat/form.py +++ b/webcompat/form.py @@ -27,12 +27,12 @@ SCHEMES = ('http://', 'https://') problem_choices = [ - (u'detection_bug', u'Desktop site instead of mobile site'), + (u'detection_bug', u'Desktop site instead of mobile site'), (u'mobile_site_bug', u'Mobile site is not usable'), - (u'video_bug', u'Video doesn\'t play'), - (u'layout_bug', u'Layout is messed up'), - (u'text_bug', u'Text is not visible'), - (u'unknown_bug', u'Something else - I\'ll add details below') + (u'video_bug', u'Video doesn\'t play'), + (u'layout_bug', u'Layout is messed up'), + (u'text_bug', u'Text is not visible'), + (u'unknown_bug', u'Something else - I\'ll add details below') ] url_message = u'A URL is required.' diff --git a/webcompat/helpers.py b/webcompat/helpers.py index 6c6c7e328..e76173c53 100644 --- a/webcompat/helpers.py +++ b/webcompat/helpers.py @@ -4,7 +4,7 @@ # License, v. 2.0. If a copy of the MPL was not distributed with this # file, You can obtain one at http://mozilla.org/MPL/2.0/. -import datetime +from datetime import datetime import hashlib import json import math @@ -29,7 +29,7 @@ 'User-Agent': 'webcompat/webcompat-bot'} HOST_WHITELIST = ('webcompat.com', 'staging.webcompat.com', '127.0.0.1', 'localhost') -FIXTURES_PATH = os.getcwd() +'/tests/fixtures' +FIXTURES_PATH = os.getcwd() + '/tests/fixtures' STATIC_PATH = os.getcwd() + '/webcompat/static' JSON_MIME = 'application/json' REPO_URI = app.config['ISSUES_REPO_URI'] @@ -40,7 +40,7 @@ @app.template_filter('format_delta') def format_delta_filter(timestamp): '''Jinja2 fiter to format a unix timestamp to a time delta string.''' - delta = datetime.datetime.now() - datetime.datetime.fromtimestamp(timestamp) + delta = datetime.now() - datetime.fromtimestamp(timestamp) return format_timedelta(delta, locale='en_US') @@ -82,7 +82,7 @@ def format_delta_seconds(timestamp): The timedelta is a negative float, so we round up the absolute value and cast it to an integer to be more human friendly. ''' - delta = datetime.datetime.now() - datetime.datetime.fromtimestamp(timestamp) + delta = datetime.now() - datetime.fromtimestamp(timestamp) seconds = delta.total_seconds() return abs(int(math.ceil(seconds))) @@ -156,7 +156,8 @@ def get_response_headers(response): 'content-type': JSON_MIME} if response.headers.get('link'): - headers['link'] = rewrite_and_sanitize_link(response.headers.get('link')) + headers['link'] = rewrite_and_sanitize_link( + response.headers.get('link')) return headers @@ -235,8 +236,8 @@ def normalize_api_params(params): def rewrite_links(link_header): '''Rewrites Link header Github API endpoints to our own. - ; rel="next", - ; rel="last" + ; rel="next", + ; rel="last" is transformed into @@ -250,7 +251,8 @@ def rewrite_links(link_header): if api_path.strip().startswith('https://api.github.com/repositories'): data['link'] = endpoint_path.replace('issues?', '/api/issues?') if api_path.strip().startswith('https://api.github.com/search'): - data['link'] = endpoint_path.replace('issues?', '/api/issues/search?') + data['link'] = endpoint_path.replace('issues?', + '/api/issues/search?') return format_link_header(header_link_data) diff --git a/webcompat/issues.py b/webcompat/issues.py index 900f87a07..122e2c172 100644 --- a/webcompat/issues.py +++ b/webcompat/issues.py @@ -22,7 +22,7 @@ def report_issue(form, proxy=False): path = 'repos/{0}'.format(REPO_URI) if proxy: return proxy_request('post', path, - data=json.dumps(build_formdata(form))) + data=json.dumps(build_formdata(form))) else: return github.post(path, build_formdata(form)) diff --git a/webcompat/webhooks/helpers.py b/webcompat/webhooks/helpers.py index 90260fcde..3c462f9bf 100644 --- a/webcompat/webhooks/helpers.py +++ b/webcompat/webhooks/helpers.py @@ -13,6 +13,7 @@ from webcompat.db import WCIssue from webcompat.helpers import extract_url + def api_post(endpoint, payload, issue): '''Helper method to post junk to GitHub.''' headers = { From af0b73f1bc01bc0c9b8e2e0d3c33235d379a60c2 Mon Sep 17 00:00:00 2001 From: Mike Taylor Date: Mon, 14 Dec 2015 17:12:25 -0600 Subject: [PATCH 7/7] Issue #860. Add pep8 linting to .travis.yml (JS is part of grunt) --- .travis.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.travis.yml b/.travis.yml index f3d5dbf40..f044a5954 100644 --- a/.travis.yml +++ b/.travis.yml @@ -34,10 +34,13 @@ install: - travis_retry npm install - travis_retry pip install -r requirements.txt --download-cache $HOME/.pip-cache - cp config.py.example config.py + # lint python + - pep8 --ignore=E402 webcompat/ tests/ config.py.example - python run.py -t & before_script: - "sleep 2" + # lint JS in default eslint task - grunt # now run the tests!