Skip to content

Commit

Permalink
Merge pull request #1947 from webcompat/dashboard
Browse files Browse the repository at this point in the history
Fixes #1857. Add a NeedsTriage Issues Dashboard
  • Loading branch information
Mike Taylor authored Nov 30, 2017
2 parents 8ebeb3a + 5e99d16 commit b322d23
Show file tree
Hide file tree
Showing 18 changed files with 1,020 additions and 84 deletions.
184 changes: 184 additions & 0 deletions tests/fixtures/dashboard/triage.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,184 @@
[
{
"labels": [
{
"url": "https://api.github.com/repos/webcompat/webcompat-tests/labels/browser-firefox",
"color": "d4c5f9",
"default": false,
"id": 182807004,
"name": "browser-firefox"
},
{
"url": "https://api.github.com/repos/webcompat/webcompat-tests/labels/status-needinfo",
"color": "bfd4f2",
"default": false,
"id": 743991534,
"name": "status-needinfo"
}
],
"number": 1,
"assignee": null,
"repository_url": "https://api.github.com/repos/webcompat/webcompat-tests",
"closed_at": null,
"id": 1,
"title": "example.org - dashboard test",
"comments": 0,
"state": "open",
"body": "<!-- @browser: Firefox 57.0 -->\n<!-- @ua_header: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.13; rv:57.0) Gecko/20100101 Firefox/57.0 -->\n<!-- @reported_with: web -->\n\n**URL**: http://example.org/dashboard\n\n**Browser / Version**: Firefox 57.0\n**Operating System**: Mac OS X 10.13\n**Tested Another Browser**: No\n\n**Problem type**: Site is not usable\n**Description**: testing the dashboard...\n**Steps to Reproduce**:\n\n\n\n\n_From [webcompat.com](https://webcompat.com/) with ❤️_",
"events_url": "https://api.github.com/repos/webcompat/webcompat-tests/issues/1/events",
"labels_url": "https://api.github.com/repos/webcompat/webcompat-tests/issues/1/labels{/name}",
"author_association": "MEMBER",
"comments_url": "https://api.github.com/repos/webcompat/webcompat-tests/issues/1/comments",
"html_url": "https://github.com/webcompat/webcompat-tests/issues/1",
"updated_at": "2017-11-10T12:00:00Z",
"user": {
"following_url": "https://api.github.com/users/webcompat-bot/following{/other_user}",
"events_url": "https://api.github.com/users/webcompat-bot/events{/privacy}",
"organizations_url": "https://api.github.com/users/webcompat-bot/orgs",
"url": "https://api.github.com/users/webcompat-bot",
"gists_url": "https://api.github.com/users/webcompat-bot/gists{/gist_id}",
"html_url": "https://github.com/webcompat-bot",
"subscriptions_url": "https://api.github.com/users/webcompat-bot/subscriptions",
"avatar_url": "https://avatars3.githubusercontent.com/u/8862693?v=4",
"repos_url": "https://api.github.com/users/webcompat-bot/repos",
"received_events_url": "https://api.github.com/users/webcompat-bot/received_events",
"gravatar_id": "",
"starred_url": "https://api.github.com/users/webcompat-bot/starred{/owner}{/repo}",
"site_admin": false,
"login": "webcompat-bot",
"type": "User",
"id": 8862693,
"followers_url": "https://api.github.com/users/webcompat-bot/followers"
},
"milestone": {
"description": "Issues which needs to be triaged",
"title": "needstriage",
"url": "https://api.github.com/repos/webcompat/webcompat-tests/milestones/1",
"labels_url": "https://api.github.com/repos/webcompat/webcompat-tests/milestones/1/labels",
"created_at": "2017-11-08T03:39:06Z",
"creator": {
"following_url": "https://api.github.com/users/karlcow/following{/other_user}",
"events_url": "https://api.github.com/users/karlcow/events{/privacy}",
"organizations_url": "https://api.github.com/users/karlcow/orgs",
"url": "https://api.github.com/users/karlcow",
"gists_url": "https://api.github.com/users/karlcow/gists{/gist_id}",
"html_url": "https://github.com/karlcow",
"subscriptions_url": "https://api.github.com/users/karlcow/subscriptions",
"avatar_url": "https://avatars0.githubusercontent.com/u/505230?v=4",
"repos_url": "https://api.github.com/users/karlcow/repos",
"received_events_url": "https://api.github.com/users/karlcow/received_events",
"gravatar_id": "",
"starred_url": "https://api.github.com/users/karlcow/starred{/owner}{/repo}",
"site_admin": false,
"login": "karlcow",
"type": "User",
"id": 505230,
"followers_url": "https://api.github.com/users/karlcow/followers"
},
"number": 1,
"html_url": "https://github.com/webcompat/webcompat-tests/milestone/1",
"updated_at": "2017-11-08T06:22:16Z",
"due_on": null,
"state": "open",
"closed_issues": 0,
"open_issues": 10,
"closed_at": null,
"id": 2744172
},
"locked": false,
"url": "https://api.github.com/repos/webcompat/webcompat-tests/issues/1",
"created_at": "2015-02-01T12:00:00Z",
"assignees": []
},
{
"labels": [
{
"url": "https://api.github.com/repos/webcompat/webcompat-tests/labels/browser-chrome",
"color": "006b75",
"default": false,
"id": 90454697,
"name": "browser-chrome"
},
{
"url": "https://api.github.com/repos/webcompat/webcompat-tests/labels/browser-firefox",
"color": "d4c5f9",
"default": false,
"id": 182807004,
"name": "browser-firefox"
}
],
"number": 2,
"assignee": null,
"repository_url": "https://api.github.com/repos/webcompat/webcompat-tests",
"closed_at": null,
"id": 2,
"title": "dashboard.example.com - site is not usable",
"comments": 0,
"state": "open",
"body": "<!-- @browser: Firefox 58.0 -->\n<!-- @ua_header: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.13; rv:58.0) Gecko/20100101 Firefox/58.0 -->\n<!-- @reported_with: web -->\n\n**URL**: http://dashboard.example.com/\n\n**Browser / Version**: Firefox 58.0\n**Operating System**: Mac OS X 10.13\n**Tested Another Browser**: Yes\n\n**Problem type**: Site is not usable\n**Description**: triage dashboard testing\n**Steps to Reproduce**:\n\n\n\n\n_From [webcompat.com](https://webcompat.com/) with ❤️_",
"events_url": "https://api.github.com/repos/webcompat/webcompat-tests/issues/2/events",
"labels_url": "https://api.github.com/repos/webcompat/webcompat-tests/issues/2/labels{/name}",
"author_association": "MEMBER",
"comments_url": "https://api.github.com/repos/webcompat/webcompat-tests/issues/2/comments",
"html_url": "https://github.com/webcompat/webcompat-tests/issues/2",
"updated_at": "2015-02-20T12:00:00Z",
"user": {
"following_url": "https://api.github.com/users/karlcow/following{/other_user}",
"events_url": "https://api.github.com/users/karlcow/events{/privacy}",
"organizations_url": "https://api.github.com/users/karlcow/orgs",
"url": "https://api.github.com/users/karlcow",
"gists_url": "https://api.github.com/users/karlcow/gists{/gist_id}",
"html_url": "https://github.com/karlcow",
"subscriptions_url": "https://api.github.com/users/karlcow/subscriptions",
"avatar_url": "https://avatars0.githubusercontent.com/u/505230?v=4",
"repos_url": "https://api.github.com/users/karlcow/repos",
"received_events_url": "https://api.github.com/users/karlcow/received_events",
"gravatar_id": "",
"starred_url": "https://api.github.com/users/karlcow/starred{/owner}{/repo}",
"site_admin": false,
"login": "karlcow",
"type": "User",
"id": 505230,
"followers_url": "https://api.github.com/users/karlcow/followers"
},
"milestone": {
"description": "Issues which needs to be triaged",
"title": "needstriage",
"url": "https://api.github.com/repos/webcompat/webcompat-tests/milestones/1",
"labels_url": "https://api.github.com/repos/webcompat/webcompat-tests/milestones/1/labels",
"created_at": "2017-09-05T03:39:06Z",
"creator": {
"following_url": "https://api.github.com/users/karlcow/following{/other_user}",
"events_url": "https://api.github.com/users/karlcow/events{/privacy}",
"organizations_url": "https://api.github.com/users/karlcow/orgs",
"url": "https://api.github.com/users/karlcow",
"gists_url": "https://api.github.com/users/karlcow/gists{/gist_id}",
"html_url": "https://github.com/karlcow",
"subscriptions_url": "https://api.github.com/users/karlcow/subscriptions",
"avatar_url": "https://avatars0.githubusercontent.com/u/505230?v=4",
"repos_url": "https://api.github.com/users/karlcow/repos",
"received_events_url": "https://api.github.com/users/karlcow/received_events",
"gravatar_id": "",
"starred_url": "https://api.github.com/users/karlcow/starred{/owner}{/repo}",
"site_admin": false,
"login": "karlcow",
"type": "User",
"id": 505230,
"followers_url": "https://api.github.com/users/karlcow/followers"
},
"number": 1,
"html_url": "https://github.com/webcompat/webcompat-tests/milestone/1",
"updated_at": "2017-11-08T06:22:16Z",
"due_on": null,
"state": "open",
"closed_issues": 0,
"open_issues": 10,
"closed_at": null,
"id": 2744172
},
"locked": false,
"url": "https://api.github.com/repos/webcompat/webcompat-tests/issues/2",
"created_at": "2015-02-20T12:00:00Z",
"assignees": []
}
]
83 changes: 83 additions & 0 deletions tests/test_dashboard.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
#!/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 the Dashboard functions."""

from datetime import datetime
import json
from mock import patch
import os.path
import sys
import unittest


from webcompat.dashboard import browser_labels
from webcompat.dashboard import filter_needstriage
from webcompat.dashboard import has_needinfo
from webcompat.dashboard import is_older

# Add webcompat module to import path
sys.path.append(os.path.realpath(os.pardir))
import webcompat # nopep8

# Any request that depends on parsing HTTP Headers (basically anything
# on the index route, will need to include the following: environ_base=headers
headers = {'HTTP_USER_AGENT': ('Mozilla/5.0 (Macintosh; Intel Mac OS X 10.13; '
'rv:58.0) Gecko/20100101 Firefox/58.0')}


def json_data(filename):
"""Return a tuple with the content and its signature."""
current_root = os.path.realpath(os.curdir)
fixtures_path = 'tests/fixtures/dashboard'
path = os.path.join(current_root, fixtures_path, filename)
with open(path, 'r') as f:
json_event = json.dumps(json.load(f))
return json_event


class TestDashboard(unittest.TestCase):
"""Test for routes in the the project."""

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

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

def test_filter_needstriage(self):
"""Assess the filtering is correct."""
expected = [{'needinfo': True, 'title': u'example.org - dashboard test', 'created_at': u'2015-02-01T12:00:00Z', 'updated_at': u'2017-11-10T12:00:00Z', 'number': 1, 'priority': True, 'browsers': ['firefox']}, {'needinfo': False, 'title': u'dashboard.example.com - site is not usable', 'created_at': u'2015-02-20T12:00:00Z', 'updated_at': u'2015-02-20T12:00:00Z', 'number': 2, 'priority': False, 'browsers': ['chrome', 'firefox']}] # noqa
raw_list = json.loads(json_data('triage.json'))
testdt = datetime(2015, 2, 19, 12, 0, 0)
with patch('webcompat.dashboard.get_control_date') as control_date:
control_date.return_value = testdt
filtered_list, total, priority = filter_needstriage(raw_list)
self.assertListEqual(expected, filtered_list)
self.assertEqual(total, 2)
self.assertEqual(priority, 1)

def test_has_needinfo(self):
"""Check if a list of labels contains the 'status-needinfo'."""
labels = ['browser-firefox', 'browser-chrome', 'status-needinfo']
self.assertTrue(has_needinfo(labels))
labels = ['needinfo', 'browser-firefox']
self.assertFalse(has_needinfo(labels))
self.assertFalse(has_needinfo([]))

def test_is_older(self):
"""Check if an issue is older than a certain time gap."""
time_gap = datetime(2017, 11, 7, 11, 0, 3, 419569)
self.assertTrue(is_older('2017-11-05T06:25:36Z', time_gap))
self.assertFalse(is_older('2017-11-08T00:30:36Z', time_gap))

def test_browser_labels(self):
"""Check we receive the right list of browsers."""
labels = ['status-foo', 'blah', 'browser-', 'browser-firefox']
self.assertListEqual(['firefox'], browser_labels(labels))
12 changes: 7 additions & 5 deletions tests/test_rendering.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,15 @@ def test_titles(self):
('/issues', 'Issues'),
('issues/new', 'New Issue'),
('/privacy', 'Privacy Policy'),
('/dashboard/triage', 'Triage Dashboard'),
('/404', defaultTitle)
]
for uri, title in website_uris:
rv = self.app.get(uri, environ_base=headers)
expected = '<title>{title} | webcompat.com</title>'.format(
title=title)
self.assertTrue(expected in rv.data)
with webcompat.app.app_context():
for uri, title in website_uris:
rv = self.app.get(uri, environ_base=headers)
expected = '<title>{title} | webcompat.com</title>'.format(
title=title)
self.assertTrue(expected in rv.data)

def test_user_title_pages(self):
"""Testing user activity page title."""
Expand Down
Loading

0 comments on commit b322d23

Please sign in to comment.