当前位置: 首页>>代码示例>>Python>>正文


Python tests.ResponseFactory类代码示例

本文整理汇总了Python中fjord.feedback.tests.ResponseFactory的典型用法代码示例。如果您正苦于以下问题:Python ResponseFactory类的具体用法?Python ResponseFactory怎么用?Python ResponseFactory使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了ResponseFactory类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_match

    def test_match(self):
        # Note: This isn't an exhaustive test. Just a rough cursory check.

        # TriggerRule that matches everything matches everything.
        tr = TriggerRuleFactory(
            versions=[],
            locales=[],
            keywords=[],
            products=[],
        )

        resp = ResponseFactory()
        assert tr.match(resp) is True

        tr = TriggerRuleFactory(
            versions=[u'38*'],
            locales=[u'en-US', u'fr'],
            keywords=[u'rc4'],
            url_exists=True
        )
        prod = ProductFactory()
        tr.products.add(prod)
        resp = ResponseFactory(
            version=u'38.0.5',
            locale=u'en-US',
            product=prod.db_name,
            description=u'rc4 is awesome',
            url=u'https://example.com/'
        )
        assert tr.match(resp) is True
        resp.locale = 'es'
        assert tr.match(resp) is False
开发者ID:TroJan,项目名称:fjord,代码行数:32,代码来源:test_models.py

示例2: test_match

    def test_match(self):
        # Note: This isn't an exhaustive test. Just a rough cursory check.

        # TriggerRule that matches everything matches everything.
        tr = TriggerRuleFactory(versions=[], locales=[], keywords=[], products=[])
        trm = tr.get_matcher()

        resp = ResponseFactory()
        assert trm.match(resp) is True

        tr = TriggerRuleFactory(versions=[u"38*"], locales=[u"en-US", u"fr"], keywords=[u"rc4"], url_exists=True)
        prod = ProductFactory()
        tr.products.add(prod)
        trm = tr.get_matcher()

        resp = ResponseFactory(
            version=u"38.0.5",
            locale=u"en-US",
            product=prod.db_name,
            description=u"rc4 is awesome",
            url=u"https://example.com/",
        )
        assert trm.match(resp) is True
        resp.locale = "es"
        assert trm.match(resp) is False
开发者ID:Givemore,项目名称:fjord,代码行数:25,代码来源:test_models.py

示例3: test_spanish_with_dennis_and_existing_translations

    def test_spanish_with_dennis_and_existing_translations(self):
        """Response should pick up existing translation"""
        existing_resp = ResponseFactory(
            locale=u'es',
            product=u'firefox',
            description=u'hola',
            translated_description=u'DUDE!'
        )

        resp = ResponseFactory(
            locale=u'es',
            product=u'firefox',
            description=u'hola',
            translated_description=u''
        )

        # Set the product up for translation *after* creating the response
        # so that it doesn't get auto-translated because Response is set up
        # for auto-translation.
        prod = Product.objects.get(db_name='firefox')
        prod.translation_system = u'dennis'
        prod.save()

        # No jobs should be translated
        eq_(len(resp.generate_translation_jobs()), 0)
        eq_(resp.translated_description, existing_resp.translated_description)
开发者ID:rlr,项目名称:fjord,代码行数:26,代码来源:test_models.py

示例4: test_happy_to_rating

    def test_happy_to_rating(self):
        """Test we don't populate rating from happy"""
        resp = ResponseFactory.build(happy=True, rating=None)
        resp.save()
        eq_(resp.rating, None)

        resp = ResponseFactory.build(happy=False, rating=None)
        resp.save()
        eq_(resp.rating, None)
开发者ID:rlr,项目名称:fjord,代码行数:9,代码来源:test_models.py

示例5: test_live_indexing

    def test_live_indexing(self):
        search = ResponseDocType.docs.search()
        count_pre = search.count()

        s = ResponseFactory(happy=True, description="Test live indexing.")
        self.refresh()
        assert count_pre + 1 == search.count()

        s.delete()
        self.refresh()
        assert count_pre == search.count()
开发者ID:Ritsyy,项目名称:fjord,代码行数:11,代码来源:test_index.py

示例6: test_live_indexing

    def test_live_indexing(self):
        S = ResponseMappingType.search
        count_pre = S().count()

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

        s.delete()
        self.refresh()
        eq_(count_pre, S().count())
开发者ID:rlr,项目名称:fjord,代码行数:11,代码来源:test_index.py

示例7: test_english_no_translation

    def test_english_no_translation(self):
        """English descriptions should get copied over"""
        resp = ResponseFactory(
            locale=u'en-US',
            description=u'hello',
            translated_description=u''
        )

        # No new jobs should be generated
        assert len(resp.generate_translation_jobs()) == 0

        # Re-fetch from the db and make sure the description was copied over
        resp = Response.objects.get(id=resp.id)
        assert resp.description == resp.translated_description
开发者ID:Givemore,项目名称:fjord,代码行数:14,代码来源:test_models.py

示例8: test_english_gb_no_translation

    def test_english_gb_no_translation(self):
        """en-GB descriptions should get copied over"""
        resp = ResponseFactory(
            locale=u'en-GB',
            description=u'hello',
            translated_description=u''
        )

        # No new jobs should be generated
        eq_(len(resp.generate_translation_jobs()), 0)

        # Re-fetch from the db and make sure the description was copied over
        resp = Response.objects.get(id=resp.id)
        eq_(resp.description, resp.translated_description)
开发者ID:rlr,项目名称:fjord,代码行数:14,代码来源:test_models.py

示例9: test_spanish_no_translation

    def test_spanish_no_translation(self):
        """Spanish should not get translated"""
        resp = ResponseFactory(
            locale=u'es',
            product=u'firefox',
            description=u'hola',
            translated_description=u''
        )

        # No jobs should be translated
        eq_(len(resp.generate_translation_jobs()), 0)

        # Nothing should be translated
        eq_(resp.translated_description, u'')
开发者ID:rlr,项目名称:fjord,代码行数:14,代码来源:test_models.py

示例10: timezone_view

def timezone_view(request):
    """Admin view showing times and timezones in data."""
    # Note: This is an admin page that gets used once in a blue moon.
    # As such, I'm taking some liberties (hand-indexing the response,
    # time.sleep, etc) that I would never take if it was used more
    # often or was viewable by users. If these two assumptions ever
    # change, then this should be rewritten.

    from fjord.feedback.models import (
        Response,
        ResponseDocType,
        ResponseDocTypeManager
    )
    from fjord.feedback.tests import ResponseFactory
    from fjord.search.index import get_es, get_index_name

    server_time = datetime.now()

    # Create a new response.
    resp = ResponseFactory()
    resp_time = resp.created

    # Index the response by hand so we know it gets to
    # Elasticsearch. Otherwise it gets done by celery and we don't
    # know how long that'll take.
    doc = ResponseDocType.extract_doc(resp)
    ResponseDocTypeManager.bulk_index(docs=[doc])

    # Fetch the response from the db.
    resp = Response.objects.get(id=resp.id)
    resp2_time = resp.created

    # Refresh and sleep 5 seconds as a hand-wavey way to make sure
    # that Elasticsearch has had time to refresh the index.
    get_es().indices.refresh(get_index_name())
    time.sleep(5)

    s = ResponseDocTypeManager.search().filter('term', id=resp.id).execute()
    es_time = s[0].created

    # Delete the test response which also deletes it in the index.
    resp.delete()

    return render(request, 'admin/timezone_view.html', {
        'server_time': server_time,
        'resp_time': resp_time,
        'resp2_time': resp2_time,
        'es_time': es_time
    })
开发者ID:Givemore,项目名称:fjord,代码行数:49,代码来源:admin.py

示例11: test_index_chunk_task

    def test_index_chunk_task(self):
        responses = ResponseFactory.create_batch(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)

        # Verify there's nothing in the index.
        assert ResponseDocType.docs.search().count() == 0

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

        chunk = (
            to_class_path(ResponseDocType),
            [item.id for item in responses]
        )
        index_chunk_task.delay(get_index_name(), batch_id, rec.id, chunk)

        self.refresh()

        # Verify everything is in the index now.
        assert ResponseDocType.docs.search().count() == 10

        # Verify the record was marked succeeded.
        rec = Record.objects.get(pk=rec.id)
        assert rec.status == Record.STATUS_SUCCESS
开发者ID:TroJan,项目名称:fjord,代码行数:30,代码来源:test_tasks.py

示例12: create_basic_sampledata

def create_basic_sampledata():
    happy_feedback = sentence_generator(HAPPY_FEEDBACK)
    sad_feedback = sentence_generator(SAD_FEEDBACK)

    products = sentence_generator(PRODUCTS)
    platforms = sentence_generator(PLATFORMS)
    locales = sentence_generator(settings.DEV_LANGUAGES)
    urls = sentence_generator(URLS)

    # Create 100 happy responses.
    now = time.time()
    objs = []
    for i in range(100):
        product = products.next()
        now = now - random.randint(500, 2000)
        objs.append(
            ResponseFactory.build(
                happy=True,
                description=happy_feedback.next(),
                product=product[0],
                version=product[1],
                platform=platforms.next(),
                locale=locales.next(),
                created=datetime.datetime.fromtimestamp(now)
            )
        )

    # Create 100 sad responses.
    now = time.time()
    for i in range(100):
        product = products.next()
        now = now - random.randint(500, 2000)
        objs.append(
            ResponseFactory.build(
                happy=False,
                description=sad_feedback.next(),
                product=product[0],
                version=product[1],
                platform=platforms.next(),
                locale=locales.next(),
                url=urls.next(),
                created=datetime.datetime.fromtimestamp(now)
            )
        )

    Response.objects.bulk_create(objs)
开发者ID:ANKIT-KS,项目名称:fjord,代码行数:46,代码来源:sampledata.py

示例13: create_additional_sampledata

def create_additional_sampledata(samplesize="1000"):
    samplesize = int(samplesize)

    print "Generating {0} feedback responses...".format(samplesize)

    happy_feedback = sentence_generator(HAPPY_FEEDBACK)
    sad_feedback = sentence_generator(SAD_FEEDBACK)
    products = sentence_generator(PRODUCT_TUPLES)
    urls = sentence_generator(URLS)
    locales = locale_generator()

    objs = []

    now = time.time()
    for i in range(samplesize):
        now = now - random.randint(500, 2000)

        happy = random.choice([True, False])
        if happy:
            description = happy_feedback.next()
            url = u""
        else:
            description = sad_feedback.next()
            url = urls.next()

        product = products.next()
        if product[0] in ALWAYS_API:
            api = "1"
        elif product[0] in NEVER_API:
            api = None
        else:
            api = random.choice(("1", None))
        objs.append(
            ResponseFactory.build(
                happy=happy,
                description=description,
                product=product[0],
                version=product[1],
                platform=product[2],
                url=url,
                user_agent=product[3],
                locale=locales.next(),
                created=datetime.datetime.fromtimestamp(now),
                api=api,
            )
        )

        # Bulk-save the objects to the db 500 at a time and
        # print something to stdout about it.
        if i % 500 == 0:
            Response.objects.bulk_create(objs)
            objs = []
            print "  {0}...".format(i)

    if objs:
        print "  {0}...".format(samplesize)
        Response.objects.bulk_create(objs)
        objs = []
开发者ID:Givemore,项目名称:fjord,代码行数:58,代码来源:sampledata.py

示例14: create_additional_sampledata

def create_additional_sampledata(samplesize):
    samplesize = int(samplesize)

    print 'Working on generating {0} feedback responses....'.format(
        samplesize)

    happy_feedback = sentence_generator(HAPPY_FEEDBACK)
    sad_feedback = sentence_generator(SAD_FEEDBACK)
    products = sentence_generator(PRODUCTS)
    urls = sentence_generator(URLS)
    user_agents = sentence_generator(USER_AGENTS)
    locales = sentence_generator(settings.DEV_LANGUAGES)

    objs = []

    now = time.time()
    for i in range(samplesize):
        now = now - random.randint(500, 2000)

        happy = random.choice([True, False])
        if happy:
            description = happy_feedback.next()
            url = u''
        else:
            description = sad_feedback.next()
            url = urls.next()

        product = products.next()
        objs.append(
            ResponseFactory.build(
                happy=happy,
                description=description,
                product=product[0],
                version=product[1],
                url=url,
                user_agent=user_agents.next(),
                locale=locales.next(),
                created=datetime.datetime.fromtimestamp(now)
            )
        )

        # Bulk-save the objects to the db 500 at a time and
        # print something to stdout about it.
        if i % 500 == 0:
            Response.objects.bulk_create(objs)
            objs = []
            print '  {0}...'.format(i)

    if objs:
        print '  {0}...'.format(samplesize)
        Response.objects.bulk_create(objs)
        objs = []
开发者ID:ANKIT-KS,项目名称:fjord,代码行数:52,代码来源:sampledata.py

示例15: test_english_with_dennis

    def test_english_with_dennis(self):
        """English descriptions should get copied over"""
        resp = ResponseFactory(
            locale=u'en-US',
            product=u'firefox',
            description=u'hello',
            translated_description=u''
        )

        # Set the product up for translation *after* creating the response
        # so that it doesn't get auto-translated because Response is set up
        # for auto-translation.
        prod = Product.objects.get(db_name='firefox')
        prod.translation_system = u'dennis'
        prod.save()

        # No new jobs should be generated
        eq_(len(resp.generate_translation_jobs()), 0)

        # Re-fetch from the db and make sure the description was copied over
        resp = Response.objects.get(id=resp.id)
        eq_(resp.description, resp.translated_description)
开发者ID:rlr,项目名称:fjord,代码行数:22,代码来源:test_models.py


注:本文中的fjord.feedback.tests.ResponseFactory类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。