Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Issue #3769 - Dual reporter form backend changes
  • Loading branch information
ksy36 committed Jun 20, 2023
commit b4feab440d0b2fd02ba17095d3169248e5386526
7 changes: 6 additions & 1 deletion config/environment.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@
ES_URL = os.environ.get('ES_URL')
ES_API_KEY_ID = os.environ.get('ES_API_KEY_ID')
ES_API_KEY = os.environ.get('ES_API_KEY')
BQ_PROJECT = 'moz-fx-dev-dschubert-wckb'
BQ_TABLE = 'webcompat_user_reports.user_reports'

if STAGING:
GITHUB_CLIENT_ID = os.environ.get('STAGING_GITHUB_CLIENT_ID')
Expand All @@ -67,7 +69,8 @@
ES_URL = os.environ.get('ES_URL')
ES_API_KEY_ID = os.environ.get('ES_API_KEY_ID')
ES_API_KEY = os.environ.get('ES_API_KEY')

BQ_PROJECT = 'moz-fx-dev-dschubert-wckb'
BQ_TABLE = 'webcompat_user_reports.user_reports_test'

if LOCALHOST:
# for now we are using .env only on localhost
Expand Down Expand Up @@ -95,6 +98,8 @@
ES_URL = os.environ.get('ES_URL')
ES_API_KEY_ID = os.environ.get('ES_API_KEY_ID')
ES_API_KEY = os.environ.get('ES_API_KEY')
BQ_PROJECT = 'moz-fx-dev-dschubert-wckb'
BQ_TABLE = 'webcompat_user_reports.user_reports_test'

# BUG STATUS
# The id will be initialized when the app is started.
Expand Down
1 change: 1 addition & 0 deletions config/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ Flask-Limiter==1.4
Flask-SQLAlchemy==2.4.4
Flask-WTF==0.15.1
GitHub-Flask==3.2.0
google-cloud-bigquery==3.11.1
Pillow==9.3.0
python-dotenv==0.15.0
requests==2.25.1
Expand Down
1 change: 1 addition & 0 deletions tests/functional/labels-auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ registerSuite("Labels (auth)", {
.findByCssSelector(".js-label-search")
.pressKeys("\uE00C")
.end()
.sleep(500)
.findByCssSelector(".js-LabelEditorLauncher")
.click()
.getAttribute("class")
Expand Down
28 changes: 5 additions & 23 deletions tests/functional/reporting-auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ registerSuite("Reporting (auth)", {
.findByCssSelector("#url")
.type("http://example.com")
.end()
.findById("steps_reproduce")
.type("This paragraph contains some description")
.end()
.sleep(500)
// Click on "Confirm"
.findByCssSelector(".next-url")
.click()
Expand Down Expand Up @@ -61,33 +65,11 @@ registerSuite("Reporting (auth)", {
document.querySelector("[for=tested_browsers-0]").click();
})
.end()
.sleep(500)
.sleep(1000)
// Click on "Confirm"
.findByCssSelector(".next-tested")
.click()
.end()
// Enter less than 30 characters in the description field
.findById("steps_reproduce")
.type("not enough characters")
.end()
.sleep(500)
.findDisplayedByCssSelector(".next-description")
.getAttribute("disabled")
.then(function (attribute) {
// Make sure "Continue" is disabled if there are not enough characters
assert.isNotNull(attribute);
})
.end()
.findById("steps_reproduce")
.clearValue()
// Enter more than 30 characters in the description field
.type("This paragraph contains more than 30 characters")
.end()
.sleep(500)
// Click on "Continue"
.findByCssSelector(".next-description")
.click()
.end()
.sleep(1000)
.findDisplayedByCssSelector(".next-screenshot")
// Click on "Continue without"
Expand Down
143 changes: 64 additions & 79 deletions tests/functional/reporting-issue-wizard-non-auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,19 @@ registerSuite("Reporting with wizard", {
.findByCssSelector("#url")
.type("http://example.com")
.end()
// Click on "Confirm"
.findDisplayedByCssSelector(".next-submit")
.getAttribute("disabled")
.then(function (attribute) {
// Make sure "Submit" is enabled
assert.isNull(attribute);
})
.end()
.findById("steps_reproduce")
.clearValue()
.type("This paragraph contains some description")
.end()
.sleep(500)
// Click on "Add more details"
.findByCssSelector(".next-url")
.click()
.end()
Expand Down Expand Up @@ -175,35 +187,6 @@ registerSuite("Reporting with wizard", {
.end()
.findByCssSelector(".step.active .description")
.getVisibleText()
.then(function (text) {
// Make sure that progress label is "Description"
assert.include(text, "Description");
})
.end()
// Enter less than 30 characters in the description field
.findById("steps_reproduce")
.type("not enough characters")
.end()
.sleep(500)
.findDisplayedByCssSelector(".next-description")
.getAttribute("disabled")
.then(function (attribute) {
// Make sure "Continue" is disabled if there are not enough characters
assert.isNotNull(attribute);
})
.end()
.findById("steps_reproduce")
.clearValue()
// Enter more than 30 characters in the description field
.type("This paragraph contains more than 30 characters")
.end()
.sleep(500)
// Click on "Continue"
.findByCssSelector(".next-description")
.click()
.end()
.findByCssSelector(".step.active .description")
.getVisibleText()
.then(function (text) {
// Make sure that progress label is "Screenshot"
assert.include(text, "Screenshot");
Expand Down Expand Up @@ -249,6 +232,20 @@ registerSuite("Reporting with wizard", {
assert.include(text, "Web address");
})
.end()
.findDisplayedByCssSelector(".next-url")
.getAttribute("disabled")
.then(function (attribute) {
// Make sure "Add more details" is disabled if there is no url
assert.isNotNull(attribute);
})
.end()
.findDisplayedByCssSelector(".next-submit")
.getAttribute("disabled")
.then(function (attribute) {
// Make sure "Submit" is disabled if there is no url
assert.isNotNull(attribute);
})
.end()
// Manual url enter
.findByCssSelector("#url")
.type("http://example.com")
Expand All @@ -260,10 +257,39 @@ registerSuite("Reporting with wizard", {
.findByCssSelector(".step.active .description")
.getVisibleText()
.then(function (text) {
// Make sure that progress label is "Issue"
assert.include(text, "Issue");
// Make sure that progress label is still "Web address"
assert.include(text, "Web address");
})
.end()
// Make sure that other problem field is focused
.getActiveElement()
.getProperty("id")
.then(function (elementId) {
assert.equal(
elementId,
"steps_reproduce",
"Focused element id is #steps_reproduce"
);
})
.end()
.findByCssSelector(".final-text")
.getVisibleText()
.then(function (text) {
assert.include(
text,
"Please describe what happened in order to proceed to the detailed reporter."
);
})
.end()
.findById("steps_reproduce")
.clearValue()
.type("This paragraph contains some description")
.end()
.sleep(500)
// Click on "Confirm"
.findByCssSelector(".next-url")
.click()
.end()
.execute(function () {
// Click on "Design is broken"
document.querySelector("[for=problem_category-2]").click();
Expand Down Expand Up @@ -363,28 +389,12 @@ registerSuite("Reporting with wizard", {
.end()
.findByCssSelector(".step.active .description")
.getVisibleText()
.then(function (text) {
// Make sure that progress label is "Description"
assert.include(text, "Description");
})
.end()
// Enter more than 30 characters in the description field
.findById("steps_reproduce")
.type("This paragraph contains more than 30 characters")
.end()
.sleep(500)
// Click "Continue"
.findByCssSelector(".next-description")
.click()
.end()
.sleep(1000)
.findByCssSelector(".step.active .description")
.getVisibleText()
.then(function (text) {
// Make sure that progress label is "Screenshot"
assert.include(text, "Screenshot");
})
.end()
.sleep(500)
.findDisplayedByCssSelector(".next-screenshot")
.getVisibleText()
.then(function (text) {
Expand All @@ -398,6 +408,7 @@ registerSuite("Reporting with wizard", {
// Click on "Continue without"
.click()
.end()
.sleep(500)
.findByCssSelector(".step.active .description")
.getVisibleText()
.then(function (text) {
Expand Down Expand Up @@ -439,7 +450,10 @@ registerSuite("Reporting with wizard", {
.end()
.end()
.sleep(500)
// Click on "Confirm"
.findById("steps_reproduce")
.type("This paragraph contains some description")
.end()
.sleep(500)
.findByCssSelector(".next-url")
.click()
.end()
Expand Down Expand Up @@ -521,35 +535,6 @@ registerSuite("Reporting with wizard", {
.end()
.findByCssSelector(".step.active .description")
.getVisibleText()
.then(function (text) {
// Make sure that progress label is "Description"
assert.include(text, "Description");
})
.end()
// Enter less than 30 characters
.findById("steps_reproduce")
.type("not enough characters")
.end()
.sleep(500)
.findDisplayedByCssSelector(".next-description")
.getAttribute("disabled")
.then(function (attribute) {
// Make sure "Continue" is disabled if there are not enough characters
assert.isNotNull(attribute);
})
.end()
// Enter more than 30 characters in the description field
.findById("steps_reproduce")
.clearValue()
.type("This paragraph contains more than 30 characters")
.end()
.sleep(500)
// Click "Continue"
.findByCssSelector(".next-description")
.click()
.end()
.findByCssSelector(".step.active .description")
.getVisibleText()
.then(function (text) {
// Make sure that progress label is "Screenshot"
assert.include(text, "Screenshot");
Expand Down
77 changes: 77 additions & 0 deletions tests/unit/test_bq.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# This Source Code Form is subject to the terms of the Mozilla Public
# 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/.

"""Tests for Siterank class."""

import json
import unittest
import webcompat

from unittest.mock import patch
from webcompat.bq import send_bq_report


class TestBQ(unittest.TestCase):
"""Tests for bq module."""

def setUp(self):
"""Set up the tests."""
webcompat.app.config['TESTING'] = True

def tearDown(self):
"""Tear down the tests."""
pass

def test_send_bq_report(self):
with patch('google.cloud.bigquery.Client') as MockClient:
mock_client_instance = MockClient.return_value
mock_client_instance.insert_rows_json.return_value = []

form_object = {
'url': 'https://example.com/',
'steps_reproduce': 'site is broken',
'details': json.dumps({
'additionalData': {
'applicationName': 'Firefox',
},
'consoleLog': ['console.log(hi)']
})
}

result = send_bq_report(form_object)
self.assertEqual(result, 'success')

def test_send_bq_report_error(self):
with patch('google.cloud.bigquery.Client') as MockClient:
mock_client_instance = MockClient.return_value
mock_client_instance.insert_rows_json.return_value = [
[{'index': 0,
'errors': [{
'reason': 'invalid',
'location': '',
'debugInfo': '',
'message': 'Repeated value added outside of an array, field: reported_at.' # noqa
}]
}]
]

form_object = {
'url': 'https://example.com/',
'steps_reproduce': 'site is broken',
'details': json.dumps({
'additionalData': {
'applicationName': 'Firefox',
},
'consoleLog': ['console.log(hi)']
})
}

result = send_bq_report(form_object)
self.assertEqual(result, 'error')


if __name__ == '__main__':
unittest.main()
Loading