Skip to content

Commit 8657f71

Browse files
authored
Merge pull request #40 from HBS-HBX/#39_es_update_start_flag_broken
closes #39 es update start flag broken
2 parents 1e4d4ad + bed2a15 commit 8657f71

File tree

5 files changed

+37
-7
lines changed

5 files changed

+37
-7
lines changed

CHANGELOG.rst

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
11
Changelog
22
---------
33

4+
0.7.6 (2018-09-11)
5+
~~~~~~~~~~~~~~~~~~
6+
* fix `#36 es_update --start flag broken <https://github.com/HBS-HBX/django-elastic-migrations/issues/39>`_
7+
48
0.7.5 (2018-08-20)
59
~~~~~~~~~~~~~~~~~~
6-
* fix `#35 open multiprocessing log in context handler
7-
<https://github.com/HBS-HBX/django-elastic-migrations/issues/35>`_
10+
* fix `#35 open multiprocessing log in context handler <https://github.com/HBS-HBX/django-elastic-migrations/issues/35>`_
811

912
0.7.4 (2018-08-15)
1013
~~~~~~~~~~~~~~~~~~
11-
* fix `#33 error when nothing to resume using --resume
12-
<https://github.com/HBS-HBX/django-elastic-migrations/issues/33>`_
14+
* fix `#33 error when nothing to resume using --resume <https://github.com/HBS-HBX/django-elastic-migrations/issues/33>`_
1315

1416
0.7.3 (2018-08-14)
1517
~~~~~~~~~~~~~~~~~~

django_elastic_migrations/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
from django_elastic_migrations.utils import loading
1111
from django_elastic_migrations.utils.django_elastic_migrations_log import get_logger
1212

13-
__version__ = '0.7.5'
13+
__version__ = '0.7.6'
1414

1515
default_app_config = 'django_elastic_migrations.apps.DjangoElasticMigrationsConfig' # pylint: disable=invalid-name
1616

django_elastic_migrations/management/commands/es_update.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ def add_arguments(self, parser):
4747
"--start",
4848
dest="start_date",
4949
help="The start date for indexing. Can be any dateutil-parsable string;"
50-
" YYYY-MM-DDTHH:MM:SS is recommended to avoid confusion",
50+
"YYYY-MM-DD or YYYY-MM-DDTHH:MM:SS is recommended to avoid confusion",
5151
)
5252

5353
def handle(self, *args, **options):

django_elastic_migrations/models.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -957,7 +957,10 @@ def __init__(self, *args, **kwargs):
957957
actual_val = kwargs.pop(kwarg_name, default_val)
958958
setattr(self, kwarg_name, actual_val)
959959
if actual_val != default_val:
960-
self.self_kwargs[kwarg_name] = actual_val
960+
if kwarg_name == 'start_date':
961+
self.self_kwargs['start_date'] = str(actual_val)
962+
else:
963+
self.self_kwargs[kwarg_name] = actual_val
961964

962965
if NewerModeMixin.MODE_NAME in kwargs:
963966
self.self_kwargs[NewerModeMixin.MODE_NAME] = True

tests/test_management_commands.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from __future__ import (absolute_import, division, print_function, unicode_literals)
22

33
import logging
4+
from datetime import datetime, timedelta
45
from unittest import skip
56

67
from django.contrib.humanize.templatetags.humanize import ordinal
@@ -17,6 +18,10 @@
1718
log = logging.getLogger(__file__)
1819

1920

21+
def days_ago(d):
22+
return datetime.now() - timedelta(days=d)
23+
24+
2025
# noinspection PyUnresolvedReferences
2126
class CommonDEMTestUtilsMixin(object):
2227

@@ -227,6 +232,26 @@ def test_newer_flag(self):
227232
actual_num=actual_num_docs
228233
))
229234

235+
def test_start_flag(self):
236+
self.check_basic_setup_and_get_models()
237+
238+
num_docs = MovieSearchIndex.get_num_docs()
239+
self.assertEqual(num_docs, 0)
240+
241+
Movie.objects.all().update(last_modified=days_ago(3))
242+
call_command('es_update', 'movies', '--start={}'.format(days_ago(2).isoformat()))
243+
num_docs = MovieSearchIndex.get_num_docs()
244+
# we had last modified set to three days ago, and we only updated last two days,
245+
# so we should not have any.
246+
self.assertEqual(num_docs, 0)
247+
248+
Movie.objects.all().update(last_modified=days_ago(1))
249+
call_command('es_update', 'movies', '--start={}'.format(days_ago(2).isoformat()))
250+
num_docs = MovieSearchIndex.get_num_docs()
251+
# we had last modified set to one days ago, and we only updated last two days,
252+
# so we should have two
253+
self.assertEqual(num_docs, 2)
254+
230255

231256
@skip("Skipped multiprocessing tests until SQLLite can be integrated into test setup")
232257
# @tag('multiprocessing')

0 commit comments

Comments
 (0)