def test_get_pages_from_allrevisions_from_date(self): HTTPServer.routes() body = read_file("data/mediawiki_pages_allrevisions.json") client = MediaWikiClient(MEDIAWIKI_SERVER_URL) namespaces = ["0"] str_date = "2016-01-01 00:00" dt = str_to_datetime(str_date) from_date = datetime_to_utc(dt) response = client.get_pages_from_allrevisions(namespaces, from_date) req = HTTPServer.requests_http[-1] self.assertEqual(response, body) self.assertEqual(req.method, "GET") self.assertRegex(req.path, "/api.php") # Check request params expected = { "action": ["query"], "list": ["allrevisions"], "arvnamespace": ["0"], "arvdir": ["newer"], "arvlimit": ["max"], "format": ["json"], "arvprop": ["ids"], "arvstart": ["2016-01-01T00:00:00Z"], } self.assertDictEqual(req.querystring, expected) from_date = datetime.datetime(2016, 1, 1, 0, 0, 0) with self.assertRaises(ValueError): _ = client.get_pages_from_allrevisions(namespaces, from_date)
def test_get_pages_from_allrevisions_from_date(self): HTTPServer.routes() body = read_file('data/mediawiki_pages_allrevisions.json') client = MediaWikiClient(MEDIAWIKI_SERVER_URL) namespaces = ['0'] str_date = '2016-01-01 00:00' dt = str_to_datetime(str_date) from_date = datetime_to_utc(dt) response = client.get_pages_from_allrevisions(namespaces, from_date) req = HTTPServer.requests_http[-1] self.assertEqual(response, body) self.assertEqual(req.method, 'GET') self.assertRegex(req.path, '/api.php') # Check request params expected = { 'action': ['query'], 'list': ['allrevisions'], 'arvnamespace': ['0'], 'arvdir': ['newer'], 'arvlimit': ['max'], 'format': ['json'], 'arvprop': ['ids'], 'arvstart': ['2016-01-01T00:00:00Z'] } self.assertDictEqual(req.querystring, expected) from_date = datetime.datetime(2016, 1, 1, 0, 0, 0) with self.assertRaises(ValueError): _ = client.get_pages_from_allrevisions(namespaces, from_date)
def test_get_pages_from_allrevisions_from_date(self): HTTPServer.routes() body = read_file('data/mediawiki_pages_allrevisions.json') client = MediaWikiClient(MEDIAWIKI_SERVER_URL) namespaces = ['0'] str_date = '2016-01-01 00:00' dt = str_to_datetime(str_date) from_date = datetime_to_utc(dt) response = client.get_pages_from_allrevisions(namespaces, from_date) req = HTTPServer.requests_http[-1] self.assertEqual(response, body) self.assertEqual(req.method, 'GET') self.assertRegex(req.path, '/api.php') # Check request params expected = { 'action' : ['query'], 'list' : ['allrevisions'], 'arvnamespace':['0'], 'arvdir':['newer'], 'arvlimit':['max'], 'format':['json'], 'arvprop': ['ids'], 'arvstart': ['2016-01-01T00:00:00Z'] } self.assertDictEqual(req.querystring, expected) from_date = datetime.datetime(2016, 1, 1, 0, 0, 0) with self.assertRaises(ValueError): _ = client.get_pages_from_allrevisions(namespaces, from_date)
def test_get_namespaces(self): HTTPServer.routes() body = read_file("data/mediawiki_namespaces.json") client = MediaWikiClient(MEDIAWIKI_SERVER_URL) response = client.get_namespaces() req = HTTPServer.requests_http[-1] self.assertEqual(response, body) self.assertEqual(req.method, "GET") self.assertRegex(req.path, "/api.php") # Check request params expected = {"action": ["query"], "meta": ["siteinfo"], "siprop": ["namespaces"], "format": ["json"]} self.assertDictEqual(req.querystring, expected)
def test_get_namespaces(self): HTTPServer.routes() body = read_file('data/mediawiki_namespaces.json') client = MediaWikiClient(MEDIAWIKI_SERVER_URL) response = client.get_namespaces() req = HTTPServer.requests_http[-1] self.assertEqual(response, body) self.assertEqual(req.method, 'GET') self.assertRegex(req.path, '/api.php') # Check request params expected = { 'action': ['query'], 'meta': ['siteinfo'], 'siprop': ['namespaces'], 'format': ['json'] } self.assertDictEqual(req.querystring, expected)
def test_get_namespaces(self): HTTPServer.routes() body = read_file('data/mediawiki_namespaces.json') client = MediaWikiClient(MEDIAWIKI_SERVER_URL) response = client.get_namespaces() req = HTTPServer.requests_http[-1] self.assertEqual(response, body) self.assertEqual(req.method, 'GET') self.assertRegex(req.path, '/api.php') # Check request params expected = { 'action' : ['query'], 'meta' : ['siteinfo'], 'siprop':['namespaces'], 'format':['json'] } self.assertDictEqual(req.querystring, expected)
def test_get_revisions(self): HTTPServer.routes() body = read_file('data/mediawiki_page_476583_revisions.json') client = MediaWikiClient(MEDIAWIKI_SERVER_URL) response = client.get_revisions('VisualEditor') req = HTTPServer.requests_http[-1] self.assertEqual(response, body) self.assertEqual(req.method, 'GET') self.assertRegex(req.path, '/api.php') # Check request params expected = { 'action': ['query'], 'prop': ['revisions'], 'titles': ['VisualEditor'], 'format': ['json'], 'rvlimit': ['max'], 'rvdir': ['newer'] } self.assertDictEqual(req.querystring, expected)
def test_get_pages(self): HTTPServer.routes() body = read_file('data/mediawiki_pages_all.json') client = MediaWikiClient(MEDIAWIKI_SERVER_URL) namespace = '0' response = client.get_pages(namespace) req = HTTPServer.requests_http[-1] self.assertEqual(response, body) self.assertEqual(req.method, 'GET') self.assertRegex(req.path, '/api.php') # Check request params expected = { 'action': ['query'], 'list': ['allpages'], 'apnamespace': ['0'], 'aplimit': ['max'], 'format': ['json'] } self.assertDictEqual(req.querystring, expected)
def test_get_revisions(self): HTTPServer.routes() body = read_file('data/mediawiki_page_476583_revisions.json') client = MediaWikiClient(MEDIAWIKI_SERVER_URL) response = client.get_revisions('VisualEditor') req = HTTPServer.requests_http[-1] self.assertEqual(response, body) self.assertEqual(req.method, 'GET') self.assertRegex(req.path, '/api.php') # Check request params expected = { 'action' : ['query'], 'prop':['revisions'], 'titles':['VisualEditor'], 'format':['json'], 'rvlimit': ['max'], 'rvdir': ['newer'] } self.assertDictEqual(req.querystring, expected)
def test_get_pages(self): HTTPServer.routes() body = read_file('data/mediawiki_pages_all.json') client = MediaWikiClient(MEDIAWIKI_SERVER_URL) namespace = '0' response = client.get_pages(namespace) req = HTTPServer.requests_http[-1] self.assertEqual(response, body) self.assertEqual(req.method, 'GET') self.assertRegex(req.path, '/api.php') # Check request params expected = { 'action' : ['query'], 'list' : ['allpages'], 'apnamespace':['0'], 'aplimit':['max'], 'format':['json'] } self.assertDictEqual(req.querystring, expected)
def test_get_revisions(self): HTTPServer.routes() body = read_file("data/mediawiki_page_476583_revisions.json") client = MediaWikiClient(MEDIAWIKI_SERVER_URL) response = client.get_revisions("VisualEditor") req = HTTPServer.requests_http[-1] self.assertEqual(response, body) self.assertEqual(req.method, "GET") self.assertRegex(req.path, "/api.php") # Check request params expected = { "action": ["query"], "prop": ["revisions"], "titles": ["VisualEditor"], "format": ["json"], "rvlimit": ["max"], "rvdir": ["newer"], } self.assertDictEqual(req.querystring, expected)
def test_get_pages(self): HTTPServer.routes() body = read_file("data/mediawiki_pages_all.json") client = MediaWikiClient(MEDIAWIKI_SERVER_URL) namespace = "0" response = client.get_pages(namespace) req = HTTPServer.requests_http[-1] self.assertEqual(response, body) self.assertEqual(req.method, "GET") self.assertRegex(req.path, "/api.php") # Check request params expected = { "action": ["query"], "list": ["allpages"], "apnamespace": ["0"], "aplimit": ["max"], "format": ["json"], } self.assertDictEqual(req.querystring, expected)
def __test_get_version(self, version): if version == "1.23": HTTPServer.routes("1.23") body = read_file("data/mediawiki_siteinfo_1.23.json") response_ok = [1, 23] elif version == "1.28": HTTPServer.routes("1.28") body = read_file("data/mediawiki_siteinfo_1.28.json") response_ok = [1, 28] else: self.assertEqual(False) client = MediaWikiClient(MEDIAWIKI_SERVER_URL) response = client.get_version() req = HTTPServer.requests_http[-1] self.assertEqual(response, response_ok) self.assertEqual(req.method, "GET") self.assertRegex(req.path, "/api.php") # Check request params expected = {"action": ["query"], "meta": ["siteinfo"], "format": ["json"]} self.assertDictEqual(req.querystring, expected)
def __test_get_version(self, version): if version == "1.23": HTTPServer.routes('1.23') body = read_file('data/mediawiki_siteinfo_1.23.json') response_ok = [1, 23] elif version == "1.28": HTTPServer.routes('1.28') body = read_file('data/mediawiki_siteinfo_1.28.json') response_ok = [1, 28] else: self.assertEqual(False) client = MediaWikiClient(MEDIAWIKI_SERVER_URL) response = client.get_version() req = HTTPServer.requests_http[-1] self.assertEqual(response, response_ok) self.assertEqual(req.method, 'GET') self.assertRegex(req.path, '/api.php') # Check request params expected = { 'action': ['query'], 'meta': ['siteinfo'], 'format': ['json'] } self.assertDictEqual(req.querystring, expected)
def __test_get_version(self, version): if version == "1.23": HTTPServer.routes('1.23') body = read_file('data/mediawiki_siteinfo_1.23.json') response_ok = [1, 23] elif version == "1.28": HTTPServer.routes('1.28') body = read_file('data/mediawiki_siteinfo_1.28.json') response_ok = [1, 28] else: self.assertEqual(False) client = MediaWikiClient(MEDIAWIKI_SERVER_URL) response = client.get_version() req = HTTPServer.requests_http[-1] self.assertEqual(response, response_ok) self.assertEqual(req.method, 'GET') self.assertRegex(req.path, '/api.php') # Check request params expected = { 'action' : ['query'], 'meta' : ['siteinfo'], 'format':['json'] } self.assertDictEqual(req.querystring, expected)