Skip to content

Commit c21b411

Browse files
author
rootware
committed
added more test for unredaction
1 parent 0553ad3 commit c21b411

File tree

2 files changed

+36
-12
lines changed

2 files changed

+36
-12
lines changed

test/test_redact.py

Lines changed: 36 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import pytest
22
from pyredactkit.redact import Redactor
3+
from pyredactkit.unredact import Unredactor
4+
from pyredactkit.identifiers import Identifier
35

46
data = """John, please get that article on www.linkedin.com to me by 5:00PM on Jan 9th 2012. 4:00 would be ideal, actually. If you have any questions, You can reach me at(519)-236-2723 or get in touch with my associate at [email protected]
57
this is my IP: 102.23.5.1
@@ -42,30 +44,52 @@
4244
people_names = "John,Jones,Alex,Bruce"
4345
mask_names = "\u2588" * 15
4446
count_names = 4
47+
key_mapping = {
48+
"2b21e939-abc9-4d06-9c5a-de9bf2aa22b4": "10.10.10.1"}
49+
redacted_text = "My router is : 2b21e939-abc9-4d06-9c5a-de9bf2aa22b4"
50+
unredacted_text = "My router is : 10.10.10.1"
51+
4552

4653
@pytest.fixture
47-
def obj():
54+
def redactor_obj():
4855
return Redactor()
4956

5057

51-
def test_check_python_file(obj):
52-
assert obj.check_file_type(
58+
@pytest.fixture
59+
def unredactor_obj():
60+
return Unredactor()
61+
62+
63+
@pytest.fixture
64+
def identifier_obj():
65+
return Identifier()
66+
67+
68+
def test_check_python_file(redactor_obj):
69+
assert redactor_obj.check_file_type(
5370
__file__) == 'text/x-python', 'Failed python file check'
5471

5572

56-
def test_number_of_allowed_types(obj):
57-
assert len(obj.get_allowed_files()
73+
def test_number_of_allowed_types(redactor_obj):
74+
assert len(redactor_obj.get_allowed_files()
5875
) == 10, 'Number of allowed tests does not match expected'
5976

6077

61-
def test_current_file_is_allowed(obj):
62-
assert obj.allowed_file(__file__), f'{__file__} should be allowed'
78+
def test_current_file_is_allowed(redactor_obj):
79+
assert redactor_obj.allowed_file(__file__), f'{__file__} should be allowed'
80+
81+
82+
def test_valid_option_function_should_return_tuple(redactor_obj):
83+
assert type(redactor_obj.valid_options()
84+
) == tuple, 'redact function should return tuple'
6385

6486

65-
def test_redact_function_should_return_string(obj):
66-
assert type(obj.redact(data)) == str, 'redact function should return string'
87+
def test_redact_name_function_should_return_string_and_integer(redactor_obj):
88+
set1 = (f'{mask_names},{mask_names},{mask_names},{mask_names}', count_names)
89+
assert redactor_obj.redact_name(
90+
people_names) == set1, 'redact_name function should return masked data and count'
6791

6892

69-
def test_redact_name_function_should_return_string_and_integer(obj):
70-
set1 = (f'{mask_names},{mask_names},{mask_names},{mask_names}',count_names)
71-
assert obj.redact_name(people_names) == set1, 'redact_name function should return masked data and count'
93+
def test_replace_all_function_should_return_unredacted_string(unredactor_obj):
94+
assert unredactor_obj.replace_all(
95+
redacted_text, key_mapping) == unredacted_text, 'replace_all function should return unredacted string'

0 commit comments

Comments
 (0)