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


Python fixtures.KeyFactory类代码示例

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


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

示例1: test_to_dict

    def test_to_dict(self):
        page_id = uuid4()
        review_id = uuid4()
        page = PageFactory.build(uuid=page_id)
        review = ReviewFactory.build(page=page, uuid=review_id)
        key1 = KeyFactory.create(name='some.random.key1')
        review.add_violation(key1, 'b', 100, review.domain)
        key2 = KeyFactory.create(name='some.random.key2')
        review.add_fact(key2, 'b')

        fact_definitions = {'some.random.key2': {}}
        violation_definitions = {'some.random.key1': {}}

        expect(review.to_dict(fact_definitions, violation_definitions)).to_be_like({
            'domain': review.domain.name,
            'uuid': str(review_id),
            'completedAt': None,
            'facts': [
                {'value': 'b', 'key': 'some.random.key2', 'unit': 'value', 'title': 'unknown', 'category': 'unknown'}
            ],
            'violations': [
                {'points': 100, 'key': 'some.random.key1', 'description': 'b', 'title': 'undefined', 'category': 'undefined'}
            ],
            'page': {
                'url': page.url,
                'lastModified': None,
                'expires': None,
                'uuid': str(page_id),
                'score': 0.0
            },
            'createdAt': review.created_date,
            'isComplete': False
        })
开发者ID:pombredanne,项目名称:holmes-api,代码行数:33,代码来源:test_review.py

示例2: test_can_insert_default_violations_values_for_domain

    def test_can_insert_default_violations_values_for_domain(self):
        domain = DomainFactory.create()

        page_title_size = KeyFactory.create(name='page.title.size')
        total_requests_img = KeyFactory.create(name='total.requests.img')

        violation_definitions = {
            'page.title.size': {'key': page_title_size, 'default_value': 100},
            'total.requests.img': {'key': total_requests_img, 'default_value': 5}
        }

        keys = violation_definitions.keys()

        data = DomainsViolationsPrefs.get_domains_violations_prefs_by_domain(self.db, domain.name)
        expect(data).to_length(0)

        DomainsViolationsPrefs.insert_default_violations_values_for_domain(
            self.db,
            domain,
            keys,
            violation_definitions,
            self.cache
        )

        data = DomainsViolationsPrefs.get_domains_violations_prefs_by_domain(self.db, domain.name)

        expect(data).not_to_be_null()
        expect(data).to_length(2)
        expect(data).to_be_like([
            {'value': 100, 'key': 'page.title.size'},
            {'value': 5, 'key': 'total.requests.img'}
        ])
开发者ID:diegosaouda,项目名称:holmes-api,代码行数:32,代码来源:test_domains_violations_prefs.py

示例3: test_can_save_prefs

    def test_can_save_prefs(self):
        user = UserFactory.create(is_superuser=True)

        key1 = KeyFactory.create(name='some.random.1')
        key2 = KeyFactory.create(name='some.random.2')

        UsersViolationsPrefsFactory.create(user=user, key=key1, is_active=True)
        UsersViolationsPrefsFactory.create(user=user, key=key2, is_active=False)

        loaded_prefs = UsersViolationsPrefs.get_prefs(self.db, user)
        expect(loaded_prefs).to_length(2)
        expect(loaded_prefs).to_be_like({
            'some.random.1': True,
            'some.random.2': False
        })

        yield self.authenticated_fetch(
            '/users/violations-prefs/',
            user_email=user.email,
            method='POST',
            body=dumps([
                {'key': 'some.random.1', 'is_active': False},
                {'key': 'some.random.2', 'is_active': True},
            ])
        )

        loaded_prefs = UsersViolationsPrefs.get_prefs(self.db, user)
        expect(loaded_prefs).to_length(2)
        expect(loaded_prefs).to_be_like({
            'some.random.1': False,
            'some.random.2': True
        })
开发者ID:diegosaouda,项目名称:holmes-api,代码行数:32,代码来源:test_users_violations_prefs.py

示例4: test_can_get_prefs

    def test_can_get_prefs(self):
        domain = DomainFactory.create(name='globo.com')

        key1 = KeyFactory.create(name='some.random.1')
        key2 = KeyFactory.create(name='some.random.2')

        DomainsViolationsPrefsFactory.create(domain=domain, key=key1, value=100)
        DomainsViolationsPrefsFactory.create(domain=domain, key=key2, value=2)

        self.server.application.violation_definitions = {
            'some.random.1': {
                'category': 'SEO',
                'default_value': 100,
                'default_value_description': 'My some.random.1',
                'unit': 'number'
            },
            'some.random.2': {
                'category': 'HTTP',
                'default_value': 2,
                'default_value_description': 'My some.random.2',
                'unit': 'number'
            },
        }

        response = yield self.authenticated_fetch(
            '/domains/%s/violations-prefs/' % domain.name
        )

        expect(response.code).to_equal(200)

        prefs = loads(response.body)

        expect(prefs).to_length(2)
        expect(prefs[0]).to_length(6)
        expect(prefs[1]).to_length(6)

        expect(prefs).to_be_like([
            {
                'category': 'SEO',
                'default_value': 100,
                'title': 'My some.random.1',
                'value': 100,
                'key': 'some.random.1',
                'unit': 'number'
            },{
                'category': 'HTTP',
                'default_value': 2,
                'title': 'My some.random.2',
                'value': 2,
                'key': 'some.random.2',
                'unit': 'number'
            }
        ])
开发者ID:diegosaouda,项目名称:holmes-api,代码行数:53,代码来源:test_domains_violations_prefs.py

示例5: test_can_insert_default_violations_values_for_all_domains

    def test_can_insert_default_violations_values_for_all_domains(self):
        DomainsViolationsPrefsFactory.create(
            domain=Domain(name='globo.com'),
            key=Key(name='some.random.fact'),
            value='whatever'
        )

        for x in range(3):
            DomainFactory.create(name='g%d.com' % x)

        domains_violations_prefs = \
            DomainsViolationsPrefs.get_domains_violations_prefs(self.db)

        expect(domains_violations_prefs).to_length(1)

        default_violations_values = {
            'page.title.size': 100,
            'total.requests.img': 5,
        }

        page_title_size = KeyFactory.create(name='page.title.size')
        total_requests_img = KeyFactory.create(name='total.requests.img')

        violation_definitions = {
            'page.title.size': {'key': page_title_size, 'default_value': 100},
            'total.requests.img': {'key': total_requests_img, 'default_value': 5}
        }

        DomainsViolationsPrefs.insert_default_violations_values_for_all_domains(
            self.db,
            default_violations_values,
            violation_definitions,
            self.cache
        )

        domains_violations_prefs = \
            DomainsViolationsPrefs.get_domains_violations_prefs(self.db)

        expect(domains_violations_prefs).to_length(4)

        expect(domains_violations_prefs).to_be_like({
            'globo.com': {
                'some.random.fact': 'whatever',
                'total.requests.img': 5,
                'page.title.size': 100
            },
            'g0.com': {'page.title.size': 100, 'total.requests.img': 5},
            'g1.com': {'page.title.size': 100, 'total.requests.img': 5},
            'g2.com': {'page.title.size': 100, 'total.requests.img': 5},
        })
开发者ID:diegosaouda,项目名称:holmes-api,代码行数:50,代码来源:test_domains_violations_prefs.py

示例6: test_can_get_prefs

    def test_can_get_prefs(self):
        user = UserFactory.create()
        key1 = KeyFactory.create()
        key2 = KeyFactory.create()

        UsersViolationsPrefs.insert_pref(self.db, user, key1, True)
        UsersViolationsPrefs.insert_pref(self.db, user, key2, False)

        data = UsersViolationsPrefs.get_prefs(self.db, user)

        expect(data).to_length(2)

        expect(data).to_be_like(
            {key1.name: True, key2.name: False}
        )
开发者ID:diegosaouda,项目名称:holmes-api,代码行数:15,代码来源:test_users_violations_prefs.py

示例7: test_get_by_name

    def test_get_by_name(self):
        key = KeyFactory.create(name='some.random.key')

        loadded_key = Key.get_by_name(self.db, 'some.random.key')

        expect(key).to_equal(loadded_key)
        expect(loadded_key.name).to_equal('some.random.key')
开发者ID:diegosaouda,项目名称:holmes-api,代码行数:7,代码来源:test_keys.py

示例8: test_can_get_domain_violations_prefs

    def test_can_get_domain_violations_prefs(self):
        domain = DomainFactory.create(name='globo.com')

        self.sync_cache.redis.delete( 'violations-prefs-%s' % domain.name)

        for i in range(3):
            DomainsViolationsPrefsFactory.create(
                domain=domain,
                key=KeyFactory.create(name='some.random.%d' % i),
                value='v%d' % i
            )

        prefs = self.sync_cache.get_domain_violations_prefs('globo.com')
        expect(prefs).to_equal([
            {'value': u'v0', 'key': u'some.random.0'},
            {'value': u'v1', 'key': u'some.random.1'},
            {'value': u'v2', 'key': u'some.random.2'}
        ])

        # should get from cache
        self.sync_cache.db = None

        prefs = self.sync_cache.get_domain_violations_prefs('globo.com')
        expect(prefs).to_equal([
            {'value': u'v0', 'key': u'some.random.0'},
            {'value': u'v1', 'key': u'some.random.1'},
            {'value': u'v2', 'key': u'some.random.2'}
        ])
开发者ID:marcelometal,项目名称:holmes-api,代码行数:28,代码来源:test_cache.py

示例9: test_cant_save_prefs_as_normal_user

    def test_cant_save_prefs_as_normal_user(self):
        self.db.query(User).delete()
        user = UserFactory(email='[email protected]', is_superuser=False)
        domain = DomainFactory.create(name='globo.com')
        key = KeyFactory.create(name='some.random')
        DomainsViolationsPrefsFactory.create(domain=domain, key=key, value=100)

        loaded_prefs = DomainsViolationsPrefs.get_domains_violations_prefs_by_domain(self.db, domain.name)
        expect(loaded_prefs).to_length(1)
        expect(loaded_prefs[0]).to_be_like({
            'value': 100,
            'key': 'some.random'
        })

        try:
            yield self.authenticated_fetch(
                '/domains/%s/violations-prefs/' % domain.name,
                user_email=user.email,
                method='POST',
                body=dumps([
                    {'key': 'some.random', 'value': 10},
                ])
            )
        except HTTPError, e:
            expect(e).not_to_be_null()
            expect(e.code).to_equal(401)
            expect(e.response.reason).to_be_like('Unauthorized')
开发者ID:diegosaouda,项目名称:holmes-api,代码行数:27,代码来源:test_domains_violations_prefs.py

示例10: test_can_save_prefs_as_superuser

    def test_can_save_prefs_as_superuser(self):
        self.db.query(User).delete()
        user = UserFactory(email='[email protected]', is_superuser=True)
        domain = DomainFactory.create(name='globo.com')
        key = KeyFactory.create(name='some.random')
        DomainsViolationsPrefsFactory.create(domain=domain, key=key, value=100)

        loaded_prefs = DomainsViolationsPrefs.get_domains_violations_prefs_by_domain(self.db, domain.name)
        expect(loaded_prefs).to_length(1)
        expect(loaded_prefs[0]).to_be_like({
            'value': 100,
            'key': 'some.random'
        })

        yield self.authenticated_fetch(
            '/domains/%s/violations-prefs/' % domain.name,
            user_email=user.email,
            method='POST',
            body=dumps([
                {'key': 'some.random', 'value': 10},
            ])
        )

        loaded_prefs = DomainsViolationsPrefs.get_domains_violations_prefs_by_domain(self.db, domain.name)
        expect(loaded_prefs).to_length(1)
        expect(loaded_prefs[0]).to_be_like({
            'value': 10,
            'key': 'some.random'
        })
开发者ID:diegosaouda,项目名称:holmes-api,代码行数:29,代码来源:test_domains_violations_prefs.py

示例11: test_can_get_most_common_violations

    def test_can_get_most_common_violations(self):
        self.db.query(Violation).delete()
        self.db.query(Key).delete()

        category = KeysCategoryFactory.create(name="SEO")
        for i in range(3):
            key = KeyFactory.create(name="some.random.fact.%s" % i, category=category)
            for j in range(i):
                ViolationFactory.create(key=key, value="value", points=10 * i + j)

        violation_definitions = {
            "some.random.fact.1": {"title": "SEO", "category": "SEO"},
            "some.random.fact.2": {"title": "SEO", "category": "SEO"},
        }

        violations = Violation.get_most_common_violations(self.db, violation_definitions)

        expect(violations).to_be_like(
            [
                {"count": 1, "key": "some.random.fact.1", "category": "SEO", "title": "SEO"},
                {"count": 2, "key": "some.random.fact.2", "category": "SEO", "title": "SEO"},
            ]
        )

        violations = Violation.get_most_common_violations(self.db, violation_definitions, sample_limit=2)

        expect(violations).to_be_like([{"count": 2, "key": "some.random.fact.2", "category": "SEO", "title": "SEO"}])
开发者ID:pombredanne,项目名称:holmes-api,代码行数:27,代码来源:test_violations.py

示例12: test_can_get_violations

    def test_can_get_violations(self):

        keys = [KeyFactory.create(name='random.fact.%s' % i) for i in range(3)]

        violation_definitions = {
            'random.fact.%s' % i: {
                'title': 'title.%d' % i,
                'category': 'category.%d' % i,
                'key': key
            } for i, key in enumerate(keys)
        }

        def extract_key_name(violation_definition):
            key = violation_definition.pop('key')
            violation_definition['key_name'] = key.name
            return violation_definition

        expected = [extract_key_name(vd) for vd in violation_definitions.values()]

        self.server.application.violation_definitions = violation_definitions

        response = yield self.authenticated_fetch('/violations')

        violations = loads(response.body)

        expect(violations).to_length(3)
        expect(violations).to_be_like(expected)
开发者ID:diegosaouda,项目名称:holmes-api,代码行数:27,代码来源:test_violation.py

示例13: test_can_insert_prefs_without_user

    def test_can_insert_prefs_without_user(self):
        user = None

        prefs = self.db.query(UsersViolationsPrefs).all()
        expect(prefs).to_length(0)

        items = []
        for x in range(3):
            name = 'key-test-%d' % x
            KeyFactory.create(name=name)
            items.append(name)

        UsersViolationsPrefs.insert_prefs(self.db, user, items)

        prefs = self.db.query(UsersViolationsPrefs).all()
        expect(prefs).to_length(0)
开发者ID:diegosaouda,项目名称:holmes-api,代码行数:16,代码来源:test_users_violations_prefs.py

示例14: test_can_create_key

    def test_can_create_key(self):
        key = KeyFactory.create(name='some.random.key')

        loaded_key = self.db.query(Key).get(key.id)

        expect(loaded_key.name).to_equal('some.random.key')
        expect(str(loaded_key)).to_be_like('%s' % key.name)
开发者ID:pombredanne,项目名称:holmes-api,代码行数:7,代码来源:test_keys.py

示例15: test_can_get_last_reviews

    def test_can_get_last_reviews(self):
        page = PageFactory.create()

        date_now = datetime(2013, 11, 12, 13, 25, 27)

        review = ReviewFactory.create(
            page=page,
            is_active=True,
            is_complete=False,
            completed_date=date_now,
            created_date=date_now)

        key1 = KeyFactory.create(name='fact')
        review.add_fact(key1, 'value')
        key2 = KeyFactory.create(name='violation')
        review.add_violation(key2, 'value', 100, page.domain)
        review.is_complete = True
        self.db.flush()

        url = self.get_url('/last-reviews')
        response = yield self.http_client.fetch(url, method='GET')

        expect(response.code).to_equal(200)

        dt = calendar.timegm(date_now.utctimetuple())

        expected = [{
            'domain': review.domain.name,
            'page': page.to_dict(),
            'uuid': str(review.uuid),
            'isComplete': True,
            'facts': [
                {u'key': u'fact', u'unit': u'value', u'value': u'value',
                 u'title': u'unknown', u'category': u'unknown'}
            ],
            'violations': [
                {u'points': 100, u'description': u'value',
                 u'key': u'violation', u'title': u'undefined', u'category': 'undefined'}
            ],
            'createdAt': dt,
            'completedAt': dt,
            'violationCount': 1,
        }]

        expect(loads(response.body)).to_be_like(expected)
开发者ID:pombredanne,项目名称:holmes-api,代码行数:45,代码来源:test_review.py


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