-
Notifications
You must be signed in to change notification settings - Fork 97
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix:dev:Use generators in dbmetadata classes
Previously connections and cursors were passed to DbMetadata classes such as tables and columns. This lead to unclean interfaces and unit test dependencies. The move to a generator has helped in cleaning up the tech debt
- Loading branch information
Showing
5 changed files
with
109 additions
and
73 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
from unittest import TestCase | ||
from piicatcher.dbmetadata import Column, Table, Schema | ||
|
||
|
||
class DbMetadataTests(TestCase): | ||
|
||
data = { | ||
"no_pii": [ | ||
('abc', 'def'), | ||
('xsfr', 'asawe') | ||
], | ||
"partial_pii": [ | ||
('917-908-2234', 'plkj'), | ||
('215-099-2234', 'sfrf') | ||
], | ||
"full_pii": [ | ||
('Jonathan Smith', 'Virginia'), | ||
('Chase Ryan', 'Chennai') | ||
] | ||
} | ||
|
||
@staticmethod | ||
def data_generator(schema_name, table_name, column_list): | ||
for row in DbMetadataTests.data[table_name.get_name()]: | ||
yield row | ||
|
||
def test_negative_scan_column(self): | ||
col = Column('col') | ||
col.scan('abc') | ||
self.assertFalse(col.has_pii()) | ||
|
||
def test_positive_scan_column(self): | ||
col = Column('col') | ||
col.scan('Jonathan Smith') | ||
self.assertTrue(col.has_pii()) | ||
|
||
def test_no_pii_table(self): | ||
schema = Schema('public') | ||
table = Table(schema, 'no_pii') | ||
table.add(Column('a')) | ||
table.add(Column('b')) | ||
|
||
table.scan(self.data_generator) | ||
self.assertFalse(table.has_pii()) | ||
|
||
def test_partial_pii_table(self): | ||
schema = Schema('public') | ||
table = Table(schema, 'partial_pii') | ||
table.add(Column('a')) | ||
table.add(Column('b')) | ||
|
||
table.scan(self.data_generator) | ||
self.assertTrue(table.has_pii()) | ||
cols = table.get_columns() | ||
self.assertTrue(cols[0].has_pii()) | ||
self.assertFalse(cols[1].has_pii()) | ||
|
||
def test_full_pii_table(self): | ||
schema = Schema('public') | ||
table = Table(schema, 'full_pii') | ||
table.add(Column('name')) | ||
table.add(Column('location')) | ||
|
||
table.scan(self.data_generator) | ||
self.assertTrue(table.has_pii()) | ||
|
||
cols = table.get_columns() | ||
self.assertTrue(cols[0].has_pii()) | ||
self.assertTrue(cols[1].has_pii()) |