diff options
| author | jvoisin | 2019-09-01 13:34:26 +0200 |
|---|---|---|
| committer | jvoisin | 2019-09-01 13:52:02 +0200 |
| commit | fc924239febb3f186585d9ea6c263e1cb7dc690d (patch) | |
| tree | 26a55471c577a70b1c304a08fa86afa468fd1659 /tests/test_deep_cleaning.py | |
| parent | 0170f0e37ec9fefd1ac2829a070b76b91c999b92 (diff) | |
Add a test for nsid cleaning
Diffstat (limited to '')
| -rw-r--r-- | tests/test_deep_cleaning.py | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/tests/test_deep_cleaning.py b/tests/test_deep_cleaning.py index ccd4955..aab46c7 100644 --- a/tests/test_deep_cleaning.py +++ b/tests/test_deep_cleaning.py | |||
| @@ -137,3 +137,34 @@ class TestRsidRemoval(unittest.TestCase): | |||
| 137 | 137 | ||
| 138 | os.remove('./tests/data/clean.docx') | 138 | os.remove('./tests/data/clean.docx') |
| 139 | os.remove('./tests/data/clean.cleaned.docx') | 139 | os.remove('./tests/data/clean.cleaned.docx') |
| 140 | |||
| 141 | |||
| 142 | class TestNsidRemoval(unittest.TestCase): | ||
| 143 | def test_office(self): | ||
| 144 | shutil.copy('./tests/data/dirty_with_nsid.docx', './tests/data/clean.docx') | ||
| 145 | p = office.MSOfficeParser('./tests/data/clean.docx') | ||
| 146 | |||
| 147 | meta = p.get_meta() | ||
| 148 | self.assertIsNotNone(meta) | ||
| 149 | |||
| 150 | how_many_rsid = False | ||
| 151 | with zipfile.ZipFile('./tests/data/clean.docx') as zin: | ||
| 152 | for item in zin.infolist(): | ||
| 153 | if not item.filename.endswith('.xml'): | ||
| 154 | continue | ||
| 155 | num = zin.read(item).decode('utf-8').lower().count('w:rsid') | ||
| 156 | how_many_rsid += num | ||
| 157 | self.assertEqual(how_many_rsid, 1190) | ||
| 158 | |||
| 159 | ret = p.remove_all() | ||
| 160 | self.assertTrue(ret) | ||
| 161 | |||
| 162 | with zipfile.ZipFile('./tests/data/clean.cleaned.docx') as zin: | ||
| 163 | for item in zin.infolist(): | ||
| 164 | if not item.filename.endswith('.xml'): | ||
| 165 | continue | ||
| 166 | num = zin.read(item).decode('utf-8').lower().count('w:nsid') | ||
| 167 | self.assertEqual(num, 0) | ||
| 168 | |||
| 169 | os.remove('./tests/data/clean.docx') | ||
| 170 | os.remove('./tests/data/clean.cleaned.docx') | ||
