Skip to content

Commit b54159b

Browse files
committed
Tests for exporting from an alternative database
1 parent 9d51112 commit b54159b

File tree

1 file changed

+27
-1
lines changed

1 file changed

+27
-1
lines changed

tests/tests.py

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -420,7 +420,7 @@ def test_hooks(self):
420420

421421
class MultiDbTest(BaseTest):
422422

423-
def test_simple_save(self):
423+
def test_from_csv(self):
424424
MockObject.objects.from_csv(
425425
self.name_path,
426426
dict(name='NAME', number='NUMBER', dt='DATE'),
@@ -433,3 +433,29 @@ def test_simple_save(self):
433433
MockObject.objects.using('alternative').get(name='BEN').dt,
434434
date(2012, 1, 1)
435435
)
436+
437+
def test_to_csv(self):
438+
# First with the default database
439+
mapping = dict(name='NAME', number='NUMBER', dt='DATE')
440+
MockObject.objects.from_csv(self.name_path, mapping)
441+
export_path = os.path.join(os.path.dirname(__file__), 'default.csv')
442+
MockObject.objects.to_csv(export_path)
443+
self.assertTrue(os.path.exists(export_path))
444+
reader = csv.DictReader(open(export_path, 'r'))
445+
self.assertTrue(
446+
['BEN', 'JOE', 'JANE'],
447+
[i['name'] for i in reader]
448+
)
449+
os.remove(export_path)
450+
451+
# Next with the alternative database
452+
MockObject.objects.from_csv(self.name_path, mapping, using="alternative")
453+
export_path = os.path.join(os.path.dirname(__file__), 'alternative.csv')
454+
MockObject.objects.using('alternative').to_csv(export_path)
455+
self.assertTrue(os.path.exists(export_path))
456+
reader = csv.DictReader(open(export_path, 'r'))
457+
self.assertTrue(
458+
['BEN', 'JOE', 'JANE'],
459+
[i['name'] for i in reader]
460+
)
461+
os.remove(export_path)

0 commit comments

Comments
 (0)