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


Python DataConcept.delete方法代码示例

本文整理汇总了Python中avocado.models.DataConcept.delete方法的典型用法代码示例。如果您正苦于以下问题:Python DataConcept.delete方法的具体用法?Python DataConcept.delete怎么用?Python DataConcept.delete使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在avocado.models.DataConcept的用法示例。


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

示例1: test_get_all_category_sort

# 需要导入模块: from avocado.models import DataConcept [as 别名]
# 或者: from avocado.models.DataConcept import delete [as 别名]
    def test_get_all_category_sort(self):
        # Create some temporary concepts and categories.
        cat1 = DataCategory(name='Category1', order=2.0, published=True)
        cat1.save()

        c1 = DataConcept(name='B', published=True, category=cat1, order=1)
        c1.save()
        field1 = DataConceptField(concept=c1, field=self.name_field, order=1)
        field1.save()

        c2 = DataConcept(name='C', published=True, category=cat1, order=2)
        c2.save()
        field2 = DataConceptField(concept=c2, field=self.name_field, order=1)
        field2.save()

        c3 = DataConcept(name='A', published=True, category=cat1, order=3)
        c3.save()
        field3 = DataConceptField(concept=c3, field=self.name_field, order=1)
        field3.save()

        # Check that category ordering is happening by default.
        response = self.client.get('/api/concepts/',
                                   HTTP_ACCEPT='application/json')
        self.assertEqual(response.status_code, codes.ok)
        self.assertEqual(len(json.loads(response.content)), 5)
        names = [concept.get('name', '') for concept in
                 json.loads(response.content)]
        self.assertEqual(names, ['Title', 'Name', 'B', 'C', 'A'])

        # Reverse the ordering of the categories.
        response = self.client.get('/api/concepts/',
                                   {'order': 'desc'},
                                   HTTP_ACCEPT='application/json')
        self.assertEqual(response.status_code, codes.ok)
        self.assertEqual(len(json.loads(response.content)), 5)
        names = [concept.get('name', '') for concept in
                 json.loads(response.content)]
        self.assertEqual(names, ['B', 'C', 'A', 'Title', 'Name'])

        # Order by concept name in addition to category.
        response = self.client.get('/api/concepts/',
                                   {'sort': 'name'},
                                   HTTP_ACCEPT='application/json')
        self.assertEqual(response.status_code, codes.ok)
        self.assertEqual(len(json.loads(response.content)), 5)
        names = [concept.get('name', '') for concept in
                 json.loads(response.content)]
        self.assertEqual(names, ['Name', 'Title', 'A', 'B', 'C'])

        # Reverse the name and category sorting.
        response = self.client.get('/api/concepts/',
                                   {'sort': 'name', 'order': 'desc'},
                                   HTTP_ACCEPT='application/json')
        self.assertEqual(response.status_code, codes.ok)
        self.assertEqual(len(json.loads(response.content)), 5)
        names = [concept.get('name', '') for concept in
                 json.loads(response.content)]
        self.assertEqual(names, ['C', 'B', 'A', 'Title', 'Name'])

        c1.delete()
        c2.delete()
        c3.delete()
        field1.delete()
        field2.delete()
        field3.delete()
        cat1.delete()
开发者ID:chop-dbhi,项目名称:serrano,代码行数:68,代码来源:concept.py


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