def test_conversion(self): """Check if it converts some timestamps to timestamps with UTC+0""" date = datetime.datetime(2001, 12, 1, 23, 15, 32, tzinfo=dateutil.tz.tzoffset(None, -21600)) expected = datetime.datetime(2001, 12, 2, 5, 15, 32, tzinfo=dateutil.tz.tzutc()) utc = datetime_to_utc(date) self.assertIsInstance(utc, datetime.datetime) self.assertEqual(utc, expected) date = datetime.datetime(2001, 12, 1, 23, 15, 32, tzinfo=dateutil.tz.tzutc()) expected = datetime.datetime(2001, 12, 1, 23, 15, 32, tzinfo=dateutil.tz.tzutc()) utc = datetime_to_utc(date) self.assertIsInstance(utc, datetime.datetime) self.assertEqual(utc, expected) date = datetime.datetime(2001, 12, 1, 23, 15, 32) expected = datetime.datetime(2001, 12, 1, 23, 15, 32, tzinfo=dateutil.tz.tzutc()) utc = datetime_to_utc(date) self.assertIsInstance(utc, datetime.datetime) self.assertEqual(utc, expected)
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)