from ichnaea.async.config import configure_export
from ichnaea.config import DummyConfig
from ichnaea.data.tasks import (
    update_cell,
    update_wifi,
    schedule_export_reports,
)
from ichnaea.data.tests.test_export import BaseExportTest
from ichnaea.models import (
    ApiKey,
    Cell,
    ScoreKey,
    User,
    WifiShard,
)


class TestUploader(BaseExportTest):

    nickname = b'World Tr\xc3\xa4veler'.decode('utf-8')
    email = b'world_tr\xc3\xa4veler@email.com'.decode('utf-8')

    def setUp(self):
        super(TestUploader, self).setUp()
        config = DummyConfig({
            'export:internal': {
                'url': 'internal://',
                'metadata': 'true',
                'batch': '0',
            },
        })
        self.celery_app.export_queues = configure_export(
            self.redis_client, config)

    def test_stats(self):
        self.session.add(ApiKey(valid_key='e5444-794', log=True))
        self.session.flush()

        self.add_reports(3, email='secretemail@localhost',
                         ip=self.geoip_data['London']['ip'])
        self.add_reports(6, api_key='e5444-794')
        self.add_reports(3, api_key=None)

        schedule_export_reports.delay().get()
        update_cell.delay().get()
        update_wifi.delay().get()