Пример #1
0
 def test_is_available_filter_before_start_date(self):
     """
     If it is before a task's start date, the task should not be
     available.
     """
     tasks = Task.objects.filter(Task.is_available_filter(now=aware_datetime(2013, 12, 1)))
     ok_(self.task_start_jan not in tasks)
Пример #2
0
 def test_is_available_filter_after_end_date(self):
     """
     If it is after a task's end date, the task should not be
     available.
     """
     tasks = Task.objects.filter(Task.is_available_filter(now=aware_datetime(2014, 2, 1)))
     ok_(self.task_end_jan not in tasks)
Пример #3
0
 def test_invalidate_tasks_not_equals_criterion(self):
     """
     The invalidate_tasks routine should invalidate tasks which match the
     invalidation criteria.
     This tests a not equals criterion.
     """
     bug_to_become_invalid, bug_to_stay_valid = BugzillaBugFactory.create_batch(2)
     batch = TaskImportBatchFactory.create()
     criterion = TaskInvalidationCriterionFactory.create(
         field_name='name',
         relation=TaskInvalidationCriterion.NOT_EQUAL,
         field_value='value')
     criterion.batches.add(batch)
     criterion.save()
     task1, task2 = TaskFactory.create_batch(2,
                                             batch=batch,
                                             imported_item=bug_to_become_invalid,
                                             is_invalid=False)
     task2.imported_item = bug_to_stay_valid
     task2.save()
     with patch('oneanddone.tasks.models.BugzillaUtils.request_bug') as request_bug:
         request_bug.side_effect = lambda x: {
             bug_to_become_invalid.bugzilla_id: {'name': 'value'},
             bug_to_stay_valid.bugzilla_id: {'name': 'not value'}}[x]
         eq_(Task.invalidate_tasks(), 1)
     eq_(Task.objects.get(pk=task1.pk).is_invalid, False)
     eq_(Task.objects.get(pk=task2.pk).is_invalid, True)
Пример #4
0
 def test_is_available_filter_after_start_date(self):
     """
     If it is after a task's start date, the task should be
     available.
     """
     tasks = Task.objects.filter(Task.is_available_filter(now=aware_datetime(2014, 2, 1)))
     ok_(self.task_start_jan in tasks)
Пример #5
0
 def test_is_available_filter_in_range(self):
     """
     If the current date is within a task's date range, the task
     should be available.
     """
     tasks = Task.objects.filter(Task.is_available_filter(now=aware_datetime(2014, 1, 5)))
     ok_(self.task_range_jan_feb in tasks)
 def test_invalidate_tasks_not_equals_criterion(self):
     """
     The invalidate_tasks routine should invalidate tasks which match the
     invalidation criteria.
     This tests a not equals criterion.
     """
     bug_to_become_invalid, bug_to_stay_valid = BugzillaBugFactory.create_batch(
         2)
     batch = TaskImportBatchFactory.create()
     criterion = TaskInvalidationCriterionFactory.create(
         field_name='name',
         relation=TaskInvalidationCriterion.NOT_EQUAL,
         field_value='value')
     criterion.batches.add(batch)
     criterion.save()
     task1, task2 = TaskFactory.create_batch(
         2,
         batch=batch,
         imported_item=bug_to_become_invalid,
         is_invalid=False)
     task2.imported_item = bug_to_stay_valid
     task2.save()
     with patch('oneanddone.tasks.models.BugzillaUtils.request_bug'
                ) as request_bug:
         request_bug.side_effect = lambda x: {
             bug_to_become_invalid.bugzilla_id: {
                 'name': 'value'
             },
             bug_to_stay_valid.bugzilla_id: {
                 'name': 'not value'
             }
         }[x]
         eq_(Task.invalidate_tasks(), 1)
     eq_(Task.objects.get(pk=task1.pk).is_invalid, False)
     eq_(Task.objects.get(pk=task2.pk).is_invalid, True)
Пример #7
0
 def test_is_available_filter_after_start_date(self):
     """
     If it is after a task's start date, the task should be
     available.
     """
     tasks = Task.objects.filter(Task.is_available_filter(now=aware_datetime(2014, 2, 1)))
     ok_(self.task_start_jan in tasks)
Пример #8
0
 def test_is_available_filter_after_end_date(self):
     """
     If it is after a task's end date, the task should not be
     available.
     """
     tasks = Task.objects.filter(Task.is_available_filter(now=aware_datetime(2014, 2, 1)))
     ok_(self.task_end_jan not in tasks)
Пример #9
0
 def test_is_available_filter_before_start_date(self):
     """
     If it is before a task's start date, the task should not be
     available.
     """
     tasks = Task.objects.filter(Task.is_available_filter(now=aware_datetime(2013, 12, 1)))
     ok_(self.task_start_jan not in tasks)
Пример #10
0
 def test_is_available_filter_invalid(self):
     """
     If a task is marked as invalid, it should not be available.
     """
     tasks = Task.objects.filter(Task.is_available_filter(now=aware_datetime(2014, 1, 2)))
     ok_(self.task_no_draft in tasks)
     ok_(self.task_invalid not in tasks)
Пример #11
0
 def test_is_available_filter_in_range(self):
     """
     If the current date is within a task's date range, the task
     should be available.
     """
     tasks = Task.objects.filter(Task.is_available_filter(now=aware_datetime(2014, 1, 5)))
     ok_(self.task_range_jan_feb in tasks)
Пример #12
0
 def test_is_available_filter_invalid(self):
     """
     If a task is marked as invalid, it should not be available.
     """
     tasks = Task.objects.filter(Task.is_available_filter(now=aware_datetime(2014, 1, 2)))
     ok_(self.task_no_draft in tasks)
     ok_(self.task_invalid not in tasks)
Пример #13
0
 def test_is_available_filter_before_end_date(self):
     """
     If it is before a task's end date, the task should be available.
     """
     tasks = Task.objects.filter(
         Task.is_available_filter(now=aware_datetime(2013, 12, 1)))
     ok_(self.task_end_jan in tasks)
Пример #14
0
 def handle(self, *args, **options):
     invalidated = Task.invalidate_tasks()
     self.stdout.write('%s: %s tasks were invalidated via bug data\n' %
                       (datetime.now().isoformat(), invalidated))
     closed = TaskAttempt.close_stale_onetime_attempts()
     self.stdout.write('%s: %s stale one-time attempts were closed\n' %
                       (datetime.now().isoformat(), closed))
     closed = TaskAttempt.close_expired_task_attempts()
     self.stdout.write('%s: %s attempts for expired tasks were closed\n' %
                       (datetime.now().isoformat(), closed))
Пример #15
0
 def test_is_available_filter_default_now(self):
     """
     If no timezone is given, is_available_filter should use
     timezone.now to determine the current datetime.
     """
     with patch('oneanddone.tasks.models.timezone.now') as now:
         now.return_value = aware_datetime(2014, 1, 5)
         tasks = Task.objects.filter(Task.is_available_filter())
         expected = [self.task_no_draft, self.task_start_jan, self.task_range_jan_feb]
         eq_(set(tasks), set(expected))
Пример #16
0
    def __init__(self, *args, **kwargs):
        super(AvailableTasksFilterSet, self).__init__(*args, **kwargs)

        # Limit the area filter to TaskAreas that have available tasks.
        available_areas = TaskArea.objects.filter(Task.is_available_filter(prefix='task__')).distinct()
        ancestor_querysets = [area.get_ancestors(include_self=True) for area in available_areas]
        self.filters['area'] = TreeFilter(
            name='area',
            queryset=reduce(operator.or_, ancestor_querysets).distinct(),
            empty_label=u'All Areas'
        )
Пример #17
0
 def test_is_available_filter_default_now(self):
     """
     If no timezone is given, is_available_filter should use
     timezone.now to determine the current datetime.
     """
     with patch('oneanddone.tasks.models.timezone.now') as now:
         now.return_value = aware_datetime(2014, 1, 5)
         tasks = Task.objects.filter(Task.is_available_filter())
         expected = [
             self.task_no_draft, self.task_start_jan,
             self.task_range_jan_feb
         ]
         eq_(set(tasks), set(expected))
Пример #18
0
 def test_is_available_filter_default_now(self):
     """
     If no timezone is given, is_available_filter should use
     timezone.now to determine the current datetime.
     This also tests the repeatable aspect of the filter by
     ensuring that tasks with attempts that are started or
     finished are not included, but those with no attempts
     or abandoned attempts are included.
     """
     with patch('oneanddone.tasks.models.timezone.now') as now:
         now.return_value = aware_datetime(2014, 1, 5)
         tasks = Task.objects.filter(Task.is_available_filter())
         expected = [self.task_not_repeatable_no_attempts,
                     self.task_not_repeatable_abandoned_attempt,
                     self.task_no_draft, self.task_start_jan,
                     self.task_range_jan_feb]
         eq_(set(tasks), set(expected))
Пример #19
0
 def test_is_available_filter_default_now(self):
     """
     If no timezone is given, is_available_filter should use
     timezone.now to determine the current datetime.
     This also tests the repeatable aspect of the filter by
     ensuring that tasks with attempts that are started or
     finished are not included, but those with no attempts
     or abandoned attempts are included.
     """
     with patch('oneanddone.tasks.models.timezone.now') as now:
         now.return_value = aware_datetime(2014, 1, 5)
         tasks = Task.objects.filter(Task.is_available_filter())
         expected = [self.task_not_repeatable_no_attempts,
                     self.task_not_repeatable_abandoned_attempt,
                     self.task_no_draft, self.task_start_jan,
                     self.task_range_jan_feb]
         eq_(set(tasks), set(expected))
Пример #20
0
 def get_queryset(self):
     queryset = super(TaskMustBePublishedMixin, self).get_queryset()
     return queryset.filter(
         Task.is_available_filter(allow_expired=self.allow_expired_tasks))
Пример #21
0
 def test_is_available_filter_before_end_date(self):
     """
     If it is before a task's end date, the task should be available.
     """
     tasks = Task.objects.filter(Task.is_available_filter(now=aware_datetime(2013, 12, 1)))
     ok_(self.task_end_jan in tasks)
Пример #22
0
 def get_queryset(self):
     queryset = super(TaskMustBeAvailableMixin, self).get_queryset()
     return queryset.filter(Task.is_available_filter(allow_expired=self.allow_expired_tasks))
Пример #23
0
class TaskForm(forms.ModelForm):
    keywords = (forms.CharField(
        help_text=_lazy(u'Please use commas to separate your keywords.'),
        required=False,
        widget=forms.TextInput(attrs={'class': 'medium-field'})))
    owner = forms.ModelChoiceField(queryset=User.objects.filter(
        is_staff=True).order_by('profile__name').exclude(profile__name=None))
    next_task = forms.ModelChoiceField(queryset=Task.objects.filter(
        Task.is_available_filter()).order_by('name'),
                                       required=False)

    def __init__(self, *args, **kwargs):
        if kwargs['instance']:
            initial = kwargs.get('initial', {})
            initial['keywords'] = kwargs['instance'].keywords_list
            kwargs['initial'] = initial
        super(TaskForm, self).__init__(*args, **kwargs)

    def _process_keywords(self, creator):
        form_keywords = self.cleaned_data['keywords'].split(',')
        # When cloning a task we need to process/add the keywords even
        # they weren't changed in the form.
        if ('keywords' in self.changed_data
                or self.instance.keyword_set.count() != len(form_keywords)):
            kw = [k.strip() for k in form_keywords]
            self.instance.replace_keywords(kw, creator)

    def clean(self):
        cleaned_data = super(TaskForm, self).clean()
        start_date = cleaned_data.get('start_date')
        end_date = cleaned_data.get('end_date')
        if start_date and end_date:
            if start_date >= end_date:
                self.add_error(
                    'start_date',
                    forms.ValidationError(
                        _("'End date' must be after "
                          "'Start date'")))
        if cleaned_data.get('must_be_verified'):
            if not cleaned_data.get('verification_instructions'):
                self.add_error(
                    'verification_instructions',
                    forms.ValidationError(
                        _("If the task is a Verified task "
                          "then you must provide some "
                          "verification instructions")))
        return cleaned_data

    def save(self, creator, *args, **kwargs):
        self.instance.creator = creator
        super(TaskForm, self).save(*args, **kwargs)
        if kwargs.get('commit', True):
            self._process_keywords(creator)
        return self.instance

    class Media:
        css = {'all': ('css/admin_ace.css', )}

    class Meta:
        model = Task
        fields = ('name', 'short_description', 'execution_time', 'difficulty',
                  'priority', 'repeatable', 'team', 'project', 'type',
                  'start_date', 'end_date', 'why_this_matters',
                  'prerequisites', 'instructions', 'is_draft', 'is_invalid',
                  'owner', 'next_task', 'must_be_verified',
                  'verification_instructions')
        widgets = {
            'name':
            forms.TextInput(attrs={
                'size': 100,
                'class': 'fill-width'
            }),
            'short_description':
            forms.TextInput(attrs={
                'size': 100,
                'class': 'fill-width'
            }),
            'instructions':
            AceWidget(mode='markdown',
                      theme='textmate',
                      width='800px',
                      height='300px',
                      wordwrap=True,
                      attrs={'class': 'fill-width'}),
            'start_date':
            CalendarInput,
            'end_date':
            CalendarInput,
            'why_this_matters':
            forms.Textarea(attrs={
                'rows': 2,
                'class': 'fill-width'
            }),
            'prerequisites':
            forms.Textarea(attrs={
                'rows': 4,
                'class': 'fill-width'
            }),
            'verification_instructions':
            forms.Textarea(attrs={
                'rows': 4,
                'class': 'fill-width'
            }),
        }