Unit test for class Chaff
(self)
| 37 | """Test case for module Chaff""" |
| 38 | |
| 39 | def test_Chaff(self): |
| 40 | """Unit test for class Chaff""" |
| 41 | tmp_dir = mkdtemp(prefix='bleachbit-chaff') |
| 42 | models_dir = os.path.join(tmp_dir, 'model') |
| 43 | os.mkdir(models_dir) |
| 44 | # con=Clinton content |
| 45 | con_path = os.path.join(models_dir, 'clinton_content_model.json.bz2') |
| 46 | # sub=Clinton subject |
| 47 | sub_path = os.path.join(models_dir, 'clinton_subject_model.json.bz2') |
| 48 | # ts = 2600 Magazine |
| 49 | ts_path = os.path.join(models_dir, '2600_model.json.bz2') |
| 50 | |
| 51 | for _i in ('download', 'already downloaded'): |
| 52 | ret = download_models(models_dir=models_dir) |
| 53 | self.assertIsInstance(ret, bool) |
| 54 | self.assertTrue( |
| 55 | ret, "download_models() return False, meaning a download error occurred") |
| 56 | |
| 57 | self.assertExists(con_path) |
| 58 | self.assertExists(sub_path) |
| 59 | self.assertExists(ts_path) |
| 60 | |
| 61 | generated_file_names = generate_emails(5, tmp_dir, models_dir) |
| 62 | |
| 63 | self.assertEqual(len(generated_file_names), 5) |
| 64 | |
| 65 | for fn in generated_file_names: |
| 66 | self.assertExists(fn) |
| 67 | self.assertGreater(getsize(fn), 100) |
| 68 | with open(fn) as f: |
| 69 | contents = f.read() |
| 70 | self.assertIn('To: ', contents) |
| 71 | self.assertIn('From: ', contents) |
| 72 | self.assertIn('Sent: ', contents) |
| 73 | self.assertIn('Subject: ', contents) |
| 74 | self.assertNotIn('base64', contents) |
| 75 | |
| 76 | generated_file_names = generate_2600(5, tmp_dir, models_dir) |
| 77 | |
| 78 | rmtree(tmp_dir) |
| 79 | |
| 80 | @mock.patch('bleachbit.Network.download_url_to_fn') |
| 81 | def test_download_models_fallback(self, mock_download): |
nothing calls this directly
no test coverage detected