jenkins-bot has submitted this change and it was merged. (
https://gerrit.wikimedia.org/r/349736 )
Change subject: site_tests.py: Use datetime.utcnow() instead of datetime.now()
......................................................................
site_tests.py: Use datetime.utcnow() instead of datetime.now()
Also:
- Move the test to an uncached class. Due to the time-dependant nature
of the test, the cached response could cause the test to fail in some
cases.
- Increase the time buffer to 30 minutes, this is to make sure the
item has not been connected recently.
- Print the related `item` in the error message which will be
helpful in debugging.
Bug: T163619
Change-Id: I4f6e2684173bd465a423c75c5442595df019d73e
---
M tests/site_tests.py
1 file changed, 33 insertions(+), 28 deletions(-)
Approvals:
jenkins-bot: Verified
Xqt: Looks good to me, approved
diff --git a/tests/site_tests.py b/tests/site_tests.py
index ba943c1..07c1b1a 100644
--- a/tests/site_tests.py
+++ b/tests/site_tests.py
@@ -966,34 +966,6 @@
self.assertNotIn(page.protection()['edit'][0], invalid_levels)
self.assertLessEqual(len(pages), 10)
- def test_unconnected(self):
- """Test that the ItemPage returned raises
NoPage."""
- if not self.site.data_repository():
- raise unittest.SkipTest('Site is not using a Wikibase repository')
- if self.site.hostname() == 'test.wikipedia.org':
- raise unittest.SkipTest('test.wikipedia is misconfigured; T85358')
- cnt = 0
- start_time = datetime.now() - timedelta(minutes=5)
- # Pages which have been connected recently may still be reported as
- # unconnected. So try on an version that is a few minutes older if the
- # tested site appears as a sitelink.
- for page in self.site.unconnected_pages(total=5):
- try:
- item = pywikibot.ItemPage.fromPage(page)
- except pywikibot.NoPage:
- pass
- else:
- revisions = list(item.revisions(total=1, starttime=start_time,
- content=True))
- if revisions:
- sitelinks = json.loads(revisions[0].text)['sitelinks']
- self.assertNotIn(
- self.site.dbName(), sitelinks,
- 'Page "{0}" is connected to a Wikibase '
- 'repository'.format(page.title()))
- cnt += 1
- self.assertLessEqual(cnt, 5)
-
def test_pages_with_property(self):
"""Test pages_with_property method."""
if MediaWikiVersion(self.site.version()) < MediaWikiVersion('1.21'):
@@ -1015,6 +987,39 @@
'NotImplementedError not raised for {0}'.format(item))
+class TestSiteGeneratorsUncached(DefaultSiteTestCase):
+
+ """Test cases for Site methods."""
+
+ def test_unconnected(self):
+ """Test that the ItemPage returned raises
NoPage."""
+ if not self.site.data_repository():
+ raise unittest.SkipTest('Site is not using a Wikibase repository')
+ if self.site.hostname() == 'test.wikipedia.org':
+ raise unittest.SkipTest('test.wikipedia is misconfigured; T85358')
+ cnt = 0
+ # Pages which have been connected recently may still be reported as
+ # unconnected. So try on a version that is a few minutes older if the
+ # tested site appears as a sitelink.
+ start_time = datetime.utcnow() - timedelta(minutes=30)
+ for page in self.site.unconnected_pages(total=3):
+ try:
+ item = pywikibot.ItemPage.fromPage(page)
+ except pywikibot.NoPage:
+ pass
+ else:
+ revisions = list(item.revisions(total=1, starttime=start_time,
+ content=True))
+ if revisions:
+ sitelinks = json.loads(revisions[0].text)['sitelinks']
+ self.assertNotIn(
+ self.site.dbName(), sitelinks,
+ 'Page "{0}" is connected to {1} on Wikibase '
+ 'repository'.format(page.title(), item))
+ cnt += 1
+ self.assertLessEqual(cnt, 3)
+
+
class TestImageUsage(DefaultSiteTestCase):
"""Test cases for Site.imageusage method."""
--
To view, visit
https://gerrit.wikimedia.org/r/349736
To unsubscribe, visit
https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I4f6e2684173bd465a423c75c5442595df019d73e
Gerrit-PatchSet: 3
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: Dalba <dalba.wiki(a)gmail.com>
Gerrit-Reviewer: Dalba <dalba.wiki(a)gmail.com>
Gerrit-Reviewer: Magul <tomasz.magulski(a)gmail.com>
Gerrit-Reviewer: Xqt <info(a)gno.de>
Gerrit-Reviewer: jenkins-bot <>