Projet

Général

Profil

0002-remove-default-check_status-29965.patch

Emmanuel Cazenave, 11 février 2019 17:15

Télécharger (3 ko)

Voir les différences:

Subject: [PATCH 2/2] remove default check_status (#29965)

Small refactoring that simplifies discrimination beetween
connector that implement a check_status method and the others.
 passerelle/base/models.py | 9 +--------
 passerelle/views.py       | 3 +--
 tests/test_manager.py     | 4 ++--
 3 files changed, 4 insertions(+), 12 deletions(-)
passerelle/base/models.py
396 396
                slug=self.slug,
397 397
                timestamp__lt=timestamp).delete()
398 398

  
399
    def check_status(self):
400
        # should raise an exception if status is not ok
401
        raise NotImplementedError
402
    check_status.not_implemented = True
403

  
404 399
    def availability(self):
405 400
        # "availability" cron job to update service statuses
406 401

  
407 402
        # eventually skip it
408
        if not self.availability_parameters.run_check:
403
        if not hasattr(self, 'check_status') or not self.availability_parameters.run_check:
409 404
            return
410 405

  
411 406
        currently_down = self.down()
......
413 408
            self.check_status()
414 409
            status = 'up'
415 410
            message = ''
416
        except NotImplementedError:
417
            return
418 411
        except Exception as e:
419 412
            status = 'down'
420 413
            message = repr(e)[:500]
passerelle/views.py
141 141

  
142 142
    def get_context_data(self, slug=None, **kwargs):
143 143
        context = super(GenericConnectorView, self).get_context_data(**kwargs)
144
        context['has_check_status'] = not hasattr(
145
            context['object'].check_status, 'not_implemented')
144
        context['has_check_status'] = hasattr(context['object'], 'check_status')
146 145
        return context
147 146

  
148 147
    def get_template_names(self):
tests/test_manager.py
208 208
    resp = app.get(csv.get_absolute_url())
209 209

  
210 210
    assert csv.availability_parameters.run_check
211
    # csv connector has the default check_status which does nothing
211
    # csv connector has no check_status
212 212
    # so availability check is hidden
213 213
    assert 'availability check' not in resp.text
214 214

  
215 215
    def check_status(*args, **kwargs):
216 216
        return True
217 217

  
218
    monkeypatch.setattr(CsvDataSource, 'check_status', check_status)
218
    monkeypatch.setattr(CsvDataSource, 'check_status', check_status, raising=False)
219 219

  
220 220
    resp = app.get(csv.get_absolute_url())
221 221
    assert 'availability check' in resp.text
222
-