forked from webcompat/webcompat.com
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Issue webcompat#1131 - Adds status, creation and last changed time to…
… issue db
- Loading branch information
1 parent
f976bc8
commit 7131fce
Showing
7 changed files
with
142 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,3 +11,4 @@ Pillow==3.1.1 | |
requests==2.9.1 | ||
ua-parser==0.6.1 | ||
WTForms==2.1 | ||
tldextract>=1.7.5 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
#!/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 helper methods in webcompat/webhooks/helpers.py.''' | ||
|
||
import os.path | ||
import sys | ||
import unittest | ||
|
||
import webcompat | ||
from webcompat.webhooks.helpers import extract_domain_name | ||
|
||
# Add webcompat module to import path | ||
sys.path.append(os.path.realpath(os.pardir)) | ||
|
||
|
||
WWW_DOMAIN_URL = "www.net" | ||
RESULT_WWW_DOMAIN_URL = "net" | ||
BLOGSPOT_URL = "http://blogsofnote.blogspot.com/" | ||
RESULT_BLOGSPOT_URL = "blogspot" | ||
SUBSITE_URL = "https://mail.google.com" | ||
RESULT_SUBSITE_URL = "mail.google" | ||
SUBSITE_WWW_URL = "https://www.mail.google.com" | ||
RESULT_SUBSITE_WWW_URL = "mail.google" | ||
NETFLIX_URL = "https://www.netflix.co.uk" | ||
RESULT_NETFLIX_URL = "netflix" | ||
|
||
|
||
class TestHelpers(unittest.TestCase): | ||
def setUp(self): | ||
webcompat.app.config['TESTING'] = True | ||
self.app = webcompat.app.test_client() | ||
|
||
def tearDown(self): | ||
pass | ||
|
||
def test_extract_domain_name(self): | ||
'''Test for different combinations of domain names.''' | ||
self.assertEqual( | ||
extract_domain_name(WWW_DOMAIN_URL), RESULT_WWW_DOMAIN_URL) | ||
self.assertEqual( | ||
extract_domain_name(BLOGSPOT_URL), | ||
RESULT_BLOGSPOT_URL) | ||
self.assertEqual(extract_domain_name(SUBSITE_URL), RESULT_SUBSITE_URL) | ||
self.assertEqual( | ||
extract_domain_name(SUBSITE_WWW_URL), | ||
RESULT_SUBSITE_WWW_URL) | ||
self.assertEqual(extract_domain_name(NETFLIX_URL), RESULT_NETFLIX_URL) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
#!/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/. | ||
|
||
from webcompat import app | ||
from webcompat.db import issue_db | ||
from webcompat.db import WCIssue | ||
|
||
|
||
def row_to_dict(row): | ||
d = {} | ||
for column in row.__table__.columns: | ||
if(column.name == 'issue_id' or column.name == 'domain' or | ||
column.name == 'summary'): | ||
d[column.name] = str(getattr(row, column.name)) | ||
return d | ||
|
||
|
||
def domain_search(search_domain): | ||
'''Returns the ten most recent issues with a similar domain name''' | ||
search_domain += "%" | ||
session = issue_db() | ||
query_result = ( | ||
session.query(WCIssue) | ||
.filter(WCIssue.domain.like(search_domain)) | ||
.limit(10) | ||
.all()) | ||
result_dict = [row_to_dict(r) for r in query_result] | ||
return result_dict |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters