def test_fetch_from_archive(self, mock_nntp): """Test whether the fetch from archive method works properly""" mock_nntp.return_value = MockNNTPLib() # first we upload data to the archive client = NNTTPClient(NNTP_SERVER, archive=self.archive, from_archive=False) group = client.group("example.dev.project-link") over = client.over((1, 1)) article = client.article(2) # then we read the data within the archive client = NNTTPClient(NNTP_SERVER, archive=self.archive, from_archive=True) group_archived = client._fetch_from_archive( "group", "example.dev.project-link") self.assertEqual(group, group_archived) over_archived = client._fetch_from_archive("over", (1, 1)) self.assertEqual(over, over_archived) article_archived = client._fetch_from_archive("article", 2) self.assertEqual(article, article_archived)
def initalization(self, mock_nntp): """Test whether the client is correctly initialized""" mock_nntp.return_value = MockNNTPLib() client = NNTTPClient(NNTP_SERVER, archive=None, from_archive=False) self.assertEqual(client.host, NNTP_SERVER) self.assertIsNone(client.archive) self.assertFalse(client.from_archive) self.assertIsNone(client.handler) mock_nntp.return_value = MockNNTPLib() client = NNTTPClient(NNTP_SERVER, archive=self.archive, from_archive=False) self.assertEqual(client.host, NNTP_SERVER) self.assertEqual(client.archive, self.archive) self.assertFalse(client.from_archive) self.assertIsNotNone(client.handler) mock_nntp.return_value = MockNNTPLib() client = NNTTPClient(NNTP_SERVER, archive=self.archive, from_archive=True) self.assertEqual(client.host, NNTP_SERVER) self.assertEqual(client.archive, self.archive) self.assertTrue(client.from_archive) self.assertIsNotNone(client.handler)
def test_fetch_remote_nntp_temporary_error(self, mock_nntp): """Test whether an exception is thrown in case of temporary error""" mock_nntp.return_value = MockNNTPLib() client = NNTTPClient(NNTP_SERVER, archive=None, from_archive=False) with self.assertRaises(nntplib.NNTPTemporaryError): client._fetch_from_remote("article", 3)
def test_archive_not_provided(self, mock_nntp): """Test whether an exception is thrown if the archive is not provided""" mock_nntp.return_value = MockNNTPLib() client = NNTTPClient(NNTP_SERVER, archive=None, from_archive=True) with self.assertRaises(ArchiveError): client.group("example.dev.project-link")
def test_fetch_from_article(self, mock_nntp): """Test whether the fetch_from_article works properly""" mock_nntp.return_value = MockNNTPLib() client = NNTTPClient(NNTP_SERVER, archive=self.archive, from_archive=False) data = client._fetch_article(2) self.assertEqual(len(data), 3) self.assertIsNotNone(data['lines']) self.assertEqual(len(data['lines']), 220) self.assertIsNotNone(data['message_id']) self.assertEqual(data['message_id'], '<*****@*****.**>') self.assertIsNotNone(data['number']) self.assertEqual(data['number'], 2)
def test_article(self, mock_nntp): """Test whether the article method works properly""" mock_nntp.return_value = MockNNTPLib() client = NNTTPClient(NNTP_SERVER, archive=self.archive, from_archive=False) data = client.article(2) self.assertEqual(len(data), 3) self.assertEqual(len(data['lines']), 220) self.assertEqual(data['lines'][-1], b'--lATx5p5hwwFl8QooX4JNWNU6e6LBSB7ES--') self.assertEqual( data['message_id'], '<*****@*****.**>') self.assertEqual(data['number'], 2) client = NNTTPClient(NNTP_SERVER, archive=self.archive, from_archive=True) archived_data = client.article(2) self.assertEqual(len(data), 3) self.assertEqual(len(data['lines']), 220) self.assertEqual(data['lines'][-1], b'--lATx5p5hwwFl8QooX4JNWNU6e6LBSB7ES--') self.assertEqual( data['message_id'], '<*****@*****.**>') self.assertEqual(data['number'], 2) self.assertEqual(data, archived_data)
def test_over(self, mock_nntp): """Test whether the over method works properly""" mock_nntp.return_value = MockNNTPLib() client = NNTTPClient(NNTP_SERVER, archive=self.archive, from_archive=False) data = client.over((1, 1)) self.assertEqual(len(data), 2) self.assertDictEqual( data[1][0][1], { 'message_id': '<*****@*****.**>' }) client = NNTTPClient(NNTP_SERVER, archive=self.archive, from_archive=True) archived_data = client.over((1, 1)) self.assertEqual(len(data), 2) self.assertDictEqual( data[1][0][1], { 'message_id': '<*****@*****.**>' }) self.assertEqual(data, archived_data)
def test_group(self, mock_nntp): """Test whether the group method works properly""" mock_nntp.return_value = MockNNTPLib() client = NNTTPClient(NNTP_SERVER, archive=self.archive, from_archive=False) data = client.group("example.dev.project-link") self.assertEqual((None, None, 1, 4, None), data) client = NNTTPClient(NNTP_SERVER, archive=self.archive, from_archive=True) archived_data = client.group("example.dev.project-link") self.assertEqual((None, None, 1, 4, None), data) self.assertEqual(data, archived_data)