From e3ba6e82412fcd56ebacc18f243b92cc43407a4d Mon Sep 17 00:00:00 2001 From: Aurélien Bompard Date: Feb 06 2017 23:30:15 +0000 Subject: [PATCH 1/4] Remove duplicated code --- diff --git a/hubs/tests/test_widgets/__init__.py b/hubs/tests/test_widgets/__init__.py index 229d620..7579b19 100644 --- a/hubs/tests/test_widgets/__init__.py +++ b/hubs/tests/test_widgets/__init__.py @@ -9,84 +9,18 @@ import requests import vcr import hubs.models +from hubs.tests import APPTest -cassette_dir = dirname(dirname(__file__)) + '/vcr-request-data/' - -class WidgetTest(unittest.TestCase): - def setUp(self): - filename = cassette_dir + self.id() - self.vcr = vcr.use_cassette(filename, record_mode='new_episodes') - self.vcr.__enter__() - - import hubs.app - hubs.app.fedmsg_config = { - 'hubs.sqlalchemy.uri': 'sqlite://', # in memory - } - hubs.app.session = hubs.models.init( - hubs.app.fedmsg_config['hubs.sqlalchemy.uri'], - create=True, - ) - self.app = hubs.app.app.test_client() - self.app.testing = True - self.session = hubs.app.session - self.populate() - - def tearDown(self): - self.vcr.__exit__() - self.session.remove() +class WidgetTest(APPTest): def populate(self): - for user in ['devyani7', 'dhrish', 'shalini', 'ralph', 'decause']: - fullname = user.title() - hubs.models.User.get_or_create( - hubs.app.session, username=user, fullname=fullname) - - hubs.app.session.flush() - + super(WidgetTest, self).populate() hub = hubs.models.Hub.by_name('ralph') widget = hubs.models.Widget( - plugin='about', - index=500, - _config=json.dumps({"text": "Testing."}), - ) - - hub.widgets.append(widget) - - widget = hubs.models.Widget( plugin='library', index=51, _config=json.dumps({"urls": "ralph/"}) # we must add a url or itll crash ) hub.widgets.append(widget) - - for team in ['i18n', 'infra', 'old']: - hub = hubs.models.Hub(name=team, summary="the %s team" % team) - if hub.name == 'old': - hub.last_refreshed = datetime.utcnow() - timedelta(days=100) - hub.last_updated = datetime.utcnow() - timedelta(days=200) - - hubs.app.session.add(hub) - widget = hubs.models.Widget(plugin='meetings', index=11, - _config=json.dumps({'calendar': team})) - hub.widgets.append(widget) - - # TODO - test that it is in the registry - # TODO - test that it has all the things it needs - - def widget_instance(self, hubname, plugin): - hub = hubs.models.Hub.by_name(hubname) - if not hub: - raise ValueError("No such hub %r" % hubname) - for widget in hub.widgets: - if widget.plugin == plugin: - return widget - raise KeyError("No such widget found for %s/%s" % (hubname, plugin)) - - @staticmethod - def get_fedmsg(idx): - url = 'https://apps.fedoraproject.org/datagrepper/id' - response = requests.get(url, params=dict(id=idx)) - if not bool(response): - raise IOError("Failed to talk to %r %r" % (response.url, response)) - return response.json() + hubs.app.session.commit() From 6bd7bfba450865f89f9ab8fe1c0a74674db73aef Mon Sep 17 00:00:00 2001 From: Aurélien Bompard Date: Feb 06 2017 23:30:15 +0000 Subject: [PATCH 2/4] Remove unused code --- diff --git a/hubs/tests/__init__.py b/hubs/tests/__init__.py index 59866ee..2394c1e 100644 --- a/hubs/tests/__init__.py +++ b/hubs/tests/__init__.py @@ -14,14 +14,12 @@ import vcr import hubs.models -cassette_dir = dirname(dirname(__file__)) + '/vcr-request-data/' -json_path = os.path.join( - os.path.join(os.path.dirname(os.path.abspath(__file__))), 'data/') +cassette_dir = os.path.join(dirname(__file__), 'vcr-request-data') class APPTest(unittest.TestCase): def setUp(self): - filename = cassette_dir + self.id() + filename = os.path.join(cassette_dir, self.id()) self.vcr = vcr.use_cassette(filename, record_mode='new_episodes') self.vcr.__enter__() @@ -155,6 +153,3 @@ class FakeAuthorization(object): self.avatar = 'avatar_src_url' self.nickname = username self.username = username - - def __getitem__(self, key): - return self.dic[key] diff --git a/hubs/tests/data/message_involved.json b/hubs/tests/data/message_involved.json deleted file mode 100644 index fdfd0db..0000000 --- a/hubs/tests/data/message_involved.json +++ /dev/null @@ -1,137 +0,0 @@ -{ - "timestamp": 1465567413.0, - "topic": "io.pagure.prod.pagure.issue.new", - "msg_id": "2016-0490127f-473f-4d01-ASDF-a864a56dc302", - "msg": { - "action": "created", - "comment": { - "body": - "hm, there is something odd the stackage page is inconsistent", - "created_at": "2016-06-10T14:03:31Z", - "html_url": - "https://github.com/fedora-infra/anitya/issues/283#issuecomment-225190438", - "id": 225190438, - "updated_at": "2016-06-10T14:03:31Z", - "url": - "https://api.github.com/repos/fedora-infra/anitya/issues/comments/225190438", - "user": { - "gravatar_id": "", - "html_url": "https://github.com/pypingou", - "id": 1240038, - "login": "pypingou", - "site_admin": false, - "type": "User", - "url": "https://api.github.com/users/pypingou" - } - }, - "fas_usernames": { - "fedora-infra": "github_org_fedora-infra", - "pypingou": "pingou" - }, - "issue": { - "assignee": null, - "body": - "@juhp it seems that the stackage backend is broken:", - "closed_at": "2016-04-29T14:53:10Z", - "comments": 8, - "created_at": "2016-04-15T16:15:57Z", - "html_url": - "https://github.com/fedora-infra/anitya/issues/283", - "id": 148703615, - "labels": [], - "locked": false, - "milestone": null, - "number": 283, - "state": "closed", - "title": "stackage backend broken", - "updated_at": "2016-06-10T14:03:31Z", - "url": - "https://api.github.com/repos/fedora-infra/anitya/issues/283", - "user": { - "gravatar_id": "", - "html_url": "https://github.com/pypingou", - "id": 1240038, - "login": "pypingou", - "site_admin": false, - "type": "User", - "url": "https://api.github.com/users/pypingou" - } - }, - "organization": { - "description": "Fedora Infrastructure Team", - "id": 3316637, - "login": "fedora-infra", - "url": "https://api.github.com/orgs/fedora-infra" - }, - "repository": { - "created_at": "2013-11-29T10:17:26Z", - "default_branch": "master", - "description": "A cross-distribution upstream release project", - "fork": false, - "forks": 33, - "forks_count": 33, - "full_name": "fedora-infra/anitya", - "has_downloads": true, - "has_issues": true, - "has_pages": false, - "has_wiki": false, - "homepage": "https://release-monitoring.org", - "html_url": "https://github.com/fedora-infra/anitya", - "id": 14798348, - "language": "Python", - "name": "anitya", - "open_issues": 25, - "open_issues_count": 25, - "owner": { - "gravatar_id": "", - "html_url": "https://github.com/fedora-infra", - "id": 3316637, - "login": "fedora-infra", - "site_admin": false, - "type": "Organization", - "url": "https://api.github.com/users/fedora-infra" - }, - "private": false, - "pushed_at": "2016-06-05T18:16:15Z", - "size": 4364, - "stargazers_count": 56, - "updated_at": "2016-06-10T09:43:58Z", - "url": "https://api.github.com/repos/fedora-infra/anitya", - "watchers": 56, - "watchers_count": 56 - }, - "sender": { - "gravatar_id": "", - "html_url": "https://github.com/pypingou", - "id": 1240038, - "login": "pypingou", - "site_admin": false, - "type": "User", - "url": "https://api.github.com/users/pypingou" - } - }, - "arguments": { - "categories": [ - "pagure" - ], - "contains": [], - "delta": 172800.0, - "end": 1465839365.0, - "grouped": false, - "meta": [], - "not_categories": [], - "not_packages": [], - "not_topics": [], - "not_users": [], - "order": "desc", - "packages": [], - "page": 1, - "rows_per_page": 1, - "start": 1465666565.0, - "topics": [], - "users": [] - }, - "count": 1, - "pages": 225, - "total": 225 -} diff --git a/hubs/tests/data/message_not_involved.json b/hubs/tests/data/message_not_involved.json deleted file mode 100644 index e72439a..0000000 --- a/hubs/tests/data/message_not_involved.json +++ /dev/null @@ -1,120 +0,0 @@ -{ - "topic": "org.fedoraproject.prod.github.issue.comment", - "i": 1, - "msg": { - "action": "created", - "comment": { - "body": - "hm, there is something odd the stackage page is inconsistent", - "created_at": "2016-06-10T14:03:31Z", - "html_url": - "https://github.com/fedora-infra/anitya/issues/283#issuecomment-225190438", - "id": 225190438, - "updated_at": "2016-06-10T14:03:31Z", - "url": - "https://api.github.com/repos/fedora-infra/anitya/issues/comments/225190438", - "user": { - "gravatar_id": "", - "html_url": "https://github.com/pypingou", - "id": 1240038, - "login": "pypingou", - "site_admin": false, - "type": "User", - "url": "https://api.github.com/users/pypingou" - } - }, - "fas_usernames": { - "fedora-infra": "github_org_fedora-infra", - "pypingou": "pingou" - }, - "issue": { - "assignee": null, - "body": - "@juhp it seems that the stackage backend is broken", - "closed_at": "2016-04-29T14:53:10Z", - "comments": 8, - "created_at": "2016-04-15T16:15:57Z", - "html_url": - "https://github.com/fedora-infra/anitya/issues/283", - "id": 148703615, - "labels": [], - "locked": false, - "milestone": null, - "number": 283, - "state": "closed", - "title": "stackage backend broken", - "updated_at": "2016-06-10T14:03:31Z", - "url": - "https://api.github.com/repos/fedora-infra/anitya/issues/283", - "user": { - "gravatar_id": "", - "html_url": "https://github.com/pypingou", - "id": 1240038, - "login": "pypingou", - "site_admin": false, - "type": "User", - "url": "https://api.github.com/users/pypingou" - } - }, - "organization": { - "description": "Fedora Infrastructure Team", - "id": 3316637, - "login": "fedora-infra", - "url": "https://api.github.com/orgs/fedora-infra" - }, - "repository": { - "created_at": "2013-11-29T10:17:26Z", - "default_branch": "master", - "description": - "A cross-distribution upstream release monitoring project", - "fork": false, - "forks": 33, - "forks_count": 33, - "full_name": "fedora-infra/anitya", - "has_downloads": true, - "has_issues": true, - "has_pages": false, - "has_wiki": false, - "homepage": "https://release-monitoring.org", - "html_url": "https://github.com/fedora-infra/anitya", - "id": 14798348, - "language": "Python", - "name": "anitya", - "open_issues": 25, - "open_issues_count": 25, - "owner": { - "gravatar_id": "", - "html_url": "https://github.com/fedora-infra", - "id": 3316637, - "login": "fedora-infra", - "site_admin": false, - "type": "Organization", - "url": "https://api.github.com/users/fedora-infra" - }, - "private": false, - "pushed_at": "2016-06-05T18:16:15Z", - "size": 4364, - "stargazers_count": 56, - "updated_at": "2016-06-10T09:43:58Z", - "url": "https://api.github.com/repos/fedora-infra/anitya", - "watchers": 56, - "watchers_count": 56 - }, - "sender": { - "gravatar_id": "", - "html_url": "https://github.com/pypingou", - "id": 1240038, - "login": "pypingou", - "site_admin": false, - "type": "User", - "url": "https://api.github.com/users/pypingou" - } - }, - "msg_id": "2016-0490127f-473f-4d01-8e3a-a864a56dc302", - "signature": - "MNpAVdrPW78dcSe94FOS+/6QFBYo/LkrV5ee9tQedkhurHY1BGpaFHlU5l8cNVEpB7rr", - "source_name": "datanommer", - "source_version": "0.6.5", - "timestamp": 1465567413.0, - "topic": "org.fedoraproject.prod.github.issue.comment" -} diff --git a/hubs/tests/test_fedora_hubs_flask_api.py b/hubs/tests/test_fedora_hubs_flask_api.py index 3c24905..1ca2a8d 100644 --- a/hubs/tests/test_fedora_hubs_flask_api.py +++ b/hubs/tests/test_fedora_hubs_flask_api.py @@ -18,8 +18,6 @@ import hubs.models import fedmsg.config -cassette_dir = dirname(dirname(__file__)) + '/vcr-request-data/' - class HubsAPITest(hubs.tests.APPTest): def test_index_logged_out(self): From daf8051be3969e8b3d3ed31bbbcd11069760085e Mon Sep 17 00:00:00 2001 From: Aurélien Bompard Date: Feb 06 2017 23:30:15 +0000 Subject: [PATCH 3/4] Don't hardcode the basepython in Tox --- diff --git a/tox.ini b/tox.ini index 37dd0c2..24d3f29 100644 --- a/tox.ini +++ b/tox.ini @@ -4,7 +4,6 @@ skipsdist = True [testenv] -basepython = python2 usedevelop = True deps = -rrequirements.txt From 56f152f7032a7c9ed5946adbe59683751a637f91 Mon Sep 17 00:00:00 2001 From: Aurélien Bompard Date: Feb 06 2017 23:30:15 +0000 Subject: [PATCH 4/4] Fix a index change --- diff --git a/hubs/tests/test_widgets/test_library.py b/hubs/tests/test_widgets/test_library.py index 9182b56..ac7ddfc 100644 --- a/hubs/tests/test_widgets/test_library.py +++ b/hubs/tests/test_widgets/test_library.py @@ -18,12 +18,12 @@ class TestLibrary(hubs.tests.test_widgets.WidgetTest): "urls": "ralph/" }, "data": { - u"edit_url": u"/ralph/57/edit", + u"edit_url": u"/ralph/%d/edit" % widget.idx, u"source_url": u"/source/library", u"urls": [ u"ralph/" ], - u"widget_url": u"/ralph/57" + u"widget_url": u"/ralph/%d" % widget.idx, }, "description": None, "hub": "ralph",