langdonholmes commited on
Commit
ceb9976
1 Parent(s): 5959a8e

update tests

Browse files
Files changed (2) hide show
  1. piilo/test_main.py +17 -27
  2. requirements.txt +0 -0
piilo/test_main.py CHANGED
@@ -1,30 +1,14 @@
1
  import logging
2
 
3
- from fastapi.testclient import TestClient
4
-
5
- logger = logging.getLogger('api')
6
  logging.basicConfig(level=logging.INFO)
7
 
8
- def test_read_main():
9
- response = client.get("/")
10
- assert response.status_code == 200
11
- assert response.json() == {"message": "Hello World"}
12
-
13
- def test_email():
14
- response = client.post("/anonymize",
15
- json={"raw_text": "My name is joe@aol.com"},
16
- )
17
- assert response.status_code == 200
18
- assert response.json() == {
19
- "anonymized_text": "My name is janedoe@aol.com"
20
- }
21
 
22
- def test_name():
23
- response = client.post("/anonymize",
24
- json={"raw_text": "My name is Nora Wang"},
25
- )
26
- assert response.status_code == 200
27
- logger.info(response.json())
28
 
29
  if __name__ == "__main__":
30
  from pathlib import Path
@@ -32,9 +16,15 @@ if __name__ == "__main__":
32
  # Add piilo to sys.path so that we can import from piilo
33
  sys.path.insert(0, str(Path(__file__).parent.parent))
34
 
35
- from main import app
36
- client = TestClient(app)
 
 
 
 
 
 
 
37
 
38
- test_read_main()
39
- test_email()
40
- test_name()
 
1
  import logging
2
 
3
+ logger = logging.getLogger('piilo')
 
 
4
  logging.basicConfig(level=logging.INFO)
5
 
6
+ def test_analyzer(texts):
7
+ return [piilo.analyze(text) for text in texts]
 
 
 
 
 
 
 
 
 
 
 
8
 
9
+
10
+ def test_anonymizer(texts):
11
+ return [piilo.anonymize(text) for text in texts]
 
 
 
12
 
13
  if __name__ == "__main__":
14
  from pathlib import Path
 
16
  # Add piilo to sys.path so that we can import from piilo
17
  sys.path.insert(0, str(Path(__file__).parent.parent))
18
 
19
+ import piilo
20
+
21
+ texts = [
22
+ 'test string without identifiers',
23
+ 'My name is Antonio. Email: Antonio99@yahoo.com'
24
+ ]
25
+
26
+ # To analyze the texts. Returns list of RecognizerResult, defined by presidio_analyzer
27
+ print(test_analyzer(texts))
28
 
29
+ # To analyze AND anonymize with hiding-in-plain-sight obfuscation. Returns list of texts with identifiers obfuscated.
30
+ print(test_anonymizer(texts))
 
requirements.txt CHANGED
Binary files a/requirements.txt and b/requirements.txt differ