Skip to content

Commit

Permalink
Merge pull request #40 from HBS-HBX/#39_es_update_start_flag_broken
Browse files Browse the repository at this point in the history
closes #39 es update start flag broken
  • Loading branch information
codekiln authored Sep 11, 2018
2 parents 1e4d4ad + bed2a15 commit 8657f71
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 7 deletions.
10 changes: 6 additions & 4 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
Changelog
---------

0.7.6 (2018-09-11)
~~~~~~~~~~~~~~~~~~
* fix `#36 es_update --start flag broken <https://github.com/HBS-HBX/django-elastic-migrations/issues/39>`_

0.7.5 (2018-08-20)
~~~~~~~~~~~~~~~~~~
* fix `#35 open multiprocessing log in context handler
<https://github.com/HBS-HBX/django-elastic-migrations/issues/35>`_
* fix `#35 open multiprocessing log in context handler <https://github.com/HBS-HBX/django-elastic-migrations/issues/35>`_

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

0.7.3 (2018-08-14)
~~~~~~~~~~~~~~~~~~
Expand Down
2 changes: 1 addition & 1 deletion django_elastic_migrations/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from django_elastic_migrations.utils import loading
from django_elastic_migrations.utils.django_elastic_migrations_log import get_logger

__version__ = '0.7.5'
__version__ = '0.7.6'

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

Expand Down
2 changes: 1 addition & 1 deletion django_elastic_migrations/management/commands/es_update.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def add_arguments(self, parser):
"--start",
dest="start_date",
help="The start date for indexing. Can be any dateutil-parsable string;"
" YYYY-MM-DDTHH:MM:SS is recommended to avoid confusion",
"YYYY-MM-DD or YYYY-MM-DDTHH:MM:SS is recommended to avoid confusion",
)

def handle(self, *args, **options):
Expand Down
5 changes: 4 additions & 1 deletion django_elastic_migrations/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -957,7 +957,10 @@ def __init__(self, *args, **kwargs):
actual_val = kwargs.pop(kwarg_name, default_val)
setattr(self, kwarg_name, actual_val)
if actual_val != default_val:
self.self_kwargs[kwarg_name] = actual_val
if kwarg_name == 'start_date':
self.self_kwargs['start_date'] = str(actual_val)
else:
self.self_kwargs[kwarg_name] = actual_val

if NewerModeMixin.MODE_NAME in kwargs:
self.self_kwargs[NewerModeMixin.MODE_NAME] = True
Expand Down
25 changes: 25 additions & 0 deletions tests/test_management_commands.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from __future__ import (absolute_import, division, print_function, unicode_literals)

import logging
from datetime import datetime, timedelta
from unittest import skip

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


def days_ago(d):
return datetime.now() - timedelta(days=d)


# noinspection PyUnresolvedReferences
class CommonDEMTestUtilsMixin(object):

Expand Down Expand Up @@ -227,6 +232,26 @@ def test_newer_flag(self):
actual_num=actual_num_docs
))

def test_start_flag(self):
self.check_basic_setup_and_get_models()

num_docs = MovieSearchIndex.get_num_docs()
self.assertEqual(num_docs, 0)

Movie.objects.all().update(last_modified=days_ago(3))
call_command('es_update', 'movies', '--start={}'.format(days_ago(2).isoformat()))
num_docs = MovieSearchIndex.get_num_docs()
# we had last modified set to three days ago, and we only updated last two days,
# so we should not have any.
self.assertEqual(num_docs, 0)

Movie.objects.all().update(last_modified=days_ago(1))
call_command('es_update', 'movies', '--start={}'.format(days_ago(2).isoformat()))
num_docs = MovieSearchIndex.get_num_docs()
# we had last modified set to one days ago, and we only updated last two days,
# so we should have two
self.assertEqual(num_docs, 2)


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

0 comments on commit 8657f71

Please sign in to comment.