def test_csv_export_import(self): csv = export_csv_bytes(PublicBody.export_csv(PublicBody.objects.all())) prev_count = PublicBody.objects.all().count() imp = CSVImporter() csv_file = six.BytesIO(csv) imp.import_from_file(csv_file) now_count = PublicBody.objects.all().count() self.assertEqual(now_count, prev_count)
def test_csv_export_import(self): csv = export_csv_bytes(PublicBody.export_csv(PublicBody.objects.all())) prev_count = PublicBody.objects.all().count() imp = CSVImporter() csv_file = BytesIO(csv) imp.import_from_file(csv_file) now_count = PublicBody.objects.all().count() self.assertEqual(now_count, prev_count)
def test_csv_command(self): from django.core.management import call_command csv_file = tempfile.NamedTemporaryFile() csv_file.write(export_csv_bytes(PublicBody.export_csv(PublicBody.objects.all()))) csv_file.flush() call_command('import_csv', csv_file.name) csv_file.close()
def test_csv(self): csv = export_csv_bytes(PublicBody.export_csv(PublicBody.objects.all())) self.assertEqual(PublicBody.objects.all().count() + 1, len(csv.splitlines()))