Skip to content

Commit

Permalink
Add test.
Browse files Browse the repository at this point in the history
  • Loading branch information
santa committed Feb 11, 2016
1 parent 6431151 commit c0d8087
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 1 deletion.
1 change: 1 addition & 0 deletions requirements/dev.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
-r base.txt
sphinx
mysql-python
psycopg==2.6.1
23 changes: 22 additions & 1 deletion tests/core/tests/resources_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@
from copy import deepcopy
from datetime import date
from decimal import Decimal
from unittest import skip
from unittest import skip, skipUnless

from django.conf import settings
from django.contrib.auth.models import User
from django.db import IntegrityError
from django.db.models import Count
from django.db.models.fields import FieldDoesNotExist
from django.test import TestCase, TransactionTestCase, skipUnlessDBFeature
Expand Down Expand Up @@ -668,3 +670,22 @@ def test_create(self):
BookResource = resources.modelresource_factory(Book)
self.assertIn('id', BookResource.fields)
self.assertEqual(BookResource._meta.model, Book)


@skipUnless(
'postgresql' in settings.DATABASES['default']['ENGINE'],
'Run only against Postgres')
class PostgresTests(TransactionTestCase):
# Make sure to start the sequences back at 1
reset_sequences = True

def test_create_object_after_importing_dataset_with_id(self):
dataset = tablib.Dataset(headers=['id', 'name'])
dataset.append([1, 'Some book'])
resource = BookResource()
result = resource.import_data(dataset)
self.assertFalse(result.has_errors())
try:
Book.objects.create(name='Some other book')
except IntegrityError:
self.fail('IntegrityError was raised.')
12 changes: 12 additions & 0 deletions tests/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,18 @@
}
}
}
elif os.environ.get('IMPORT_EXPORT_TEST_TYPE') == 'postgres':
IMPORT_EXPORT_USE_TRANSACTIONS = True
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql',
'NAME': 'import_export',
'USER': 'postgres',
'PASSWORD': 'postgres',
'HOST': 'localhost',
'PORT': 5432
}
}
else:
DATABASES = {
'default': {
Expand Down

0 comments on commit c0d8087

Please sign in to comment.