Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
From 817df78e5995b12908f5b758ccb68ea14f1f63b8 Mon Sep 17 00:00:00 2001
From: Mike Taylor <miketaylr@gmail.com>
Date: Thu, 26 Apr 2018 22:58:14 -0500
Subject: [PATCH] Issue #2288. Add "0.json" fixture.
---
.gitignore | 1 -
tests/fixtures/api/issues/0.json | 74 ++++++++++++++++++++++++++++++++++++++++
2 files changed, 74 insertions(+), 1 deletion(-)
create mode 100644 tests/fixtures/api/issues/0.json
diff --git a/.gitignore b/.gitignore
index 78afb1a8..b57b20ee 100644
--- a/.gitignore
+++ b/.gitignore
@@ -17,7 +17,6 @@ tmp/
# The data folder contains information that shouldn't live in version control.
data/*
-tests/fixtures/api/issues/0.json
# these are our 'dist' files
# checking them into the repo is silly
diff --git a/tests/fixtures/api/issues/0.json b/tests/fixtures/api/issues/0.json
new file mode 100644
index 00000000..743459b2
--- /dev/null
+++ b/tests/fixtures/api/issues/0.json
@@ -0,0 +1,74 @@
+{
+ "_fixture": true,
+ "url": "https://api.github.com/repos/webcompat/webcompat-tests/issues/1496",
+ "repository_url": "https://api.github.com/repos/webcompat/webcompat-tests",
+ "labels_url": "https://api.github.com/repos/webcompat/webcompat-tests/issues/1496/labels{/name}",
+ "comments_url": "https://api.github.com/repos/webcompat/webcompat-tests/issues/1496/comments",
+ "events_url": "https://api.github.com/repos/webcompat/webcompat-tests/issues/1496/events",
+ "html_url": "https://github.com/webcompat/webcompat-tests/issues/1496",
+ "id": 318968166,
+ "number": 0,
+ "title": "example.com - desktop site instead of mobile site",
+ "user": {
+ "login": "miketaylr",
+ "id": 8862693,
+ "avatar_url": "https://avatars3.githubusercontent.com/u/8862693?v=4"
+ },
+ "labels": [
+ {
+ "id": 182807004,
+ "url": "https://api.github.com/repos/webcompat/webcompat-tests/labels/browser-firefox",
+ "name": "browser-firefox",
+ "color": "d4c5f9",
+ "default": false
+ }
+ ],
+ "state": "open",
+ "locked": false,
+ "assignee": null,
+ "assignees": [
+
+ ],
+ "milestone": {
+ "url": "https://api.github.com/repos/webcompat/webcompat-tests/milestones/1",
+ "html_url": "https://github.com/webcompat/webcompat-tests/milestone/1",
+ "labels_url": "https://api.github.com/repos/webcompat/webcompat-tests/milestones/1/labels",
+ "id": 2744172,
+ "number": 1,
+ "title": "needstriage",
+ "description": "Issues which needs to be triaged",
+ "creator": {
+ "login": "karlcow",
+ "id": 505230,
+ "avatar_url": "https://avatars0.githubusercontent.com/u/505230?v=4",
+ "gravatar_id": "",
+ "url": "https://api.github.com/users/karlcow",
+ "html_url": "https://github.com/karlcow",
+ "followers_url": "https://api.github.com/users/karlcow/followers",
+ "following_url": "https://api.github.com/users/karlcow/following{/other_user}",
+ "gists_url": "https://api.github.com/users/karlcow/gists{/gist_id}",
+ "starred_url": "https://api.github.com/users/karlcow/starred{/owner}{/repo}",
+ "subscriptions_url": "https://api.github.com/users/karlcow/subscriptions",
+ "organizations_url": "https://api.github.com/users/karlcow/orgs",
+ "repos_url": "https://api.github.com/users/karlcow/repos",
+ "events_url": "https://api.github.com/users/karlcow/events{/privacy}",
+ "received_events_url": "https://api.github.com/users/karlcow/received_events",
+ "type": "User",
+ "site_admin": false
+ },
+ "open_issues": 128,
+ "closed_issues": 0,
+ "state": "open",
+ "created_at": "2017-09-05T03:39:06Z",
+ "updated_at": "2018-04-30T17:21:54Z",
+ "due_on": null,
+ "closed_at": null
+ },
+ "comments": 0,
+ "created_at": "2018-04-30T17:21:54Z",
+ "updated_at": "2018-04-30T17:21:54Z",
+ "closed_at": null,
+ "author_association": "MEMBER",
+ "body": "<!-- @browser: Firefox 60.0 -->\n<!-- @ua_header: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.13; rv:60.0) Gecko/20100101 Firefox/60.0 -->\n<!-- @reported_with: web -->\n\n**URL**: http://example.com\n\n**Browser / Version**: Firefox 60.0\n**Operating System**: Mac OS X 10.13\n**Tested Another Browser**: Unknown\n\n**Problem type**: Desktop site instead of mobile site\n**Description**: Oh no a bug\n**Steps to Reproduce**:\nwowowowow\n\n\n\n_From [webcompat.com](https://webcompat.com/) with ❤️_",
+ "closed_by": null
+}
--
2.14.1
From 619284a4df8c0cf1a38180530d33daba102e4d58 Mon Sep 17 00:00:00 2001
From: Mike Taylor <miketaylr@gmail.com>
Date: Thu, 26 Apr 2018 22:42:33 -0500
Subject: [PATCH] Issue #2288. Add a @mockable_report decorator so we can
functionally test form submission.
---
.gitignore | 1 +
webcompat/helpers.py | 41 ++++++++++++++++++++++++++++++++++++++++-
webcompat/issues.py | 4 +++-
3 files changed, 44 insertions(+), 2 deletions(-)
diff --git a/.gitignore b/.gitignore
index b57b20ee..78afb1a8 100644
--- a/.gitignore
+++ b/.gitignore
@@ -17,6 +17,7 @@ tmp/
# The data folder contains information that shouldn't live in version control.
data/*
+tests/fixtures/api/issues/0.json
# these are our 'dist' files
# checking them into the repo is silly
diff --git a/webcompat/helpers.py b/webcompat/helpers.py
index 325a5ee0..7a44b08e 100644
--- a/webcompat/helpers.py
+++ b/webcompat/helpers.py
@@ -25,6 +25,7 @@ from flask import request
from flask import session
from ua_parser import user_agent_parser
+import form
from webcompat import api
from webcompat import app
from webcompat import github
@@ -382,7 +383,7 @@ def mockable_response(func):
"""Mock out API reponses with a decorator.
This allows us to send back fixture files when in TESTING mode, rather
- than making API requests over the network. See /api/endponts.py
+ than making API requests over the network. See /api/endpoints.py
for usage.
"""
@wraps(func)
@@ -407,6 +408,44 @@ def mockable_response(func):
return wrapped_func
+def mockable_report(func):
+ """Mock out an API reponse for `issues.report_issue`, if in TESTING mode.
+
+ This allows us to test form submission, always returning a special
+ issue 0 (that doesn't exist). It loads fixture data from a "zero.json"
+ template, and merges in the reported title and body, saving it to "0.json".
+
+ Note: unless you've created 0.json locally by running tests, navigating
+ there directly will 404. We don't check it into source control because
+ it can change depending on the test. But only tests should care abou this.
+ """
+ class Mocked201Response:
+ """Class to mock out the requests Reponse object that is created
+ when a new issue is created (or something close enough).
+ """
+
+ def __init__(self, *args):
+ self.form_data = args[0]
+ self.status_code = 201
+ self.headers = {'content-type': JSON_MIME}
+ self.json_data = None
+
+ def json(self):
+ with open(FIXTURES_PATH + '/api/issues/0.json', 'r') as f:
+ return json.loads(f.read())
+
+ def get(self, key):
+ """Always return 0."""
+ return 0
+
+ @wraps(func)
+ def wrapped_func(*args, **kwargs):
+ if app.config['TESTING']:
+ return Mocked201Response(*args)
+ return func(*args, **kwargs)
+ return wrapped_func
+
+
def extract_url(issue_body):
"""Extract the URL for an issue from WebCompat.
diff --git a/webcompat/issues.py b/webcompat/issues.py
index d25d2b01..103b1da0 100644
--- a/webcompat/issues.py
+++ b/webcompat/issues.py
@@ -11,12 +11,14 @@ import json
from webcompat import github
from webcompat.form import build_formdata
+from webcompat.helpers import mockable_report
from webcompat.helpers import proxy_request
from webcompat.helpers import REPO_URI
+@mockable_report
def report_issue(form, proxy=False):
- '''Report an issue, as a logged in user or anonymously.'''
+ """Report an issue, as a logged in user or anonymously."""
# /repos/:owner/:repo/issues
path = 'repos/{0}'.format(REPO_URI)
if proxy:
--
2.14.1
From 763518c0989bfcf7117ccd18142cbed14fa374a7 Mon Sep 17 00:00:00 2001
From: Mike Taylor <miketaylr@gmail.com>
Date: Fri, 27 Apr 2018 10:03:29 -0500
Subject: [PATCH] Issue #2288. Add some issue creation functional tests.
---
tests/functional/reporting-auth.js | 61 ++++++++++++++++++++++++++++++++++
tests/functional/reporting-non-auth.js | 61 ++++++++++++++++++++++++++++++++++
2 files changed, 122 insertions(+)
diff --git a/tests/functional/reporting-auth.js b/tests/functional/reporting-auth.js
index 4028da57..68ee34ec 100755
--- a/tests/functional/reporting-auth.js
+++ b/tests/functional/reporting-auth.js
@@ -33,6 +33,67 @@ registerSuite("Reporting (auth)", {
assert.include(text, "Report as"); //Report as FooUser (logged in)
})
.end();
+ },
+
+ "Reporting an issue works (no image)"() {
+ return FunctionalHelpers.openPage(
+ this,
+ url("/issues/new"),
+ ".js-Navbar-link"
+ )
+ .findById("url")
+ .type("http://example.com")
+ .end()
+ .findByCssSelector("[for=problem_category-0]")
+ .click()
+ .end()
+ .findById("description")
+ .type("Oh no a bug")
+ .end()
+ .findById("steps_reproduce")
+ .type("wowowowow")
+ .end()
+ .findById("submitgithub")
+ .click()
+ .end()
+ .sleep(5000)
+ .getCurrentUrl()
+ .then(url => {
+ // We made it to our special "0"th fixture image. Hooray.
+ assert.include(url, "/0");
+ });
+ },
+
+ "Reporting an issue works (with image)"() {
+ return FunctionalHelpers.openPage(
+ this,
+ url("/issues/new"),
+ ".js-Navbar-link"
+ )
+ .findById("url")
+ .type("http://example.com")
+ .end()
+ .findByCssSelector("[for=problem_category-0]")
+ .click()
+ .end()
+ .findById("description")
+ .type("Oh no a bug")
+ .end()
+ .findById("steps_reproduce")
+ .type("wowowowow")
+ .end()
+ .findById("image")
+ .type("tests/fixtures/green_square.png")
+ .end()
+ .findById("submitgithub")
+ .click()
+ .end()
+ .sleep(5000)
+ .getCurrentUrl()
+ .then(url => {
+ // We made it to our special "0"th fixture image. Hooray.
+ assert.include(url, "/0");
+ });
}
}
});
diff --git a/tests/functional/reporting-non-auth.js b/tests/functional/reporting-non-auth.js
index abbe91a1..47418542 100755
--- a/tests/functional/reporting-non-auth.js
+++ b/tests/functional/reporting-non-auth.js
@@ -275,6 +275,67 @@ registerSuite("Reporting (non-auth)", {
"details param is added after reporting (legacy or not)"
);
});
+ },
+
+ "Reporting an issue works (no image)"() {
+ return FunctionalHelpers.openPage(
+ this,
+ url("/issues/new"),
+ ".js-Navbar-link"
+ )
+ .findById("url")
+ .type("http://example.com")
+ .end()
+ .findByCssSelector("[for=problem_category-0]")
+ .click()
+ .end()
+ .findById("description")
+ .type("Oh no a bug")
+ .end()
+ .findById("steps_reproduce")
+ .type("wowowowow")
+ .end()
+ .findById("submitanon")
+ .click()
+ .end()
+ .sleep(5000)
+ .getCurrentUrl()
+ .then(url => {
+ // We made it to our special "0"th fixture image. Hooray.
+ assert.include(url, "/0");
+ });
+ },
+
+ "Reporting an issue works (with image)"() {
+ return FunctionalHelpers.openPage(
+ this,
+ url("/issues/new"),
+ ".js-Navbar-link"
+ )
+ .findById("url")
+ .type("http://example.com")
+ .end()
+ .findByCssSelector("[for=problem_category-0]")
+ .click()
+ .end()
+ .findById("description")
+ .type("Oh no a bug")
+ .end()
+ .findById("steps_reproduce")
+ .type("wowowowow")
+ .end()
+ .findById("image")
+ .type("tests/fixtures/green_square.png")
+ .end()
+ .findById("submitanon")
+ .click()
+ .end()
+ .sleep(5000)
+ .getCurrentUrl()
+ .then(url => {
+ // We made it to our special "0"th fixture image. Hooray.
+ assert.include(url, "/0");
+ });
}
}
});
--
2.14.1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.