Пример #1
0
    def setUp(self):
        super(CLITestHelper, self).setUp()
        self.pii_file = create_temp_file()
        self.pii_file_2 = create_temp_file()

        # Get random PII
        pii_data = randomnames.NameList(self.SAMPLES)
        data = [(name, dob) for _, name, dob, _ in pii_data.names]

        headers = ['NAME freetext', 'DOB YYYY/MM/DD']
        randomnames.save_csv(data, headers, self.pii_file)

        random.shuffle(data)
        randomnames.save_csv(data[::2], headers, self.pii_file_2)

        self.default_schema = [{
            "identifier": "INDEX"
        }, {
            "identifier": "NAME freetext"
        }, {
            "identifier": "DOB YYYY/MM/DD"
        }, {
            "identifier": "GENDER M or F"
        }]

        self.pii_file.close()
        self.pii_file_2.close()
Пример #2
0
 def test_save_csv(self):
     stringIO = StringIO()
     headers = ['Name', 'Count']
     body = [('a', 1), ('b', 2)]
     rn.save_csv(body, headers, stringIO)
     self.assertListEqual(stringIO.getvalue().split(),
                          ['Name,Count', 'a,1', 'b,2'])
Пример #3
0
    def setUp(self):
        self.pii_file = create_temp_file()

        pii_data = randomnames.NameList(TestHasherDefaultSchema.samples)
        randomnames.save_csv(pii_data.names,
                             [f.identifier for f in pii_data.SCHEMA.fields],
                             self.pii_file)
        self.pii_file.flush()
Пример #4
0
def generate(size, output, schema):
    """Generate fake PII data for testing"""
    pii_data = randomnames.NameList(size)

    if schema is not None:
        raise NotImplementedError

    randomnames.save_csv(pii_data.names,
                         [f.identifier for f in pii_data.SCHEMA.fields],
                         output)
Пример #5
0
    def test_hashing_json_schema(self):
        runner = CliRunner()

        pii_data = randomnames.NameList(self.SAMPLES)
        pii_file = create_temp_file()
        randomnames.save_csv(pii_data.names,
                             [f.identifier for f in pii_data.SCHEMA.fields],
                             pii_file)
        pii_file.close()

        with temporary_file() as output_filename:
            with open(output_filename) as output:
                cli_result = runner.invoke(
                    cli.cli,
                    ['hash', pii_file.name, 'secret', RANDOMNAMES_SCHEMA_PATH, output.name])

            self.assertEqual(cli_result.exit_code, 0, msg=cli_result.output)

            with open(output_filename) as output:
                self.assertIn('clks', json.load(output))