Skip to content

Commit

Permalink
Merge pull request #1398 from glogiotatidis/generate-all-bundles-if-d…
Browse files Browse the repository at this point in the history
…ist-changes

[Fix #1394] Re-generate all bundles when DistBundle updates.
  • Loading branch information
glogiotatidis committed Jun 23, 2020
2 parents 052b732 + 3da1395 commit f1bee35
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
5 changes: 4 additions & 1 deletion snippets/base/management/commands/generate_bundles.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,10 @@ def handle(self, *args, **options):
self.stdout.write(
'Generating bundles with Jobs modified on or after {}'.format(options['timestamp'])
)
total_jobs = Job.objects.filter(snippet__modified__gte=options['timestamp'])
total_jobs = Job.objects.filter(
Q(snippet__modified__gte=options['timestamp']) |
Q(distribution__distributionbundle__modified__gte=options['timestamp'])
).distinct()

if not total_jobs:
self.stdout.write('Nothing to do…')
Expand Down
10 changes: 7 additions & 3 deletions snippets/base/tests/test_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from django.conf import settings
from django.core.management import call_command
from django.core.management.base import CommandError
from django.db.models import Q
from django.test.utils import override_settings

from snippets.base import models
Expand Down Expand Up @@ -291,17 +292,20 @@ def setUp(self):

def test_generate_all(self):
with patch('snippets.base.management.commands.generate_bundles.Job') as job_mock:
job_mock.objects.all.return_value = []
job_mock.objects.all.return_value = models.Job.objects.none()
call_command('generate_bundles', stdout=Mock())
job_mock.objects.all.assert_called()
job_mock.objects.filter.assert_not_called()

def test_generate_after_timestamp(self):
with patch('snippets.base.management.commands.generate_bundles.Job') as job_mock:
job_mock.objects.filter.return_value = []
job_mock.objects.filter.return_value = models.Job.objects.none()
call_command('generate_bundles', timestamp='2019-01-01', stdout=Mock())
job_mock.objects.all.assert_not_called()
job_mock.objects.filter.assert_called_with(snippet__modified__gte='2019-01-01')
job_mock.objects.filter.assert_called_with(
Q(snippet__modified__gte='2019-01-01') |
Q(distribution__distributionbundle__modified__gte='2019-01-01')
)

@override_settings(MEDIA_BUNDLES_PREGEN_ROOT='pregen')
def test_generation(self):
Expand Down

0 comments on commit f1bee35

Please sign in to comment.