def handle(self, *args, **options):
        print('Starting Figures monthly metrics...')

        if options['no_delay']:
            run_figures_monthly_metrics()
        else:
            run_figures_monthly_metrics.delay()

        print('Done.')
Пример #2
0
def test_run_figures_monthly_metrics_with_faked_subtask(transactional_db, monkeypatch):
    """Verify we visit the site in the subtask

    Faking the subtask for the function under test
    """
    expected_sites = Site.objects.all()
    assert expected_sites
    sites_visited = []

    def fake_populate_monthly_metrics_for_site(celery_task_group):
        for t in celery_task_group.tasks:
            sites_visited.extend(t.args)

    monkeypatch.setattr('celery.group.delay', fake_populate_monthly_metrics_for_site)

    run_figures_monthly_metrics()

    assert set(sites_visited) == set([rec.id for rec in expected_sites])
Пример #3
0
def test_run_figures_monthly_metrics_with_faked_subtask(
        transactional_db, monkeypatch):
    """Verify we visit the site in the subtask

    Faking the subtask for the function under test
    """
    expected_sites = Site.objects.all()
    assert expected_sites.count()
    sites_visited = []

    def fake_populate_monthly_metrics_for_site(site_id):
        sites_visited.append(site_id)

    monkeypatch.setattr(
        'figures.tasks.populate_monthly_metrics_for_site.delay',
        fake_populate_monthly_metrics_for_site)

    run_figures_monthly_metrics()

    assert set(sites_visited) == set([rec.id for rec in expected_sites])
Пример #4
0
def test_run_figures_monthly_metrics_with_unfaked_subtask(transactional_db, monkeypatch):
    """Verify we visit the function our subtasks calls

    Faking the function called by the subtask our function under test calls.
    Basically, we're faking two levels below our function under test instead of
    one level below
    """
    expected_sites = Site.objects.all()
    assert expected_sites.count()
    sites_visited = []

    def fake_fill_last_smm_month(site):
        # assert site == expected_site
        sites_visited.append(site)

    monkeypatch.setattr('figures.tasks.fill_last_smm_month',
                        fake_fill_last_smm_month)

    run_figures_monthly_metrics()

    assert set(sites_visited) == set(expected_sites)