def handle(self, *args, **options):
        print('Starting Figures MAU metrics for all Sites...')

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

        print('Done.')
Beispiel #2
0
def test_populate_all_mau_single_site(transactional_db, monkeypatch):
    assert Site.objects.count() == 1
    expected_site = Site.objects.first()

    def mock_populate_mau_metrics_for_site(site_id, force_update=False):
        assert site_id == expected_site.id

    monkeypatch.setattr('figures.tasks.populate_mau_metrics_for_site',
                        mock_populate_mau_metrics_for_site)

    populate_all_mau()
Beispiel #3
0
def test_populate_all_mau_multiple_site(transactional_db, monkeypatch):
    assert Site.objects.count() == 1
    sites = [Site.objects.first()]
    sites += [SiteFactory() for i in range(3)]
    sites_visited = []

    def mock_populate_mau_metrics_for_site(site_id, force_update=False):
        sites_visited.append(site_id)

    monkeypatch.setattr('figures.tasks.populate_mau_metrics_for_site',
                        mock_populate_mau_metrics_for_site)

    populate_all_mau()

    assert set(sites_visited) == set([site.id for site in sites])
    def handle(self, *args, **options):
        '''
        Note the '# pragma: no cover' lines below. This is because we are not
        yet mocking celery for test coverage

        The 'mau' conditional check in this method is a quick hack to run the
        MAU task from this command. What we probably want is a 'figures_cli'
        command with subcommands.
        '''
        print('populating Figures metrics...')

        kwargs = dict(
            date_for=options['date'],
            force_update=options['force_update'],
        )

        if options['mau']:
            if options['no_delay']:
                populate_all_mau()
            else:
                populate_all_mau.delay()  # pragma: no cover
        else:
            experimental = options['experimental']
            options.pop('experimental')

            if experimental:
                if options['no_delay']:
                    experimental_populate_daily_metrics(**kwargs)
                else:
                    experimental_populate_daily_metrics.delay(
                        **kwargs)  # pragma: no cover
            else:
                if options['no_delay']:
                    populate_daily_metrics(**kwargs)
                else:
                    populate_daily_metrics.delay(**kwargs)  # pragma: no cover

        # TODO: improve this message to say 'today' when options['date'] is None
        print(
            'Management command populate_figures_metrics complete. date_for: {}'
            .format(options['date']))
        print('Done.')