def test_export_matches__records_export(self):
    obj_1 = FirstSearchModelFactory.create(chars='test1', email='example@example.com', anonymised=False)
    obj_2 = FirstSearchModelFactory.create(chars='test2', email='example@example.com', anonymised=False)
    obj_3 = SecondSearchModelFactory.create(chars='test3', email='example@example.com', anonymised=False)
    obj_4 = SecondSearchModelFactory.create(chars='test4', email='example@example.com', anonymised=False)
    content_type_1 = ContentType.objects.get_for_model(FirstSearchModel).pk
    content_type_2 = ContentType.objects.get_for_model(SecondSearchModel).pk
    response = self.client.post(tool_root_url, {'term': 'example@example.com', 'action': gdpr_assist.admin.tool.PersonalDataSearchForm.ACTION_EXPORT, 'obj_pk': ['{}-{}'.format(content_type_1, obj_1.pk), '{}-{}'.format(content_type_2, obj_3.pk), '{}-{}'.format(content_type_2, obj_4.pk)]}, follow=True)
    obj_1.refresh_from_db()
    obj_2.refresh_from_db()
    obj_3.refresh_from_db()
    obj_4.refresh_from_db()
    self.assertFalse(obj_1.anonymised)
    self.assertFalse(obj_2.anonymised)
    self.assertFalse(obj_3.anonymised)
    self.assertFalse(obj_4.anonymised)
    zip_data = BytesIO()
    zip_data.write(response.content)
    zip_file = zipfile.ZipFile(zip_data)
    self.assertEqual(sorted(zip_file.namelist()), ['gdpr_assist_tests_app-FirstSearchModel.csv', 'second_search.csv'])
    if six.PY2:
        mode = 'rU'
    else:
        mode = 'r'
    with zip_file.open('gdpr_assist_tests_app-FirstSearchModel.csv', mode) as f:
        reader = csv.DictReader(TextIOWrapper(f))
        self.assertEqual(reader.fieldnames, ['email'])
        rows = list(reader)
        self.assertEqual(len(rows), 1)
        self.assertEqual(rows[0]['email'], 'example@example.com')
    with zip_file.open('second_search.csv', mode) as f:
        reader = csv.DictReader(TextIOWrapper(f))
        self.assertEqual(sorted(reader.fieldnames), ['chars', 'email'])
        rows = list(reader)
        self.assertEqual(len(rows), 2)
        self.assertEqual(rows[0]['chars'], 'test3')
        self.assertEqual(rows[0]['email'], 'example@example.com')
        self.assertEqual(rows[1]['chars'], 'test4')
        self.assertEqual(rows[1]['email'], 'example@example.com')
def test_export_matches__records_export(self):
    obj_1 = FirstSearchModelFactory.create(chars='test1', email='example@example.com', anonymised=False)
    obj_2 = FirstSearchModelFactory.create(chars='test2', email='example@example.com', anonymised=False)
    obj_3 = SecondSearchModelFactory.create(chars='test3', email='example@example.com', anonymised=False)
    obj_4 = SecondSearchModelFactory.create(chars='test4', email='example@example.com', anonymised=False)
    content_type_1 = ContentType.objects.get_for_model(FirstSearchModel).pk
    content_type_2 = ContentType.objects.get_for_model(SecondSearchModel).pk
    response = self.client.post(tool_root_url, {'term': 'example@example.com', 'action': gdpr_assist.admin.tool.PersonalDataSearchForm.ACTION_EXPORT, 'obj_pk': ['{}-{}'.format(content_type_1, obj_1.pk), '{}-{}'.format(content_type_2, obj_3.pk), '{}-{}'.format(content_type_2, obj_4.pk)]}, follow=True)
    obj_1.refresh_from_db()
    obj_2.refresh_from_db()
    obj_3.refresh_from_db()
    obj_4.refresh_from_db()
    self.assertFalse(obj_1.anonymised)
    self.assertFalse(obj_2.anonymised)
    self.assertFalse(obj_3.anonymised)
    self.assertFalse(obj_4.anonymised)
    zip_data = BytesIO()
    zip_data.write(response.content)
    zip_file = zipfile.ZipFile(zip_data)
    self.assertEqual(sorted(zip_file.namelist()), ['gdpr_assist_tests_app-FirstSearchModel.csv', 'second_search.csv'])
    if six.PY2:
        mode = 'rU'
    else:
        mode = 'r'
    with zip_file.open('gdpr_assist_tests_app-FirstSearchModel.csv', mode) as f:
        reader = csv.DictReader(TextIOWrapper(f))
        self.assertEqual(reader.fieldnames, ['email'])
        rows = list(reader)
        self.assertEqual(len(rows), 1)
        self.assertEqual(rows[0]['email'], 'example@example.com')
    with zip_file.open('second_search.csv', mode) as f:
        reader = csv.DictReader(TextIOWrapper(f))
        self.assertEqual(sorted(reader.fieldnames), ['chars', 'email'])
        rows = list(reader)
        self.assertEqual(len(rows), 2)
        self.assertEqual(rows[0]['chars'], 'test3')
        self.assertEqual(rows[0]['email'], 'example@example.com')
        self.assertEqual(rows[1]['chars'], 'test4')
        self.assertEqual(rows[1]['email'], 'example@example.com')