Skip to content

Commit add3d34

Browse files
authored
Initial tests (#14)
1 parent 56507a1 commit add3d34

File tree

12 files changed

+100
-14
lines changed

12 files changed

+100
-14
lines changed

.flake8

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@ per-file-ignores = tests/*:S101,*__init__.py:F401 D104,*helpers.py:S311
33
application-import-names = redactdump,tests
44
import-order-style = google
55
select = B,B9,BLK,C,E,F,I,S,W, D, A
6-
ignore = E203,E501,W503,ANN101,D100,D107,D401,S404,S607,S603,S605,S101,S602, S608
6+
ignore = E203,E501,W503,ANN101,D100,D107,D401,S404,S607,S603,S605,S101,S602,S608,B905
77
max-line-length = 120

.github/workflows/test.yaml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
name: "Test"
2+
3+
on:
4+
push:
5+
6+
jobs:
7+
test:
8+
name: test
9+
runs-on: ubuntu-latest
10+
permissions:
11+
actions: read
12+
contents: read
13+
14+
steps:
15+
- name: Checkout repository
16+
uses: actions/checkout@v2
17+
18+
- name: Install dependencies
19+
run: python -m pip install -r dev-requirements.txt
20+
21+
- name: Run tests
22+
run: python -m pytest

.github/workflows/type-lint.yaml

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,6 @@ name: "Typing and Linting"
22

33
on:
44
push:
5-
branches: [ main ]
6-
paths-ignore:
7-
- "README.md"
8-
pull_request:
9-
branches: [ main ]
10-
paths-ignore:
11-
- "README.md"
125

136
jobs:
147
lint:

dev-requirements.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@ rich==10.15.2
33
setuptools~=59.5.0
44
PyYAML~=6.0
55
schema~=0.7.5
6-
psycopg2==2.9.2
6+
psycopg2-binary==2.9.3
77
SQLAlchemy~=1.4.27
88
faker==10.0.0
99
pymysql==1.0.2
10+
pytest==6.2.5
11+
nox==2022.11.21

noxfile.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import nox
22
from nox.sessions import Session
33

4-
locations = "redactdump", "noxfile.py"
4+
locations = "redactdump", "noxfile.py", "tests"
55
python_versions = ["3.9"]
66
nox.options.sessions = "lint", "mypy"
77

redactdump/core/redactor.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from dataclasses import dataclass
22
import re
3-
from typing import Any, List, Pattern
3+
from typing import Any, List, Pattern, Union
44

55
from faker import Faker
66

@@ -61,7 +61,7 @@ def load_rules(self) -> None:
6161
)
6262
)
6363

64-
def get_replacement(self, replacement: str) -> Any:
64+
def get_replacement(self, replacement: str) -> Union[str, Any]:
6565
"""
6666
Get replacement value.
6767

setup.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,10 @@
2626
install_requires=[
2727
'rich==10.15.2',
2828
'PyYAML==6.0',
29-
'schema==0.7.4',
29+
'schema==0.7.5',
3030
'configargparse==1.5.3',
3131
'SQLAlchemy~=1.4.27',
32-
'psycopg2==2.9.2',
32+
'psycopg2-binary==2.9.3',
3333
'pymysql==1.0.2',
3434
'faker==10.0.0'
3535
],

tests/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
!config.yaml

tests/config.yaml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
connection:
2+
type: pgsql
3+
host: 127.0.0.1
4+
port: 5432
5+
database: postgres
6+
7+
redact:
8+
patterns:
9+
column:
10+
- pattern: '^[a-zA-Z]+_name'
11+
replacement: name
12+
data:
13+
- pattern: '192.168.0.1'
14+
replacement: ipv4
15+
- pattern: 'John Doe'
16+
replacement: name
17+
18+
output:
19+
type: multi_file
20+
naming: 'dump-[table_name]-[timestamp]' # Default: [table_name]-[timestamp]
21+
location: 'tests/tmp/test_output'

tests/test_config.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
from configargparse import Namespace
2+
3+
from redactdump.core.config import Config
4+
5+
6+
def test_config_load() -> None:
7+
"""Test Config loading."""
8+
config = Config(Namespace(config="tests/config.yaml"))
9+
10+
assert type(config) is Config
11+
assert type(config.config) is dict

tests/test_database.py

Whitespace-only changes.

tests/test_redactor.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
from configargparse import Namespace
2+
3+
from redactdump.core import Config
4+
from redactdump.core.redactor import Redactor
5+
6+
7+
def test_redaction() -> None:
8+
"""Test data redaction."""
9+
config = Config(Namespace(config="tests/config.yaml", debug=False))
10+
redactor = Redactor(config)
11+
12+
data = [
13+
{
14+
"full_name": "Test Name",
15+
"secondary_name": "John Doe",
16+
"ip": "192.168.0.1",
17+
"email": "my@email.com",
18+
}
19+
]
20+
original = [
21+
{
22+
"full_name": "Test Name",
23+
"secondary_name": "John Doe",
24+
"ip": "192.168.0.1",
25+
"email": "my@email.com",
26+
}
27+
]
28+
29+
for idx, item in enumerate(data):
30+
31+
if redactor.data_rules or redactor.column_rules:
32+
redactor.redact(item, ["full_name", "email"])
33+
assert data[idx]["full_name"] != original[idx]["full_name"]
34+
assert data[idx]["secondary_name"] != original[idx]["secondary_name"]
35+
assert data[idx]["ip"] != original[idx]["ip"]
36+
assert data[idx]["email"] == original[idx]["email"]

0 commit comments

Comments
 (0)