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


Python factories.CategoryFactory类代码示例

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


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

示例1: test_project_create

    def test_project_create(self):
        """Test Auditlog API project create works."""
        CategoryFactory.create()
        user = UserFactory.create()

        data = {'name': 'New Name',
                'short_name': 'new_short_name',
                'description': 'new_description',
                'long_description': 'new_long_description',
                'allow_anonymous_contributors': 'False',
                }
        url = '/api/project?api_key=%s' % (user.api_key)
        self.app.post(url, data=json.dumps(data))
        logs = auditlog_repo.filter_by(project_short_name='new_short_name')

        assert len(logs) == 1, logs
        for log in logs:
            assert log.user_id == user.id, log.user_id
            assert log.user_name == user.name, log.user_name
            assert log.project_short_name == 'new_short_name', log.project_short_name
            assert log.caller == 'api', log.caller
            assert log.action == 'create', log.action
            assert log.attribute == 'project', log.attribute
            assert log.old_value == 'Nothing', log.old_value
            assert log.new_value == 'New project', log.new_value
开发者ID:fiorda,项目名称:pybossa,代码行数:25,代码来源:test_auditlog.py

示例2: test_get_category_by_returns_none_if_no_category

    def test_get_category_by_returns_none_if_no_category(self):
        """Test get_category returns None if no category matches the query"""

        CategoryFactory.create(name='My Project', short_name='mycategory')

        category = self.project_repo.get_by(name='no_name')

        assert category is None, category
开发者ID:anukat2015,项目名称:pybossa,代码行数:8,代码来源:test_project_repository.py

示例3: test_get_used_returns_only_categories_with_projects

    def test_get_used_returns_only_categories_with_projects(self):
        used_category = CategoryFactory.create()
        ProjectFactory.create(category=used_category)
        unused_category = CategoryFactory.create()

        used_categories = cached_categories.get_used()

        assert used_categories[0]["id"] == used_category.id, used_categories
开发者ID:chandra1b,项目名称:pybossa,代码行数:8,代码来源:test_cache_categories.py

示例4: test_application_crud

 def test_application_crud(self):
     c = CategoryFactory()
     r = self.c.get(c.get_absolute_url())
     self.assertFalse("test application" in r.content)
     r = self.c.post(c.get_absolute_url() + "add_application/",
                     {'name': 'test application'})
     self.assertEqual(r.status_code, 302)
     r = self.c.get(c.get_absolute_url())
     self.assertTrue("test application" in r.content)
开发者ID:ccnmtl,项目名称:rolf,代码行数:9,代码来源:test_views.py

示例5: test_filter_categories_by_no_matches

    def test_filter_categories_by_no_matches(self):
        """Test filter_categories_by returns an empty list if no categories
        match the query"""

        CategoryFactory.create(name='My Project', short_name='mycategory')

        retrieved_categories = self.project_repo.filter_categories_by(name='no_name')

        assert isinstance(retrieved_categories, list)
        assert len(retrieved_categories) == 0, retrieved_categories
开发者ID:anukat2015,项目名称:pybossa,代码行数:10,代码来源:test_project_repository.py

示例6: test_filter_categories_by_one_condition

    def test_filter_categories_by_one_condition(self):
        """Test filter_categories_by returns a list of categories that meet
        the filtering condition"""

        CategoryFactory.create_batch(3, description='generic category')
        should_be_missing = CategoryFactory.create(description='other category')

        retrieved_categories = (self.project_repo
            .filter_categories_by(description='generic category'))

        assert len(retrieved_categories) == 3, retrieved_categories
        assert should_be_missing not in retrieved_categories, retrieved_categories
开发者ID:anukat2015,项目名称:pybossa,代码行数:12,代码来源:test_project_repository.py

示例7: test_query_category

    def test_query_category(self):
        """Test API query for category endpoint works"""
        CategoryFactory.create(name="thinking", short_name="thinking")
        # Test for real field
        url = "/api/category"
        res = self.app.get(url + "?short_name=thinking")
        data = json.loads(res.data)
        # Should return one result
        assert len(data) == 1, data
        # Correct result
        assert data[0]["short_name"] == "thinking", data

        # Valid field but wrong value
        res = self.app.get(url + "?short_name=wrongvalue")
        data = json.loads(res.data)
        assert len(data) == 0, data

        # Multiple fields
        res = self.app.get(url + "?short_name=thinking&name=thinking")
        data = json.loads(res.data)
        # One result
        assert len(data) == 1, data
        # Correct result
        assert data[0]["short_name"] == "thinking", data
        assert data[0]["name"] == "thinking", data

        # Limits
        res = self.app.get(url + "?limit=1")
        data = json.loads(res.data)
        for item in data:
            assert item["short_name"] == "thinking", item
        assert len(data) == 1, data

        # Keyset pagination
        CategoryFactory.create(name="computing", short_name="computing")
        res = self.app.get(url)
        data = json.loads(res.data)
        tmp = "?limit=1&last_id=%s" % data[0]["id"]
        res = self.app.get(url + tmp)
        data_new = json.loads(res.data)
        assert len(data_new) == 1, data_new
        assert data_new[0]["id"] == data[1]["id"]

        # Errors
        res = self.app.get(url + "?something")
        err = json.loads(res.data)
        err_msg = "AttributeError exception should be raised"
        res.status_code == 415, err_msg
        assert res.status_code == 415, err_msg
        assert err["action"] == "GET", err_msg
        assert err["status"] == "failed", err_msg
        assert err["exception_cls"] == "AttributeError", err_msg
开发者ID:ronaldlcheung,项目名称:pybossa,代码行数:52,代码来源:test_category_api.py

示例8: test_filter_categories_by_limit_offset

    def test_filter_categories_by_limit_offset(self):
        """Test that filter_categories_by supports limit and offset options"""

        CategoryFactory.create_batch(4)
        all_categories = self.project_repo.filter_categories_by()

        first_two = self.project_repo.filter_categories_by(limit=2)
        last_two = self.project_repo.filter_categories_by(limit=2, offset=2)

        assert len(first_two) == 2, first_two
        assert len(last_two) == 2, last_two
        assert first_two == all_categories[:2]
        assert last_two == all_categories[2:]
开发者ID:anukat2015,项目名称:pybossa,代码行数:13,代码来源:test_project_repository.py

示例9: test_save_category_fails_if_integrity_error

    def test_save_category_fails_if_integrity_error(self):
        """Test save_category raises a DBIntegrityError if the instance to be
       saved lacks a required value"""

        category = CategoryFactory.build(name=None)

        assert_raises(DBIntegrityError, self.project_repo.save_category, category)
开发者ID:anukat2015,项目名称:pybossa,代码行数:7,代码来源:test_project_repository.py

示例10: test_index_based_sorting

 def test_index_based_sorting(self):
     """Tests index based category sorting"""
     parent_1 = CategoryFactory.create(name="parent 1", index=10)
     sub_1 = CategoryFactory.create(name="sub 1", index=13,
         parent=parent_1)
     sub_2 = CategoryFactory.create(name="sub 2", index=12,
         parent=parent_1)
     sub_3 = CategoryFactory.create(name="sub 3", index=11,
         parent=parent_1)
     categories = Category.objects.all()
     indexes = []
     for category in categories:
         indexes.append(category.index)
     self.assertEquals(indexes, sorted(indexes))
     self.assertEquals(categories[0], parent_1)
     self.assertEquals(categories[3], sub_1)
开发者ID:dsandoval,项目名称:lizard-maptree,代码行数:16,代码来源:models.py

示例11: test_get_category_by

    def test_get_category_by(self):
        """Test get_category returns a category with the specified attribute"""

        category = CategoryFactory.create(name='My Cat', short_name='mycat')

        retrieved_category = self.project_repo.get_category_by(name=category.name)

        assert category == retrieved_category, retrieved_category
开发者ID:anukat2015,项目名称:pybossa,代码行数:8,代码来源:test_project_repository.py

示例12: test_get_category_returns_category

    def test_get_category_returns_category(self):
        """Test get_category method returns a category if exists"""

        category = CategoryFactory.create()

        retrieved_category = self.project_repo.get_category(category.id)

        assert category == retrieved_category, retrieved_category
开发者ID:anukat2015,项目名称:pybossa,代码行数:8,代码来源:test_project_repository.py

示例13: test_update_category_fails_if_integrity_error

    def test_update_category_fails_if_integrity_error(self):
        """Test update raises a DBIntegrityError if the instance to be updated
        lacks a required value"""

        category = CategoryFactory.create()
        category.name = None

        assert_raises(DBIntegrityError, self.project_repo.update_category, category)
开发者ID:anukat2015,项目名称:pybossa,代码行数:8,代码来源:test_project_repository.py

示例14: test_save_category

    def test_save_category(self):
        """Test save_category persist the category"""

        category = CategoryFactory.build()
        assert self.project_repo.get(category.id) is None

        self.project_repo.save_category(category)

        assert self.project_repo.get_category(category.id) == category, "Category not saved"
开发者ID:anukat2015,项目名称:pybossa,代码行数:9,代码来源:test_project_repository.py

示例15: test_authenticated_user_can_crud

    def test_authenticated_user_can_crud(self):
        """Test authenticated users cannot crud categories"""
        category = CategoryFactory.build()

        assert_raises(Forbidden, ensure_authorized_to, "create", category)
        assert_not_raises(Exception, ensure_authorized_to, "read", category)
        assert_not_raises(Exception, ensure_authorized_to, "read", Category)
        assert_raises(Forbidden, ensure_authorized_to, "update", category)
        assert_raises(Forbidden, ensure_authorized_to, "delete", category)
开发者ID:chandra1b,项目名称:pybossa,代码行数:9,代码来源:test_category_auth.py


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