django-dbdiff 0.9.4__tar.gz → 0.9.6__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (47) hide show
  1. django-dbdiff-0.9.6/PKG-INFO +142 -0
  2. {django-dbdiff-0.9.4 → django-dbdiff-0.9.6}/README.rst +11 -3
  3. {django-dbdiff-0.9.4 → django-dbdiff-0.9.6}/dbdiff/fixture.py +13 -2
  4. {django-dbdiff-0.9.4 → django-dbdiff-0.9.6}/dbdiff/tests/decimal_test/migrations/0001_initial.py +0 -3
  5. {django-dbdiff-0.9.4 → django-dbdiff-0.9.6}/dbdiff/tests/decimal_test/migrations/0002_auto_20160102_0914.py +0 -3
  6. django-dbdiff-0.9.6/dbdiff/tests/project/settings_mysql.py +21 -0
  7. django-dbdiff-0.9.6/dbdiff/tests/project/settings_postgresql.py +16 -0
  8. {django-dbdiff-0.9.4 → django-dbdiff-0.9.6}/dbdiff/tests/test_compare.py +8 -19
  9. {django-dbdiff-0.9.4 → django-dbdiff-0.9.6}/dbdiff/utils.py +4 -5
  10. django-dbdiff-0.9.6/django_dbdiff.egg-info/PKG-INFO +142 -0
  11. {django-dbdiff-0.9.4 → django-dbdiff-0.9.6}/django_dbdiff.egg-info/entry_points.txt +0 -1
  12. {django-dbdiff-0.9.4 → django-dbdiff-0.9.6}/django_dbdiff.egg-info/requires.txt +0 -1
  13. {django-dbdiff-0.9.4 → django-dbdiff-0.9.6}/setup.py +13 -4
  14. django-dbdiff-0.9.4/PKG-INFO +0 -125
  15. django-dbdiff-0.9.4/dbdiff/tests/project/settings_mysql.py +0 -9
  16. django-dbdiff-0.9.4/dbdiff/tests/project/settings_postgresql.py +0 -9
  17. django-dbdiff-0.9.4/django_dbdiff.egg-info/PKG-INFO +0 -125
  18. {django-dbdiff-0.9.4 → django-dbdiff-0.9.6}/dbdiff/__init__.py +0 -0
  19. {django-dbdiff-0.9.4 → django-dbdiff-0.9.6}/dbdiff/apps.py +0 -0
  20. {django-dbdiff-0.9.4 → django-dbdiff-0.9.6}/dbdiff/exceptions.py +0 -0
  21. {django-dbdiff-0.9.4 → django-dbdiff-0.9.6}/dbdiff/plugin.py +0 -0
  22. {django-dbdiff-0.9.4 → django-dbdiff-0.9.6}/dbdiff/sequence.py +0 -0
  23. {django-dbdiff-0.9.4 → django-dbdiff-0.9.6}/dbdiff/serializers/__init__.py +0 -0
  24. {django-dbdiff-0.9.4 → django-dbdiff-0.9.6}/dbdiff/serializers/base.py +0 -0
  25. {django-dbdiff-0.9.4 → django-dbdiff-0.9.6}/dbdiff/serializers/json.py +0 -0
  26. {django-dbdiff-0.9.4 → django-dbdiff-0.9.6}/dbdiff/test.py +0 -0
  27. {django-dbdiff-0.9.4 → django-dbdiff-0.9.6}/dbdiff/tests/__init__.py +0 -0
  28. {django-dbdiff-0.9.4 → django-dbdiff-0.9.6}/dbdiff/tests/decimal_test/__init__.py +0 -0
  29. {django-dbdiff-0.9.4 → django-dbdiff-0.9.6}/dbdiff/tests/decimal_test/migrations/__init__.py +0 -0
  30. {django-dbdiff-0.9.4 → django-dbdiff-0.9.6}/dbdiff/tests/decimal_test/models.py +0 -0
  31. {django-dbdiff-0.9.4 → django-dbdiff-0.9.6}/dbdiff/tests/inheritance/__init__.py +0 -0
  32. {django-dbdiff-0.9.4 → django-dbdiff-0.9.6}/dbdiff/tests/inheritance/models.py +0 -0
  33. {django-dbdiff-0.9.4 → django-dbdiff-0.9.6}/dbdiff/tests/nonintpk/__init__.py +0 -0
  34. {django-dbdiff-0.9.4 → django-dbdiff-0.9.6}/dbdiff/tests/nonintpk/models.py +0 -0
  35. {django-dbdiff-0.9.4 → django-dbdiff-0.9.6}/dbdiff/tests/project/__init__.py +0 -0
  36. {django-dbdiff-0.9.4 → django-dbdiff-0.9.6}/dbdiff/tests/project/settings.py +0 -0
  37. {django-dbdiff-0.9.4 → django-dbdiff-0.9.6}/dbdiff/tests/project/settings_sqlite.py +0 -0
  38. {django-dbdiff-0.9.4 → django-dbdiff-0.9.6}/dbdiff/tests/project/urls.py +0 -0
  39. {django-dbdiff-0.9.4 → django-dbdiff-0.9.6}/dbdiff/tests/test_decimal.py +0 -0
  40. {django-dbdiff-0.9.4 → django-dbdiff-0.9.6}/dbdiff/tests/test_fixture.py +0 -0
  41. {django-dbdiff-0.9.4 → django-dbdiff-0.9.6}/dbdiff/tests/test_mixin.py +0 -0
  42. {django-dbdiff-0.9.4 → django-dbdiff-0.9.6}/dbdiff/tests/test_plugin.py +0 -0
  43. {django-dbdiff-0.9.4 → django-dbdiff-0.9.6}/dbdiff/tests/test_utils.py +0 -0
  44. {django-dbdiff-0.9.4 → django-dbdiff-0.9.6}/django_dbdiff.egg-info/SOURCES.txt +0 -0
  45. {django-dbdiff-0.9.4 → django-dbdiff-0.9.6}/django_dbdiff.egg-info/dependency_links.txt +0 -0
  46. {django-dbdiff-0.9.4 → django-dbdiff-0.9.6}/django_dbdiff.egg-info/top_level.txt +0 -0
  47. {django-dbdiff-0.9.4 → django-dbdiff-0.9.6}/setup.cfg +0 -0
@@ -0,0 +1,142 @@
1
+ Metadata-Version: 2.1
2
+ Name: django-dbdiff
3
+ Version: 0.9.6
4
+ Summary: Database data diffing against fixtures for testing
5
+ Home-page: https://github.com/yourlabs/django-dbdiff
6
+ Author: James Pic
7
+ Author-email: jamespic@gmail.com
8
+ License: MIT
9
+ Keywords: django test database fixture diff
10
+ Classifier: Development Status :: 4 - Beta
11
+ Classifier: Environment :: Web Environment
12
+ Classifier: Intended Audience :: Developers
13
+ Classifier: License :: OSI Approved :: MIT License
14
+ Classifier: Operating System :: OS Independent
15
+ Classifier: Framework :: Django
16
+ Classifier: Framework :: Django :: 3.2
17
+ Classifier: Framework :: Django :: 4.0
18
+ Classifier: Framework :: Django :: 4.1
19
+ Classifier: Framework :: Django :: 4.2
20
+ Classifier: Framework :: Django :: 5.0
21
+ Classifier: Programming Language :: Python
22
+ Classifier: Programming Language :: Python :: 3
23
+ Classifier: Programming Language :: Python :: 3.8
24
+ Classifier: Programming Language :: Python :: 3.9
25
+ Classifier: Programming Language :: Python :: 3.10
26
+ Classifier: Programming Language :: Python :: 3.11
27
+ Classifier: Programming Language :: Python :: 3.12
28
+ Classifier: Topic :: Internet :: WWW/HTTP
29
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
30
+ Requires-Dist: ijson
31
+ Requires-Dist: json_delta
32
+
33
+ .. image:: https://travis-ci.org/yourlabs/django-dbdiff.svg
34
+ :target: https://travis-ci.org/yourlabs/django-dbdiff
35
+ .. image:: https://codecov.io/github/yourlabs/django-dbdiff/coverage.svg?branch=master
36
+ :target: https://codecov.io/github/yourlabs/django-dbdiff?branch=master
37
+ .. image:: https://badge.fury.io/py/django-dbdiff.png
38
+ :target: http://badge.fury.io/py/django-dbdiff
39
+
40
+ django-dbdiff
41
+ ~~~~~~~~~~~~~
42
+
43
+ I'm pretty lazy when it comes to writing tests for existing code, however, I'm
44
+ even lazier when it comes to repetitive manual testing action.
45
+
46
+ This package aims at de-duplicating the data import tests from
47
+ django-representatives and django-representatives-votes which is re-used in
48
+ django-cities-light.
49
+
50
+ Database state assertion
51
+ ========================
52
+
53
+ A nice way to test a data import script is to create a source data fixture with
54
+ a subset of data, ie. with only 10 cities instead of 28K or only 3 european
55
+ parliament representatives instead of 3600, feed the import function with that
56
+ and then compare the database state with a django fixture. This looks like what
57
+ I was used to do:
58
+
59
+ - use such a command to create a small data extract
60
+ `shuf -n3 cities15000.txt > cities_light/tests/cities_test_fixture.txt`,
61
+ - use it against the import script on a clean database,
62
+ - verify the database manually, and run
63
+ `django-admin dumpdata --indent=4 cities_light > cities_light/tests/cities_test_expected.txt`
64
+ - then, make a test case that calls the import script against the fixture,
65
+ - write and maintain some funny (fuzzy ?) repetitive test code to ensure that
66
+ the database is in the expected state.
67
+
68
+ When a bug is fixed, just add the case to the fixture and repeat the process to
69
+ create new expected data dumps, use coverage to ensure no case is missed.
70
+
71
+ With django-dbdiff, I just need to maintain to initial data extract, and test
72
+ it with ``Fixture('appname/path/to/fixture',
73
+ models=[YourModelToTest]).assertNoDiff()`` in a
74
+ ``django.test.TransactionTestCase`` which has ``reset_sequences=True``:
75
+
76
+ - if the fixture in question doesn't exist, it'll be automatically created on
77
+ with dumpdata for the concerned models on the first run, raising
78
+ "FixtureCreated" exception to fail the test and inform of the path of the
79
+ created fixture, so that it doesn't mislead the user in thinking the test
80
+ passed with an existing fixture,
81
+ - if the fixture exists, it'll run dumpdata on the models concerned and GNU
82
+ diff it against the fixture, if there's any output it'll be raised in the
83
+ "DiffFound" exception, failing the test and printing the diff.
84
+
85
+ Usage
86
+ =====
87
+
88
+ Example:
89
+
90
+ .. code-block:: python
91
+
92
+ from django import TransactionTestCase
93
+ from dbdiff.fixture import Fixture
94
+
95
+
96
+ class YourImportTest(test.TransactionTestCase):
97
+ reset_sequences = True
98
+
99
+ def test_your_import(self):
100
+ your_import()
101
+
102
+ Fixture('yourapp/tests/yourtest.json',
103
+ models=[YourModel]).assertNoDiff()
104
+
105
+ The first time, it will raise a ``FixtureCreated`` exception, and the test will
106
+ fail. This is to inform the user that the test didn't really run. On the next
107
+ run though, it will pass.
108
+
109
+ If any difference is found between the database and the test fixture, then
110
+ ``diff()`` will return the diff as outputed by GNU diff.
111
+
112
+ If you need to ignore fields globally, set the class-level variable exclude as such:
113
+
114
+ .. code-block:: python
115
+
116
+ Fixture.exclude = {'mrsrequest.mrsrequest': ['token']}
117
+
118
+ Instead of deleting the fixtures manually before running the tests to
119
+ regenerate them, just run your tests with FIXTURE_REWRITE=1 environment
120
+ variable. This will overwrite the fixtures and make the tests look like it
121
+ passed.
122
+
123
+ See tests and docstrings for crunchy details.
124
+
125
+ Requirements
126
+ ============
127
+
128
+ MySQL, SQLite and PostgreSQL, Python 3.8 to 3.12 are supported along with
129
+ Django 3.2 to 5.0 - it's always better to support django's master so that we
130
+ can **upgrade easily when it is released**, which is one of the selling points
131
+ for having 100% coverage.
132
+
133
+ Install
134
+ =======
135
+
136
+ Install ``django-dbdiff`` with pip and add ``dbdiff`` to ``INSTALLED_APPS``.
137
+
138
+ Django model observer
139
+ =====================
140
+
141
+ It is interresting to note that a related, perhaps sort-of similar app exists:
142
+ https://github.com/Griffosx/djmo
@@ -53,7 +53,9 @@ models=[YourModelToTest]).assertNoDiff()`` in a
53
53
  Usage
54
54
  =====
55
55
 
56
- Example::
56
+ Example:
57
+
58
+ .. code-block:: python
57
59
 
58
60
  from django import TransactionTestCase
59
61
  from dbdiff.fixture import Fixture
@@ -75,6 +77,12 @@ run though, it will pass.
75
77
  If any difference is found between the database and the test fixture, then
76
78
  ``diff()`` will return the diff as outputed by GNU diff.
77
79
 
80
+ If you need to ignore fields globally, set the class-level variable exclude as such:
81
+
82
+ .. code-block:: python
83
+
84
+ Fixture.exclude = {'mrsrequest.mrsrequest': ['token']}
85
+
78
86
  Instead of deleting the fixtures manually before running the tests to
79
87
  regenerate them, just run your tests with FIXTURE_REWRITE=1 environment
80
88
  variable. This will overwrite the fixtures and make the tests look like it
@@ -85,8 +93,8 @@ See tests and docstrings for crunchy details.
85
93
  Requirements
86
94
  ============
87
95
 
88
- MySQL, SQLite and PostgreSQL, Python 2.7 and 3.4 are supported along with
89
- Django 1.7 to 1.10 - it's always better to support django's master so that we
96
+ MySQL, SQLite and PostgreSQL, Python 3.8 to 3.12 are supported along with
97
+ Django 3.2 to 5.0 - it's always better to support django's master so that we
90
98
  can **upgrade easily when it is released**, which is one of the selling points
91
99
  for having 100% coverage.
92
100
 
@@ -1,5 +1,6 @@
1
1
  """Public fixture API."""
2
2
 
3
+ import copy
3
4
  import json
4
5
  import os
5
6
  import tempfile
@@ -36,8 +37,15 @@ class Fixture(object):
36
37
  .. py:attribute:: database
37
38
 
38
39
  Database name to use, 'default' by default.
40
+
41
+ .. py:attribute:: exclude
42
+
43
+ Class attribute, dict of model fields to ignore in the form of:
44
+ {'app.model': ['fieldN']}
39
45
  """
40
46
 
47
+ exclude = dict()
48
+
41
49
  def __init__(self, relative_path, models=None, database=None):
42
50
  """
43
51
  Instanciate a FixtureDiff on a database.
@@ -92,6 +100,9 @@ class Fixture(object):
92
100
  """
93
101
  fh, dump_path = tempfile.mkstemp('_dbdiff')
94
102
 
103
+ exclude_final = copy.copy(self.exclude)
104
+ exclude_final.update(exclude or {})
105
+
95
106
  with os.fdopen(fh, 'w') as f:
96
107
  self.dump(f)
97
108
 
@@ -99,8 +110,8 @@ class Fixture(object):
99
110
  expected, result = json.load(e), json.load(r)
100
111
 
101
112
  unexpected, missing, different = diff(
102
- get_tree(expected, exclude),
103
- get_tree(result, exclude),
113
+ get_tree(expected, exclude_final),
114
+ get_tree(result, exclude_final),
104
115
  )
105
116
 
106
117
  if not unexpected and not missing and not diff:
@@ -1,6 +1,3 @@
1
- # -*- coding: utf-8 -*-
2
- from __future__ import unicode_literals
3
-
4
1
  from django.db import models, migrations
5
2
 
6
3
 
@@ -1,6 +1,3 @@
1
- # -*- coding: utf-8 -*-
2
- from __future__ import unicode_literals
3
-
4
1
  from django.db import models, migrations
5
2
 
6
3
 
@@ -0,0 +1,21 @@
1
+ from .settings import * # noqa
2
+
3
+ import os
4
+
5
+ DATABASES = {
6
+ 'default': {
7
+ 'ENGINE': 'django.db.backends.mysql',
8
+ 'HOST': os.environ.get('DB_HOST', ''),
9
+ 'NAME': os.environ.get('DB_NAME', 'dbdiff_test'),
10
+ 'USER': os.environ.get('DB_USER', 'root'),
11
+ 'PASSWORD': os.environ.get('DB_PASSWORD', ''),
12
+ 'PORT': os.environ.get('DB_PORT', ''),
13
+ 'OPTIONS': {
14
+ 'charset': 'utf8mb4',
15
+ },
16
+ 'TEST':{
17
+ 'CHARSET': 'utf8mb4',
18
+ 'COLLATION': 'utf8mb4_unicode_ci',
19
+ }
20
+ }
21
+ }
@@ -0,0 +1,16 @@
1
+ from .settings import * # noqa
2
+
3
+ import os
4
+
5
+ DATABASES = {
6
+ 'default': {
7
+ 'ENGINE': 'django.db.backends.postgresql_psycopg2',
8
+ 'HOST': os.environ.get('DB_HOST', ''),
9
+ 'NAME': os.environ.get('DB_NAME', 'dbdiff_test'),
10
+ 'USER': os.environ.get('DB_USER', 'postgres'),
11
+ 'PASSWORD': os.environ.get('DB_PASSWORD', ''),
12
+ 'PORT': os.environ.get('DB_PORT', '5432'),
13
+ 'OPTIONS': {},
14
+
15
+ }
16
+ }
@@ -1,15 +1,11 @@
1
1
  """Public API tests."""
2
2
 
3
- from __future__ import unicode_literals
4
-
5
3
  import os
6
4
  import tempfile
7
5
 
8
6
  from django import test
9
7
  from django.contrib.auth.models import Group
10
8
 
11
- import six
12
-
13
9
  from ..exceptions import DiffFound, FixtureCreated
14
10
  from ..fixture import Fixture
15
11
 
@@ -57,8 +53,8 @@ class SmokeTest(test.TransactionTestCase):
57
53
  1 instance(s) of auth.group have not expected fields
58
54
  #1:
59
55
  name:
60
- - u'testgroup'
61
- + u'BOOM'
56
+ - 'testgroup'
57
+ + 'BOOM'
62
58
  '''
63
59
 
64
60
  with self.assertRaises(DiffFound) as result:
@@ -73,12 +69,12 @@ class SmokeTest(test.TransactionTestCase):
73
69
  expected = '''
74
70
  1 unexpected instance(s) of auth.group found in the dump:
75
71
  #2:
76
- {u'name': u'unexpected', u'permissions': []}
72
+ {'name': 'unexpected', 'permissions': []}
77
73
  1 instance(s) of auth.group have not expected fields
78
74
  #1:
79
75
  name:
80
- - u'testgroup'
81
- + u'BOOM'
76
+ - 'testgroup'
77
+ + 'BOOM'
82
78
  '''
83
79
 
84
80
  with self.assertRaises(DiffFound) as result:
@@ -90,10 +86,10 @@ class SmokeTest(test.TransactionTestCase):
90
86
  expected = '''
91
87
  1 unexpected instance(s) of auth.group found in the dump:
92
88
  #2:
93
- {u'name': u'unexpected', u'permissions': []}
89
+ {'name': 'unexpected', 'permissions': []}
94
90
  1 expected instance(s) of auth.group missing from dump:
95
91
  #1:
96
- {u'name': u'testgroup', u'permissions': []}
92
+ {'name': 'testgroup', 'permissions': []}
97
93
  '''
98
94
 
99
95
  with self.assertRaises(DiffFound) as result:
@@ -101,13 +97,6 @@ class SmokeTest(test.TransactionTestCase):
101
97
  self.assert_message_is(expected, result)
102
98
 
103
99
  def assert_message_is(self, expected, result):
104
- if six.PY3:
105
- expected = expected.replace("u'", "'")
106
-
107
- msg = (
108
- result.exception.message
109
- if six.PY2 else result.exception.args[0]
110
- )
111
-
100
+ msg = result.exception.args[0]
112
101
  out = '\n'.join(msg.split('\n')[1:])
113
102
  assert out.strip() == expected.strip()
@@ -1,13 +1,11 @@
1
1
  """Utils for dbdiff."""
2
2
 
3
- import imp
4
3
  import os
5
4
 
6
5
  from django.apps import apps
7
6
  from django.db import connections
8
7
 
9
- import six
10
-
8
+ from importlib.util import find_spec
11
9
 
12
10
  def get_tree(dump, exclude=None):
13
11
  """Return a tree of model -> pk -> fields."""
@@ -86,7 +84,8 @@ def get_absolute_path(path):
86
84
  if path.startswith('.'):
87
85
  module_path = '.'
88
86
  else:
89
- module_path = imp.find_module(path.split('/')[0])[1]
87
+ module_path = find_spec(path.split('/')[0]).submodule_search_locations[0]
88
+
90
89
  return os.path.abspath(os.path.join(
91
90
  module_path,
92
91
  *path.split('/')[1:]
@@ -96,7 +95,7 @@ def get_absolute_path(path):
96
95
  def get_model_names(model_classes):
97
96
  """Return model names for model classes."""
98
97
  return [
99
- m if isinstance(m, six.string_types)
98
+ m if isinstance(m, str)
100
99
  else '%s.%s' % (m._meta.app_label, m._meta.model_name)
101
100
  for m in model_classes
102
101
  ]
@@ -0,0 +1,142 @@
1
+ Metadata-Version: 2.1
2
+ Name: django-dbdiff
3
+ Version: 0.9.6
4
+ Summary: Database data diffing against fixtures for testing
5
+ Home-page: https://github.com/yourlabs/django-dbdiff
6
+ Author: James Pic
7
+ Author-email: jamespic@gmail.com
8
+ License: MIT
9
+ Keywords: django test database fixture diff
10
+ Classifier: Development Status :: 4 - Beta
11
+ Classifier: Environment :: Web Environment
12
+ Classifier: Intended Audience :: Developers
13
+ Classifier: License :: OSI Approved :: MIT License
14
+ Classifier: Operating System :: OS Independent
15
+ Classifier: Framework :: Django
16
+ Classifier: Framework :: Django :: 3.2
17
+ Classifier: Framework :: Django :: 4.0
18
+ Classifier: Framework :: Django :: 4.1
19
+ Classifier: Framework :: Django :: 4.2
20
+ Classifier: Framework :: Django :: 5.0
21
+ Classifier: Programming Language :: Python
22
+ Classifier: Programming Language :: Python :: 3
23
+ Classifier: Programming Language :: Python :: 3.8
24
+ Classifier: Programming Language :: Python :: 3.9
25
+ Classifier: Programming Language :: Python :: 3.10
26
+ Classifier: Programming Language :: Python :: 3.11
27
+ Classifier: Programming Language :: Python :: 3.12
28
+ Classifier: Topic :: Internet :: WWW/HTTP
29
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
30
+ Requires-Dist: ijson
31
+ Requires-Dist: json_delta
32
+
33
+ .. image:: https://travis-ci.org/yourlabs/django-dbdiff.svg
34
+ :target: https://travis-ci.org/yourlabs/django-dbdiff
35
+ .. image:: https://codecov.io/github/yourlabs/django-dbdiff/coverage.svg?branch=master
36
+ :target: https://codecov.io/github/yourlabs/django-dbdiff?branch=master
37
+ .. image:: https://badge.fury.io/py/django-dbdiff.png
38
+ :target: http://badge.fury.io/py/django-dbdiff
39
+
40
+ django-dbdiff
41
+ ~~~~~~~~~~~~~
42
+
43
+ I'm pretty lazy when it comes to writing tests for existing code, however, I'm
44
+ even lazier when it comes to repetitive manual testing action.
45
+
46
+ This package aims at de-duplicating the data import tests from
47
+ django-representatives and django-representatives-votes which is re-used in
48
+ django-cities-light.
49
+
50
+ Database state assertion
51
+ ========================
52
+
53
+ A nice way to test a data import script is to create a source data fixture with
54
+ a subset of data, ie. with only 10 cities instead of 28K or only 3 european
55
+ parliament representatives instead of 3600, feed the import function with that
56
+ and then compare the database state with a django fixture. This looks like what
57
+ I was used to do:
58
+
59
+ - use such a command to create a small data extract
60
+ `shuf -n3 cities15000.txt > cities_light/tests/cities_test_fixture.txt`,
61
+ - use it against the import script on a clean database,
62
+ - verify the database manually, and run
63
+ `django-admin dumpdata --indent=4 cities_light > cities_light/tests/cities_test_expected.txt`
64
+ - then, make a test case that calls the import script against the fixture,
65
+ - write and maintain some funny (fuzzy ?) repetitive test code to ensure that
66
+ the database is in the expected state.
67
+
68
+ When a bug is fixed, just add the case to the fixture and repeat the process to
69
+ create new expected data dumps, use coverage to ensure no case is missed.
70
+
71
+ With django-dbdiff, I just need to maintain to initial data extract, and test
72
+ it with ``Fixture('appname/path/to/fixture',
73
+ models=[YourModelToTest]).assertNoDiff()`` in a
74
+ ``django.test.TransactionTestCase`` which has ``reset_sequences=True``:
75
+
76
+ - if the fixture in question doesn't exist, it'll be automatically created on
77
+ with dumpdata for the concerned models on the first run, raising
78
+ "FixtureCreated" exception to fail the test and inform of the path of the
79
+ created fixture, so that it doesn't mislead the user in thinking the test
80
+ passed with an existing fixture,
81
+ - if the fixture exists, it'll run dumpdata on the models concerned and GNU
82
+ diff it against the fixture, if there's any output it'll be raised in the
83
+ "DiffFound" exception, failing the test and printing the diff.
84
+
85
+ Usage
86
+ =====
87
+
88
+ Example:
89
+
90
+ .. code-block:: python
91
+
92
+ from django import TransactionTestCase
93
+ from dbdiff.fixture import Fixture
94
+
95
+
96
+ class YourImportTest(test.TransactionTestCase):
97
+ reset_sequences = True
98
+
99
+ def test_your_import(self):
100
+ your_import()
101
+
102
+ Fixture('yourapp/tests/yourtest.json',
103
+ models=[YourModel]).assertNoDiff()
104
+
105
+ The first time, it will raise a ``FixtureCreated`` exception, and the test will
106
+ fail. This is to inform the user that the test didn't really run. On the next
107
+ run though, it will pass.
108
+
109
+ If any difference is found between the database and the test fixture, then
110
+ ``diff()`` will return the diff as outputed by GNU diff.
111
+
112
+ If you need to ignore fields globally, set the class-level variable exclude as such:
113
+
114
+ .. code-block:: python
115
+
116
+ Fixture.exclude = {'mrsrequest.mrsrequest': ['token']}
117
+
118
+ Instead of deleting the fixtures manually before running the tests to
119
+ regenerate them, just run your tests with FIXTURE_REWRITE=1 environment
120
+ variable. This will overwrite the fixtures and make the tests look like it
121
+ passed.
122
+
123
+ See tests and docstrings for crunchy details.
124
+
125
+ Requirements
126
+ ============
127
+
128
+ MySQL, SQLite and PostgreSQL, Python 3.8 to 3.12 are supported along with
129
+ Django 3.2 to 5.0 - it's always better to support django's master so that we
130
+ can **upgrade easily when it is released**, which is one of the selling points
131
+ for having 100% coverage.
132
+
133
+ Install
134
+ =======
135
+
136
+ Install ``django-dbdiff`` with pip and add ``dbdiff`` to ``INSTALLED_APPS``.
137
+
138
+ Django model observer
139
+ =====================
140
+
141
+ It is interresting to note that a related, perhaps sort-of similar app exists:
142
+ https://github.com/Griffosx/djmo
@@ -1,3 +1,2 @@
1
1
  [pytest11]
2
2
  dbdiff = dbdiff.plugin
3
-
@@ -12,7 +12,7 @@ def read(fname):
12
12
 
13
13
  setup(
14
14
  name='django-dbdiff',
15
- version='0.9.4',
15
+ version='0.9.6',
16
16
  description='Database data diffing against fixtures for testing',
17
17
  author='James Pic',
18
18
  author_email='jamespic@gmail.com',
@@ -22,18 +22,27 @@ setup(
22
22
  long_description=read('README.rst'),
23
23
  license='MIT',
24
24
  keywords='django test database fixture diff',
25
- install_requires=['ijson', 'json_delta', 'six'],
25
+ install_requires=['ijson', 'json_delta'],
26
26
  entry_points={'pytest11': ['dbdiff = dbdiff.plugin']},
27
27
  classifiers=[
28
28
  'Development Status :: 4 - Beta',
29
29
  'Environment :: Web Environment',
30
- 'Framework :: Django',
31
30
  'Intended Audience :: Developers',
32
31
  'License :: OSI Approved :: MIT License',
33
32
  'Operating System :: OS Independent',
33
+ 'Framework :: Django',
34
+ 'Framework :: Django :: 3.2',
35
+ 'Framework :: Django :: 4.0',
36
+ 'Framework :: Django :: 4.1',
37
+ 'Framework :: Django :: 4.2',
38
+ 'Framework :: Django :: 5.0',
34
39
  'Programming Language :: Python',
35
- 'Programming Language :: Python :: 2',
36
40
  'Programming Language :: Python :: 3',
41
+ 'Programming Language :: Python :: 3.8',
42
+ 'Programming Language :: Python :: 3.9',
43
+ 'Programming Language :: Python :: 3.10',
44
+ 'Programming Language :: Python :: 3.11',
45
+ 'Programming Language :: Python :: 3.12',
37
46
  'Topic :: Internet :: WWW/HTTP',
38
47
  'Topic :: Software Development :: Libraries :: Python Modules',
39
48
  ],
@@ -1,125 +0,0 @@
1
- Metadata-Version: 2.1
2
- Name: django-dbdiff
3
- Version: 0.9.4
4
- Summary: Database data diffing against fixtures for testing
5
- Home-page: https://github.com/yourlabs/django-dbdiff
6
- Author: James Pic
7
- Author-email: jamespic@gmail.com
8
- License: MIT
9
- Description: .. image:: https://travis-ci.org/yourlabs/django-dbdiff.svg
10
- :target: https://travis-ci.org/yourlabs/django-dbdiff
11
- .. image:: https://codecov.io/github/yourlabs/django-dbdiff/coverage.svg?branch=master
12
- :target: https://codecov.io/github/yourlabs/django-dbdiff?branch=master
13
- .. image:: https://badge.fury.io/py/django-dbdiff.png
14
- :target: http://badge.fury.io/py/django-dbdiff
15
-
16
- django-dbdiff
17
- ~~~~~~~~~~~~~
18
-
19
- I'm pretty lazy when it comes to writing tests for existing code, however, I'm
20
- even lazier when it comes to repetitive manual testing action.
21
-
22
- This package aims at de-duplicating the data import tests from
23
- django-representatives and django-representatives-votes which is re-used in
24
- django-cities-light.
25
-
26
- Database state assertion
27
- ========================
28
-
29
- A nice way to test a data import script is to create a source data fixture with
30
- a subset of data, ie. with only 10 cities instead of 28K or only 3 european
31
- parliament representatives instead of 3600, feed the import function with that
32
- and then compare the database state with a django fixture. This looks like what
33
- I was used to do:
34
-
35
- - use such a command to create a small data extract
36
- `shuf -n3 cities15000.txt > cities_light/tests/cities_test_fixture.txt`,
37
- - use it against the import script on a clean database,
38
- - verify the database manually, and run
39
- `django-admin dumpdata --indent=4 cities_light > cities_light/tests/cities_test_expected.txt`
40
- - then, make a test case that calls the import script against the fixture,
41
- - write and maintain some funny (fuzzy ?) repetitive test code to ensure that
42
- the database is in the expected state.
43
-
44
- When a bug is fixed, just add the case to the fixture and repeat the process to
45
- create new expected data dumps, use coverage to ensure no case is missed.
46
-
47
- With django-dbdiff, I just need to maintain to initial data extract, and test
48
- it with ``Fixture('appname/path/to/fixture',
49
- models=[YourModelToTest]).assertNoDiff()`` in a
50
- ``django.test.TransactionTestCase`` which has ``reset_sequences=True``:
51
-
52
- - if the fixture in question doesn't exist, it'll be automatically created on
53
- with dumpdata for the concerned models on the first run, raising
54
- "FixtureCreated" exception to fail the test and inform of the path of the
55
- created fixture, so that it doesn't mislead the user in thinking the test
56
- passed with an existing fixture,
57
- - if the fixture exists, it'll run dumpdata on the models concerned and GNU
58
- diff it against the fixture, if there's any output it'll be raised in the
59
- "DiffFound" exception, failing the test and printing the diff.
60
-
61
- Usage
62
- =====
63
-
64
- Example::
65
-
66
- from django import TransactionTestCase
67
- from dbdiff.fixture import Fixture
68
-
69
-
70
- class YourImportTest(test.TransactionTestCase):
71
- reset_sequences = True
72
-
73
- def test_your_import(self):
74
- your_import()
75
-
76
- Fixture('yourapp/tests/yourtest.json',
77
- models=[YourModel]).assertNoDiff()
78
-
79
- The first time, it will raise a ``FixtureCreated`` exception, and the test will
80
- fail. This is to inform the user that the test didn't really run. On the next
81
- run though, it will pass.
82
-
83
- If any difference is found between the database and the test fixture, then
84
- ``diff()`` will return the diff as outputed by GNU diff.
85
-
86
- Instead of deleting the fixtures manually before running the tests to
87
- regenerate them, just run your tests with FIXTURE_REWRITE=1 environment
88
- variable. This will overwrite the fixtures and make the tests look like it
89
- passed.
90
-
91
- See tests and docstrings for crunchy details.
92
-
93
- Requirements
94
- ============
95
-
96
- MySQL, SQLite and PostgreSQL, Python 2.7 and 3.4 are supported along with
97
- Django 1.7 to 1.10 - it's always better to support django's master so that we
98
- can **upgrade easily when it is released**, which is one of the selling points
99
- for having 100% coverage.
100
-
101
- Install
102
- =======
103
-
104
- Install ``django-dbdiff`` with pip and add ``dbdiff`` to ``INSTALLED_APPS``.
105
-
106
- Django model observer
107
- =====================
108
-
109
- It is interresting to note that a related, perhaps sort-of similar app exists:
110
- https://github.com/Griffosx/djmo
111
-
112
- Keywords: django test database fixture diff
113
- Platform: UNKNOWN
114
- Classifier: Development Status :: 4 - Beta
115
- Classifier: Environment :: Web Environment
116
- Classifier: Framework :: Django
117
- Classifier: Intended Audience :: Developers
118
- Classifier: License :: OSI Approved :: MIT License
119
- Classifier: Operating System :: OS Independent
120
- Classifier: Programming Language :: Python
121
- Classifier: Programming Language :: Python :: 2
122
- Classifier: Programming Language :: Python :: 3
123
- Classifier: Topic :: Internet :: WWW/HTTP
124
- Classifier: Topic :: Software Development :: Libraries :: Python Modules
125
- Description-Content-Type: text/x-rst
@@ -1,9 +0,0 @@
1
- from .settings import * # noqa
2
-
3
- DATABASES = {
4
- 'default': {
5
- 'ENGINE': 'django.db.backends.mysql',
6
- 'NAME': 'dbdiff_test',
7
- 'USER': 'root',
8
- }
9
- }
@@ -1,9 +0,0 @@
1
- from .settings import * # noqa
2
-
3
- DATABASES = {
4
- 'default': {
5
- 'ENGINE': 'django.db.backends.postgresql_psycopg2',
6
- 'NAME': 'dbdiff_test',
7
- 'USER': 'postgres',
8
- }
9
- }
@@ -1,125 +0,0 @@
1
- Metadata-Version: 2.1
2
- Name: django-dbdiff
3
- Version: 0.9.4
4
- Summary: Database data diffing against fixtures for testing
5
- Home-page: https://github.com/yourlabs/django-dbdiff
6
- Author: James Pic
7
- Author-email: jamespic@gmail.com
8
- License: MIT
9
- Description: .. image:: https://travis-ci.org/yourlabs/django-dbdiff.svg
10
- :target: https://travis-ci.org/yourlabs/django-dbdiff
11
- .. image:: https://codecov.io/github/yourlabs/django-dbdiff/coverage.svg?branch=master
12
- :target: https://codecov.io/github/yourlabs/django-dbdiff?branch=master
13
- .. image:: https://badge.fury.io/py/django-dbdiff.png
14
- :target: http://badge.fury.io/py/django-dbdiff
15
-
16
- django-dbdiff
17
- ~~~~~~~~~~~~~
18
-
19
- I'm pretty lazy when it comes to writing tests for existing code, however, I'm
20
- even lazier when it comes to repetitive manual testing action.
21
-
22
- This package aims at de-duplicating the data import tests from
23
- django-representatives and django-representatives-votes which is re-used in
24
- django-cities-light.
25
-
26
- Database state assertion
27
- ========================
28
-
29
- A nice way to test a data import script is to create a source data fixture with
30
- a subset of data, ie. with only 10 cities instead of 28K or only 3 european
31
- parliament representatives instead of 3600, feed the import function with that
32
- and then compare the database state with a django fixture. This looks like what
33
- I was used to do:
34
-
35
- - use such a command to create a small data extract
36
- `shuf -n3 cities15000.txt > cities_light/tests/cities_test_fixture.txt`,
37
- - use it against the import script on a clean database,
38
- - verify the database manually, and run
39
- `django-admin dumpdata --indent=4 cities_light > cities_light/tests/cities_test_expected.txt`
40
- - then, make a test case that calls the import script against the fixture,
41
- - write and maintain some funny (fuzzy ?) repetitive test code to ensure that
42
- the database is in the expected state.
43
-
44
- When a bug is fixed, just add the case to the fixture and repeat the process to
45
- create new expected data dumps, use coverage to ensure no case is missed.
46
-
47
- With django-dbdiff, I just need to maintain to initial data extract, and test
48
- it with ``Fixture('appname/path/to/fixture',
49
- models=[YourModelToTest]).assertNoDiff()`` in a
50
- ``django.test.TransactionTestCase`` which has ``reset_sequences=True``:
51
-
52
- - if the fixture in question doesn't exist, it'll be automatically created on
53
- with dumpdata for the concerned models on the first run, raising
54
- "FixtureCreated" exception to fail the test and inform of the path of the
55
- created fixture, so that it doesn't mislead the user in thinking the test
56
- passed with an existing fixture,
57
- - if the fixture exists, it'll run dumpdata on the models concerned and GNU
58
- diff it against the fixture, if there's any output it'll be raised in the
59
- "DiffFound" exception, failing the test and printing the diff.
60
-
61
- Usage
62
- =====
63
-
64
- Example::
65
-
66
- from django import TransactionTestCase
67
- from dbdiff.fixture import Fixture
68
-
69
-
70
- class YourImportTest(test.TransactionTestCase):
71
- reset_sequences = True
72
-
73
- def test_your_import(self):
74
- your_import()
75
-
76
- Fixture('yourapp/tests/yourtest.json',
77
- models=[YourModel]).assertNoDiff()
78
-
79
- The first time, it will raise a ``FixtureCreated`` exception, and the test will
80
- fail. This is to inform the user that the test didn't really run. On the next
81
- run though, it will pass.
82
-
83
- If any difference is found between the database and the test fixture, then
84
- ``diff()`` will return the diff as outputed by GNU diff.
85
-
86
- Instead of deleting the fixtures manually before running the tests to
87
- regenerate them, just run your tests with FIXTURE_REWRITE=1 environment
88
- variable. This will overwrite the fixtures and make the tests look like it
89
- passed.
90
-
91
- See tests and docstrings for crunchy details.
92
-
93
- Requirements
94
- ============
95
-
96
- MySQL, SQLite and PostgreSQL, Python 2.7 and 3.4 are supported along with
97
- Django 1.7 to 1.10 - it's always better to support django's master so that we
98
- can **upgrade easily when it is released**, which is one of the selling points
99
- for having 100% coverage.
100
-
101
- Install
102
- =======
103
-
104
- Install ``django-dbdiff`` with pip and add ``dbdiff`` to ``INSTALLED_APPS``.
105
-
106
- Django model observer
107
- =====================
108
-
109
- It is interresting to note that a related, perhaps sort-of similar app exists:
110
- https://github.com/Griffosx/djmo
111
-
112
- Keywords: django test database fixture diff
113
- Platform: UNKNOWN
114
- Classifier: Development Status :: 4 - Beta
115
- Classifier: Environment :: Web Environment
116
- Classifier: Framework :: Django
117
- Classifier: Intended Audience :: Developers
118
- Classifier: License :: OSI Approved :: MIT License
119
- Classifier: Operating System :: OS Independent
120
- Classifier: Programming Language :: Python
121
- Classifier: Programming Language :: Python :: 2
122
- Classifier: Programming Language :: Python :: 3
123
- Classifier: Topic :: Internet :: WWW/HTTP
124
- Classifier: Topic :: Software Development :: Libraries :: Python Modules
125
- Description-Content-Type: text/x-rst
File without changes