Skip to content

Commit

Permalink
FilePage: remove deprecated use of fileUrl
Browse files Browse the repository at this point in the history
Use get_file_url in favor of deprecated fileUrl.

Change-Id: I06ab79183b13918b89abfb3b7e7f3a27becfe1cb
  • Loading branch information
Mpaa committed May 29, 2017
1 parent f4410dc commit a5e5a3f
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 11 deletions.
4 changes: 2 additions & 2 deletions pywikibot/page.py
Expand Up @@ -2495,10 +2495,10 @@ def fileIsShared(self):
if not self.site.has_image_repository:
return False
elif 'wikitravel_shared' in self.site.shared_image_repository():
return self.fileUrl().startswith(
return self.latest_file_info.url.startswith(
u'http://wikitravel.org/upload/shared/')
else:
return self.fileUrl().startswith(
return self.latest_file_info.url.startswith(
'https://upload.wikimedia.org/wikipedia/commons/')

@deprecated("FilePage.latest_file_info.sha1")
Expand Down
28 changes: 19 additions & 9 deletions tests/file_tests.py
Expand Up @@ -20,7 +20,7 @@

class TestShareFiles(TestCase):

"""Test methods fileIsShared, exists and fileUrl with shared files."""
"""Test fileIsShared, exists and fileUrl/get_file_url with shared files."""

sites = {
'enwiki': {
Expand All @@ -43,6 +43,16 @@ class TestShareFiles(TestCase):

cached = True

def test_fileUrl_versus_get_file_url(self):
"""Test fileUrl() is equivalent to get_file_url()."""
title = 'File:Sepp Maier 1.JPG'
commons = self.get_site('commons')
commons_file = pywikibot.FilePage(commons, title)
self.assertEqual(commons_file.fileUrl(), commons_file.get_file_url())
itwp = self.get_site('itwiki')
itwp_file = pywikibot.FilePage(itwp, title)
self.assertEqual(itwp_file.fileUrl(), itwp_file.get_file_url())

def testSharedOnly(self):
"""Test fileIsShared() on file page with shared file only."""
title = 'File:Sepp Maier 1.JPG'
Expand All @@ -60,9 +70,9 @@ def testSharedOnly(self):

self.assertTrue(itwp_file.fileIsShared())
self.assertTrue(commons_file.fileIsShared())
self.assertTrue(commons_file.fileUrl())
self.assertTrue(commons_file.get_file_url())

self.assertIn('/wikipedia/commons/', itwp_file.fileUrl())
self.assertIn('/wikipedia/commons/', itwp_file.get_file_url())
self.assertRaises(pywikibot.NoPage, itwp_file.get)

def testLocalOnly(self):
Expand All @@ -78,14 +88,14 @@ def testLocalOnly(self):

commons_file = pywikibot.FilePage(commons, title)

self.assertTrue(enwp_file.fileUrl())
self.assertTrue(enwp_file.latest_file_info.url)
self.assertTrue(enwp_file.exists())
self.assertFalse(commons_file.exists())

self.assertFalse(enwp_file.fileIsShared())
self.assertRaises(pywikibot.NoPage, commons_file.fileIsShared)

self.assertRaises(pywikibot.NoPage, commons_file.fileUrl)
self.assertRaises(pywikibot.NoPage, commons_file.get_file_url)
self.assertRaises(pywikibot.NoPage, commons_file.get)

def testOnBoth(self):
Expand All @@ -100,7 +110,7 @@ def testOnBoth(self):

commons_file = pywikibot.FilePage(commons, title)

self.assertTrue(itwp_file.fileUrl())
self.assertTrue(itwp_file.get_file_url())
self.assertTrue(itwp_file.exists())
self.assertTrue(commons_file.exists())

Expand All @@ -115,13 +125,13 @@ def testNonFileLocal(self):
testwp = self.get_site('testwiki')
testwp_file = pywikibot.FilePage(testwp, title)

self.assertTrue(testwp_file.fileUrl())
self.assertTrue(testwp_file.latest_file_info.url)
self.assertTrue(testwp_file.exists())
self.assertTrue(testwp_file.fileIsShared())

commons_file = pywikibot.FilePage(commons, title)
self.assertEqual(testwp_file.fileUrl(),
commons_file.fileUrl())
self.assertEqual(testwp_file.get_file_url(),
commons_file.get_file_url())


class TestFilePage(TestCase):
Expand Down

0 comments on commit a5e5a3f

Please sign in to comment.