def test_fetch(self, mock_utcnow): """Test whether archives are fetched""" mock_utcnow.return_value = datetime.datetime(2016, 4, 10, tzinfo=dateutil.tz.tzutc()) mbox_march = read_file('data/hyperkitty/hyperkitty_2016_march.mbox') mbox_april = read_file('data/hyperkitty/hyperkitty_2016_april.mbox') httpretty.register_uri(httpretty.GET, HYPERKITTY_URL, body="") httpretty.register_uri(httpretty.GET, HYPERKITTY_URL + 'export/2016-03.mbox.gz', body=mbox_march) httpretty.register_uri(httpretty.GET, HYPERKITTY_URL + 'export/2016-04.mbox.gz', body=mbox_april) from_date = datetime.datetime(2016, 3, 10) hkls = HyperKittyList('http://example.com/archives/list/[email protected]/', self.tmp_path) fetched = hkls.fetch(from_date=from_date) self.assertEqual(len(fetched), 2) self.assertEqual(fetched[0][0], HYPERKITTY_URL + 'export/2016-03.mbox.gz') self.assertEqual(fetched[0][1], os.path.join(self.tmp_path, '2016-03.mbox.gz')) self.assertEqual(fetched[1][0], HYPERKITTY_URL + 'export/2016-04.mbox.gz') self.assertEqual(fetched[1][1], os.path.join(self.tmp_path, '2016-04.mbox.gz')) mboxes = hkls.mboxes self.assertEqual(mboxes[0].filepath, os.path.join(self.tmp_path, '2016-03.mbox.gz')) self.assertEqual(mboxes[1].filepath, os.path.join(self.tmp_path, '2016-04.mbox.gz'))
def test_init(self): """Check attributes initialization""" hkls = HyperKittyList(HYPERKITTY_URL, self.tmp_path) self.assertIsInstance(hkls, MailingList) self.assertEqual(hkls.uri, HYPERKITTY_URL) self.assertEqual(hkls.dirpath, self.tmp_path) self.assertEqual(hkls.client.base_url, HYPERKITTY_URL)
def test_mboxes(self): """Test whether it returns the mboxes ordered by the date on their filenames""" # Simulate the fetch process copying the files shutil.copy(os.path.join(os.path.dirname(os.path.abspath(__file__)), 'data/hyperkitty/hyperkitty_2016_march.mbox'), os.path.join(self.tmp_path, '2016-03.mbox.gz')) shutil.copy(os.path.join(os.path.dirname(os.path.abspath(__file__)), 'data/hyperkitty/hyperkitty_2016_april.mbox'), os.path.join(self.tmp_path, '2016-04.mbox.gz')) hkls = HyperKittyList('http://example.com/archives/list/[email protected]/', self.tmp_path) mboxes = hkls.mboxes self.assertEqual(mboxes[0].filepath, os.path.join(self.tmp_path, '2016-03.mbox.gz')) self.assertEqual(mboxes[1].filepath, os.path.join(self.tmp_path, '2016-04.mbox.gz'))
def test_fetch_from_date_after_current_day(self, mock_utcnow): """Test if it does not store anything when from_date is a date from the future""" mock_utcnow.return_value = datetime.datetime( 2016, 4, 10, tzinfo=dateutil.tz.tzutc()) httpretty.register_uri(httpretty.GET, HYPERKITTY_URL, body="") from_date = datetime.datetime(2017, 1, 10) hkls = HyperKittyList( 'http://example.com/archives/list/[email protected]/', self.tmp_path) fetched = hkls.fetch(from_date=from_date) self.assertEqual(len(fetched), 0)