Пример #1
0
    def test_index_chunk_task(self):
        simple_items = [simple(save=True) for i in range(10)]

        # With live indexing, that'll create items in the index. Since
        # we want to test index_chunk_test, we need a clean index to
        # start with so we delete and recreate it.
        self.setup_indexes(empty=True)

        self.refresh()

        # Verify there's nothing in the index.
        eq_(len(SimpleIndex.search()), 0)

        # Create the record and the chunk and then run it through
        # celery.
        batch_id = 'ou812'
        rec = record(batch_id=batch_id, save=True)

        chunk = (SimpleIndex, [item.id for item in simple_items])
        index_chunk_task.delay(get_index(), batch_id, rec.id, chunk)

        # Verify everything is in the index now.
        eq_(len(SimpleIndex.search()), 10)

        # Verify the record was marked succeeded.
        rec = Record.objects.get(pk=rec.id)
        eq_(rec.status, Record.STATUS_SUCCESS)
Пример #2
0
    def test_index_chunk_task(self):
        simple_items = [simple(save=True) for i in range(10)]

        # With live indexing, that'll create items in the index. Since
        # we want to test index_chunk_test, we need a clean index to
        # start with so we delete and recreate it.
        self.setup_indexes(empty=True)

        self.refresh()

        # Verify there's nothing in the index.
        eq_(len(SimpleIndex.search()), 0)

        # Create the record and the chunk and then run it through
        # celery.
        batch_id = "ou812"
        rec = record(batch_id=batch_id, save=True)

        chunk = (SimpleIndex, [item.id for item in simple_items])
        index_chunk_task.delay(get_index(), batch_id, rec.id, chunk)

        # Verify everything is in the index now.
        eq_(len(SimpleIndex.search()), 10)

        # Verify the record was marked succeeded.
        rec = Record.objects.get(pk=rec.id)
        eq_(rec.status, Record.STATUS_SUCCESS)
Пример #3
0
    def test_live_indexing(self):
        S = SimpleIndex.search
        count_pre = S().count()

        s = simple(happy=True, description='Test live indexing.', save=True)
        self.refresh()
        eq_(count_pre + 1, S().count())

        s.delete()
        self.refresh()
        eq_(count_pre, S().count())
Пример #4
0
    def setUp(self):
        super(TestDashboardView, self).setUp()
        # Set up some sample data
        # 4 happy, 3 sad.
        # 2 Windows XP, 2 Linux, 1 OS X, 2 Windows 7
        items = [
            (True, 'Windows XP', 'en-US', 'apple', datetime(2012, 1, 1)),
            (True, 'Windows 7', 'es', 'banana', datetime(2012, 1, 2)),
            (True, 'Linux', 'en-US', 'orange', datetime(2012, 1, 3)),
            (True, 'Linux', 'en-US', 'apple', datetime(2012, 1, 4)),
            (False, 'Windows XP', 'en-US', 'banana', datetime(2012, 1, 5)),
            (False, 'Windows 7', 'en-US', 'orange', datetime(2012, 1, 6)),
            (False, 'Linux', 'es', 'apple', datetime(2012, 1, 7)),
        ]
        for happy, platform, locale, description, created in items:
            # We don't need to keep this around, just need to create it.
            simple(happy=happy, platform=platform, locale=locale,
                   description=description, created=created, save=True)

        self.refresh()
Пример #5
0
    def setUp(self):
        super(TestDashboardView, self).setUp()
        # Set up some sample data
        # 4 happy, 3 sad.
        # 2 Windows XP, 2 Linux, 1 OS X, 2 Windows 7
        items = [
            (True, 'Windows XP', 'en-US'),
            (True, 'Windows 7', 'es'),
            (True, 'Linux', 'en-US'),
            (True, 'Linux', 'en-US'),
            (False, 'Windows XP', 'en-US'),
            (False, 'Windows 7', 'en-US'),
            (False, 'Linux', 'es'),
        ]
        for happy, platform, locale in items:
            # We don't need to keep this around, just need to create it.
            simple(happy=happy, platform=platform, locale=locale, save=True)

        # TODO: Remove this when live indexing works.
        self.setup_indexes()
        self.refresh()
Пример #6
0
    def setUp(self):
        super(TestDashboardView, self).setUp()
        # Set up some sample data
        # 4 happy, 3 sad.
        # 2 Windows XP, 2 Linux, 1 OS X, 2 Windows 7
        now = datetime.now()
        # The dashboard by default shows the last week of data, so these need
        # to be relative to today. The alternative is that every test gives an
        # explicit date range, and that is annoying and verbose.
        items = [
            (True, "Windows XP", "en-US", "apple", now - timedelta(days=6)),
            (True, "Windows 7", "es", "banana", now - timedelta(days=5)),
            (True, "Linux", "en-US", "orange", now - timedelta(days=4)),
            (True, "Linux", "en-US", "apple", now - timedelta(days=3)),
            (False, "Windows XP", "en-US", "banana", now - timedelta(days=2)),
            (False, "Windows 7", "en-US", "orange", now - timedelta(days=1)),
            (False, "Linux", "es", "apple", now - timedelta(days=0)),
        ]
        for happy, platform, locale, description, created in items:
            # We don't need to keep this around, just need to create it.
            simple(happy=happy, platform=platform, locale=locale, description=description, created=created, save=True)

        self.refresh()
Пример #7
0
def create_simple(happy, description, url=u'', ua=FIREFOX_LINUX_17,
                  locale=u'en-US'):
    parsed = browsers.parse_ua(ua)
    data = {
        'happy': happy,
        'url': url,
        'description': description,

        'user_agent': ua,
        'browser': parsed.browser,
        'browser_version': parsed.browser_version,
        'platform': parsed.platform,
        'locale': locale,
    }
    obj = simple(**data)
    obj.save()
    return obj
Пример #8
0
def create_simple(happy,
                  description,
                  url=u'',
                  ua=FIREFOX_LINUX_17,
                  locale=u'en-US'):
    parsed = browsers.parse_ua(ua)
    data = {
        'happy': happy,
        'url': url,
        'description': description,
        'user_agent': ua,
        'browser': parsed.browser,
        'browser_version': parsed.browser_version,
        'platform': parsed.platform,
        'locale': locale,
    }
    obj = simple(**data)
    obj.save()
    return obj