Skip to content

Commit

Permalink
Updated django tests to new 2.2 requirement for additional databases
Browse files Browse the repository at this point in the history
  • Loading branch information
palewire committed Apr 13, 2019
1 parent be68eb0 commit 1105b45
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 15 deletions.
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def run(self):
'USER': 'postgres',
'ENGINE': 'django.db.backends.postgresql_psycopg2'
},
'alternative': {
'other': {
'NAME': 'test_alternative',
'USER': 'postgres',
'ENGINE': 'django.db.backends.postgresql_psycopg2'
Expand Down
4 changes: 0 additions & 4 deletions tests/export.csv

This file was deleted.

21 changes: 11 additions & 10 deletions tests/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@


class BaseTest(TestCase):
databases = ["default", "sqlite", "other", "secondary"]

def setUp(self):
self.data_dir = os.path.join(os.path.dirname(__file__), 'data')
Expand Down Expand Up @@ -691,16 +692,16 @@ def test_from_csv(self, _):
MockObject.objects.from_csv(
self.name_path,
dict(name='NAME', number='NUMBER', dt='DATE'),
using='alternative'
using='other'
)
self.assertEqual(MockObject.objects.count(), 0)
self.assertEqual(MockObject.objects.using('alternative').count(), 3)
self.assertEqual(MockObject.objects.using('alternative').get(name='BEN').number, 1)
self.assertEqual(MockObject.objects.using('other').count(), 3)
self.assertEqual(MockObject.objects.using('other').get(name='BEN').number, 1)
self.assertEqual(
MockObject.objects.using('alternative').get(name='BEN').dt,
MockObject.objects.using('other').get(name='BEN').dt,
date(2012, 1, 1)
)
MockObject.objects.using("alternative").all().delete()
MockObject.objects.using("other").all().delete()

@mock.patch("django.db.connection.validate_no_atomic_block")
def test_to_csv(self, _):
Expand All @@ -719,16 +720,16 @@ def test_to_csv(self, _):

@mock.patch("django.db.connection.validate_no_atomic_block")
def test_to_csv_from_alt_db(self, _):
# Next with the alternative database
# Next with the other database
mapping = dict(name='NAME', number='NUMBER', dt='DATE')
MockObject.objects.from_csv(self.name_path, mapping, using="alternative")
export_path = os.path.join(os.path.dirname(__file__), 'alternative.csv')
MockObject.objects.using('alternative').to_csv(export_path)
MockObject.objects.from_csv(self.name_path, mapping, using="other")
export_path = os.path.join(os.path.dirname(__file__), 'other.csv')
MockObject.objects.using('other').to_csv(export_path)
self.assertTrue(os.path.exists(export_path))
reader = csv.DictReader(open(export_path, 'r'))
self.assertTrue(
['BEN', 'JOE', 'JANE'],
[i['name'] for i in reader]
)
MockObject.objects.using("alternative").all().delete()
MockObject.objects.using("other").all().delete()
os.remove(export_path)

0 comments on commit 1105b45

Please sign in to comment.