• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python models.Anchor类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: setUp

    def setUp(self):
        """
        Create 3 BasicModel instances.
        """
        items = ['foo', 'bar', 'baz']
        anchors = []
        for item in items:
            anchor = Anchor(text=item)
            anchor.save()
            anchors.append(anchor)

        manytomany = ManyToManyModel()
        manytomany.save()
        manytomany.rel.add(*anchors)

        self.data = [{
            'url': 'http://testserver/manytomany/1/',
            'rel': [
                'http://testserver/anchor/1/',
                'http://testserver/anchor/2/',
                'http://testserver/anchor/3/',
            ]
        }]
        self.list_view = ManyToManyList.as_view()
        self.detail_view = ManyToManyDetail.as_view()
开发者ID:limnick,项目名称:django-rest-framework,代码行数:25,代码来源:hyperlinkedserializers.py


示例2: ReadOnlyManyToManyTests

class ReadOnlyManyToManyTests(TestCase):
    def setUp(self):
        class ReadOnlyManyToManySerializer(serializers.ModelSerializer):
            rel = serializers.RelatedField(many=True, read_only=True)

            class Meta:
                model = ReadOnlyManyToManyModel

        self.serializer_class = ReadOnlyManyToManySerializer

        # An anchor instance to use for the relationship
        self.anchor = Anchor()
        self.anchor.save()

        # A model instance with a many to many relationship to the anchor
        self.instance = ReadOnlyManyToManyModel()
        self.instance.save()
        self.instance.rel.add(self.anchor)

        # A serialized representation of the model instance
        self.data = {'rel': [self.anchor.id], 'id': 1, 'text': 'anchor'}

    def test_update(self):
        """
        Attempt to update an instance of a model with a ManyToMany
        relationship.  Not updated due to read_only=True
        """
        new_anchor = Anchor()
        new_anchor.save()
        data = {'rel': [self.anchor.id, new_anchor.id]}
        serializer = self.serializer_class(self.instance, data=data)
        self.assertEqual(serializer.is_valid(), True)
        instance = serializer.save()
        self.assertEqual(len(ReadOnlyManyToManyModel.objects.all()), 1)
        self.assertEqual(instance.pk, 1)
        # rel is still as original (1 entry)
        self.assertEqual(list(instance.rel.all()), [self.anchor])

    def test_update_without_relationship(self):
        """
        Attempt to update an instance of a model where many to ManyToMany
        relationship is not supplied.  Not updated due to read_only=True
        """
        new_anchor = Anchor()
        new_anchor.save()
        data = {}
        serializer = self.serializer_class(self.instance, data=data)
        self.assertEqual(serializer.is_valid(), True)
        instance = serializer.save()
        self.assertEqual(len(ReadOnlyManyToManyModel.objects.all()), 1)
        self.assertEqual(instance.pk, 1)
        # rel is still as original (1 entry)
        self.assertEqual(list(instance.rel.all()), [self.anchor])
开发者ID:bingorabbit,项目名称:django-rest-framework-0.4,代码行数:53,代码来源:serializer.py


示例3: test_update

 def test_update(self):
     """
     Update an instance of a model with a ManyToMany relationship.
     """
     new_anchor = Anchor()
     new_anchor.save()
     data = {'rel': [self.anchor.id, new_anchor.id]}
     serializer = self.serializer_class(self.instance, data=data)
     self.assertEqual(serializer.is_valid(), True)
     instance = serializer.save()
     self.assertEqual(len(ManyToManyModel.objects.all()), 1)
     self.assertEqual(instance.pk, 1)
     self.assertEqual(list(instance.rel.all()), [self.anchor, new_anchor])
开发者ID:bingorabbit,项目名称:django-rest-framework-0.4,代码行数:13,代码来源:serializer.py


示例4: test_update_empty_relationship

 def test_update_empty_relationship(self):
     """
     Update an instance of a model with a ManyToMany relationship,
     containing no items.
     """
     new_anchor = Anchor()
     new_anchor.save()
     data = {'rel': []}
     serializer = self.serializer_class(self.instance, data=data)
     self.assertEquals(serializer.is_valid(), True)
     instance = serializer.save()
     self.assertEquals(len(ManyToManyModel.objects.all()), 1)
     self.assertEquals(instance.pk, 1)
     self.assertEquals(list(instance.rel.all()), [])
开发者ID:NamPNQ,项目名称:vp.repo,代码行数:14,代码来源:serializer.py


示例5: test_update_without_relationship

 def test_update_without_relationship(self):
     """
     Attempt to update an instance of a model where many to ManyToMany
     relationship is not supplied.  Not updated due to read_only=True
     """
     new_anchor = Anchor()
     new_anchor.save()
     data = {}
     serializer = self.serializer_class(self.instance, data=data)
     self.assertEqual(serializer.is_valid(), True)
     instance = serializer.save()
     self.assertEqual(len(ReadOnlyManyToManyModel.objects.all()), 1)
     self.assertEqual(instance.pk, 1)
     # rel is still as original (1 entry)
     self.assertEqual(list(instance.rel.all()), [self.anchor])
开发者ID:bingorabbit,项目名称:django-rest-framework-0.4,代码行数:15,代码来源:serializer.py


示例6: test_update

 def test_update(self):
     """
     Attempt to update an instance of a model with a ManyToMany
     relationship.  Not updated due to read_only=True
     """
     new_anchor = Anchor()
     new_anchor.save()
     data = {'rel': [self.anchor.id, new_anchor.id]}
     serializer = self.serializer_class(self.instance, data=data)
     self.assertEquals(serializer.is_valid(), True)
     instance = serializer.save()
     self.assertEquals(len(ReadOnlyManyToManyModel.objects.all()), 1)
     self.assertEquals(instance.pk, 1)
     # rel is still as original (1 entry)
     self.assertEquals(list(instance.rel.all()), [self.anchor])
开发者ID:NamPNQ,项目名称:vp.repo,代码行数:15,代码来源:serializer.py


示例7: setUp

    def setUp(self):
        """
        Create 3 BasicModel instances.
        """
        items = ["foo", "bar", "baz"]
        anchors = []
        for item in items:
            anchor = Anchor(text=item)
            anchor.save()
            anchors.append(anchor)

        manytomany = ManyToManyModel()
        manytomany.save()
        manytomany.rel.add(*anchors)

        self.data = [
            {
                "url": "http://testserver/manytomany/1/",
                "rel": ["http://testserver/anchor/1/", "http://testserver/anchor/2/", "http://testserver/anchor/3/"],
            }
        ]
        self.list_view = ManyToManyList.as_view()
        self.detail_view = ManyToManyDetail.as_view()
开发者ID:BryceBrown,项目名称:LinkstrDjango,代码行数:23,代码来源:hyperlinkedserializers.py


示例8: setUp

    def setUp(self):
        class ManyToManySerializer(serializers.ModelSerializer):
            class Meta:
                model = ManyToManyModel

        self.serializer_class = ManyToManySerializer

        # An anchor instance to use for the relationship
        self.anchor = Anchor()
        self.anchor.save()

        # A model instance with a many to many relationship to the anchor
        self.instance = ManyToManyModel()
        self.instance.save()
        self.instance.rel.add(self.anchor)

        # A serialized representation of the model instance
        self.data = {'id': 1, 'rel': [self.anchor.id]}
开发者ID:bingorabbit,项目名称:django-rest-framework-0.4,代码行数:18,代码来源:serializer.py


示例9: ManyToManyTests

class ManyToManyTests(TestCase):
    def setUp(self):
        class ManyToManySerializer(serializers.ModelSerializer):
            class Meta:
                model = ManyToManyModel

        self.serializer_class = ManyToManySerializer

        # An anchor instance to use for the relationship
        self.anchor = Anchor()
        self.anchor.save()

        # A model instance with a many to many relationship to the anchor
        self.instance = ManyToManyModel()
        self.instance.save()
        self.instance.rel.add(self.anchor)

        # A serialized representation of the model instance
        self.data = {'id': 1, 'rel': [self.anchor.id]}

    def test_retrieve(self):
        """
        Serialize an instance of a model with a ManyToMany relationship.
        """
        serializer = self.serializer_class(instance=self.instance)
        expected = self.data
        self.assertEqual(serializer.data, expected)

    def test_create(self):
        """
        Create an instance of a model with a ManyToMany relationship.
        """
        data = {'rel': [self.anchor.id]}
        serializer = self.serializer_class(data=data)
        self.assertEqual(serializer.is_valid(), True)
        instance = serializer.save()
        self.assertEqual(len(ManyToManyModel.objects.all()), 2)
        self.assertEqual(instance.pk, 2)
        self.assertEqual(list(instance.rel.all()), [self.anchor])

    def test_update(self):
        """
        Update an instance of a model with a ManyToMany relationship.
        """
        new_anchor = Anchor()
        new_anchor.save()
        data = {'rel': [self.anchor.id, new_anchor.id]}
        serializer = self.serializer_class(self.instance, data=data)
        self.assertEqual(serializer.is_valid(), True)
        instance = serializer.save()
        self.assertEqual(len(ManyToManyModel.objects.all()), 1)
        self.assertEqual(instance.pk, 1)
        self.assertEqual(list(instance.rel.all()), [self.anchor, new_anchor])

    def test_create_empty_relationship(self):
        """
        Create an instance of a model with a ManyToMany relationship,
        containing no items.
        """
        data = {'rel': []}
        serializer = self.serializer_class(data=data)
        self.assertEqual(serializer.is_valid(), True)
        instance = serializer.save()
        self.assertEqual(len(ManyToManyModel.objects.all()), 2)
        self.assertEqual(instance.pk, 2)
        self.assertEqual(list(instance.rel.all()), [])

    def test_update_empty_relationship(self):
        """
        Update an instance of a model with a ManyToMany relationship,
        containing no items.
        """
        new_anchor = Anchor()
        new_anchor.save()
        data = {'rel': []}
        serializer = self.serializer_class(self.instance, data=data)
        self.assertEqual(serializer.is_valid(), True)
        instance = serializer.save()
        self.assertEqual(len(ManyToManyModel.objects.all()), 1)
        self.assertEqual(instance.pk, 1)
        self.assertEqual(list(instance.rel.all()), [])

    def test_create_empty_relationship_flat_data(self):
        """
        Create an instance of a model with a ManyToMany relationship,
        containing no items, using a representation that does not support
        lists (eg form data).
        """
        data = MultiValueDict()
        data.setlist('rel', [''])
        serializer = self.serializer_class(data=data)
        self.assertEqual(serializer.is_valid(), True)
        instance = serializer.save()
        self.assertEqual(len(ManyToManyModel.objects.all()), 2)
        self.assertEqual(instance.pk, 2)
        self.assertEqual(list(instance.rel.all()), [])
开发者ID:bingorabbit,项目名称:django-rest-framework-0.4,代码行数:96,代码来源:serializer.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python models.ForeignKeyTarget类代码示例发布时间:2022-05-26
下一篇:
Python test.CoreAPIClient类代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap