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

Python serializers.CollectionSerializer类代码示例

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

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



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

示例1: test_wrong_default_language_serialization

 def test_wrong_default_language_serialization(self):
     # The following is wrong because we only accept the 'en-us' form.
     data = {'default_language': u'en_US'}
     serializer = CollectionSerializer(instance=self.collection, data=data,
                                       partial=True)
     eq_(serializer.is_valid(), False)
     ok_('default_language' in serializer.errors)
开发者ID:hardikj,项目名称:zamboni,代码行数:7,代码来源:test_serializers.py


示例2: test_name_required

 def test_name_required(self):
     data = {
         'description': u'some description',
         'collection_type': u'1'
     }
     serializer = CollectionSerializer(instance=self.collection, data=data)
     eq_(serializer.is_valid(), False)
     ok_('name' in serializer.errors)
开发者ID:rachelhathaway,项目名称:zamboni,代码行数:8,代码来源:test_serializers.py


示例3: test_translation_deserialization

 def test_translation_deserialization(self):
     data = {
         'name': u'¿Dónde está la biblioteca?'
     }
     serializer = CollectionSerializer(instance=self.collection, data=data,
                                       partial=True)
     eq_(serializer.errors, {})
     ok_(serializer.is_valid())
开发者ID:hardikj,项目名称:zamboni,代码行数:8,代码来源:test_serializers.py


示例4: test_name_cannot_be_empty

 def test_name_cannot_be_empty(self):
     data = {
         'name': u''
     }
     serializer = CollectionSerializer(instance=self.collection, data=data,
                                       partial=True)
     eq_(serializer.is_valid(), False)
     ok_('name' in serializer.errors)
     eq_(serializer.errors['name'],
         [u'The field must have a length of at least 1 characters.'])
开发者ID:rachelhathaway,项目名称:zamboni,代码行数:10,代码来源:test_serializers.py


示例5: test_name_one_locale_must_be_non_empty

 def test_name_one_locale_must_be_non_empty(self):
     data = {
         'name': {
             'fr': u'',
             'en-US': u'Non-Empty Name'
         }
     }
     serializer = CollectionSerializer(instance=self.collection, data=data,
                                       partial=True)
     eq_(serializer.is_valid(), True)
开发者ID:rachelhathaway,项目名称:zamboni,代码行数:10,代码来源:test_serializers.py


示例6: test_name_all_locales_cannot_be_empty

 def test_name_all_locales_cannot_be_empty(self):
     data = {
         'name': {
             'fr': u'',
             'en-US': u''
         }
     }
     serializer = CollectionSerializer(instance=self.collection, data=data,
                                       partial=True)
     eq_(serializer.is_valid(), False)
     ok_('name' in serializer.errors)
开发者ID:rachelhathaway,项目名称:zamboni,代码行数:11,代码来源:test_serializers.py


示例7: test_translation_deserialization_multiples_locales

 def test_translation_deserialization_multiples_locales(self):
     data = {
         'name': {
             'fr': u'Chat grincheux…',
             'en-US': u'Grumpy Cat...'
         }
     }
     serializer = CollectionSerializer(instance=self.collection, data=data,
                                       partial=True)
     eq_(serializer.errors, {})
     ok_(serializer.is_valid())
开发者ID:hardikj,项目名称:zamboni,代码行数:11,代码来源:test_serializers.py


示例8: setUp

 def setUp(self):
     minimal_context = {
         'request': RequestFactory().get('/whatever')
     }
     self.collection = Collection.objects.create(**self.collection_data)
     self.serializer = CollectionSerializer(self.collection,
                                            context=minimal_context)
开发者ID:hardikj,项目名称:zamboni,代码行数:7,代码来源:test_serializers.py


示例9: TestCollectionSerializer

class TestCollectionSerializer(CollectionDataMixin, amo.tests.TestCase):
    def setUp(self):
        self.collection = Collection.objects.create(**self.collection_data)
        self.serializer = CollectionSerializer()

    def test_to_native(self, apps=None):
        if apps:
            for app in apps:
                self.collection.add_app(app)
        else:
            apps = []

        data = self.serializer.to_native(self.collection)
        for name, value in self.collection_data.iteritems():
            eq_(self.collection_data[name], data[name])
        self.assertSetEqual(
            data.keys(),
            [
                "id",
                "name",
                "description",
                "apps",
                "collection_type",
                "category",
                "region",
                "carrier",
                "author",
                "is_public",
            ],
        )
        for order, app in enumerate(apps):
            eq_(data["apps"][order]["slug"], app.app_slug)

    def test_to_native_with_apps(self):
        apps = [amo.tests.app_factory() for n in xrange(1, 5)]
        self.test_to_native(apps=apps)
开发者ID:kodypeterson,项目名称:zamboni,代码行数:36,代码来源:test_serializers.py


示例10: TestCollectionSerializer

class TestCollectionSerializer(CollectionDataMixin, amo.tests.TestCase):

    def setUp(self):
        self.collection = Collection.objects.create(**self.collection_data)
        self.serializer = CollectionSerializer()

    def test_to_native(self, apps=None):
        if apps:
            for app in apps:
                self.collection.add_app(app)
        else:
            apps = []

        data = self.serializer.to_native(self.collection)
        for name, value in self.collection_data.iteritems():
            eq_(self.collection_data[name], data[name])
        self.assertSetEqual(data.keys(), ['id', 'name', 'description', 'apps',
                                          'collection_type'])
        for order, app in enumerate(apps):
            eq_(data['apps'][order]['slug'], app.app_slug)

    def test_to_native_with_apps(self):
        apps = [amo.tests.app_factory() for n in xrange(1, 5)]
        self.test_to_native(apps=apps)
开发者ID:selimsumlu,项目名称:zamboni,代码行数:24,代码来源:test_serializers.py


示例11: setUp

 def setUp(self):
     minimal_context = {"request": RequestFactory().get("/whatever")}
     minimal_context["request"].user = AnonymousUser()
     self.collection = Collection.objects.create(**self.collection_data)
     self.serializer = CollectionSerializer(self.collection, context=minimal_context)
开发者ID:gurumukhi,项目名称:zamboni,代码行数:5,代码来源:test_serializers.py


示例12: TestCollectionSerializer

class TestCollectionSerializer(CollectionDataMixin, amo.tests.TestCase):

    def setUp(self):
        minimal_context = {
            'request': RequestFactory().get('/whatever')
        }
        self.collection = Collection.objects.create(**self.collection_data)
        self.serializer = CollectionSerializer(self.collection,
                                               context=minimal_context)

    def test_to_native(self, apps=None):
        if apps:
            for app in apps:
                self.collection.add_app(app)
        else:
            apps = []

        data = self.serializer.to_native(self.collection)
        for name, value in self.collection_data.iteritems():
            eq_(self.collection_data[name], data[name])
        self.assertSetEqual(data.keys(), [
            'apps', 'author', 'background_color', 'carrier', 'category',
            'collection_type', 'default_language', 'description', 'id',
            'image', 'is_public', 'name', 'region', 'slug', 'text_color'
        ])
        for order, app in enumerate(apps):
            eq_(data['apps'][order]['slug'], app.app_slug)
        return data

    def test_to_native_operator(self):
        self.collection.update(collection_type=COLLECTIONS_TYPE_OPERATOR)
        data = self.serializer.to_native(self.collection)
        ok_('can_be_hero' in data.keys())

    def test_image(self):
        data = self.serializer.to_native(self.collection)
        eq_(data['image'], None)
        self.collection.update(has_image=True)
        data = self.serializer.to_native(self.collection)
        self.assertApiUrlEqual(data['image'],
            '/rocketfuel/collections/%s/image.png' % self.collection.pk)

    def test_wrong_default_language_serialization(self):
        # The following is wrong because we only accept the 'en-us' form.
        data = {'default_language': u'en_US'}
        serializer = CollectionSerializer(instance=self.collection, data=data,
                                          partial=True)
        eq_(serializer.is_valid(), False)
        ok_('default_language' in serializer.errors)

    def test_translation_deserialization(self):
        data = {
            'name': u'¿Dónde está la biblioteca?'
        }
        serializer = CollectionSerializer(instance=self.collection, data=data,
                                          partial=True)
        eq_(serializer.errors, {})
        ok_(serializer.is_valid())

    def test_translation_deserialization_multiples_locales(self):
        data = {
            'name': {
                'fr': u'Chat grincheux…',
                'en-US': u'Grumpy Cat...'
            }
        }
        serializer = CollectionSerializer(instance=self.collection, data=data,
                                          partial=True)
        eq_(serializer.errors, {})
        ok_(serializer.is_valid())

    def test_empty_choice_deserialization(self):
        # Build data from existing object.
        data = self.serializer.to_native(self.collection)
        data.pop('id')
        # Emulate empty values passed via POST.
        data.update({'carrier': '', 'region': ''})

        instance = self.serializer.from_native(data, None)
        eq_(self.serializer.errors, {})
        ok_(self.serializer.is_valid())
        eq_(instance.region, None)
        eq_(instance.carrier, None)

    def test_to_native_with_apps(self):
        apps = [amo.tests.app_factory() for n in xrange(1, 5)]
        data = self.test_to_native(apps=apps)
        keys = data['apps'][0].keys()
        ok_('name' in keys)
        ok_('id' in keys)

    def validate(self, **kwargs):
        return self.serializer.validate(kwargs)

    def test_validation_operatorshelf_category(self):
        category = Category.objects.create(name='BastaCorp', slug='basta',
                                           type=amo.ADDON_WEBAPP)
        ok_(self.validate(collection_type=COLLECTIONS_TYPE_BASIC,
                          category=category))
        ok_(self.validate(collection_type=COLLECTIONS_TYPE_OPERATOR))
#.........这里部分代码省略.........
开发者ID:hardikj,项目名称:zamboni,代码行数:101,代码来源:test_serializers.py


示例13: TestCollectionSerializer

class TestCollectionSerializer(CollectionDataMixin, amo.tests.TestCase):

    def setUp(self):
        minimal_context = {
            'request': RequestFactory().get('/whatever')
        }
        self.collection = Collection.objects.create(**self.collection_data)
        self.serializer = CollectionSerializer(context=minimal_context)

    def test_to_native(self, apps=None):
        if apps:
            for app in apps:
                self.collection.add_app(app)
        else:
            apps = []

        data = self.serializer.to_native(self.collection)
        for name, value in self.collection_data.iteritems():
            eq_(self.collection_data[name], data[name])
        self.assertSetEqual(data.keys(), ['apps', 'author', 'background_color',
                                          'carrier', 'category',
                                          'collection_type', 'default_language',
                                          'description', 'id', 'image',
                                          'is_public', 'name', 'region',
                                          'slug', 'text_color'])
        for order, app in enumerate(apps):
            eq_(data['apps'][order]['slug'], app.app_slug)
        return data

    def test_image(self):
        data = self.serializer.to_native(self.collection)
        eq_(data['image'], None)
        try:
            os.makedirs(os.path.dirname(self.collection.image_path()))
        except OSError:
            pass
        open(self.collection.image_path(), 'w').write("some data")
        data = self.serializer.to_native(self.collection)
        eq_(data['image'], reverse('collection-image-detail',
                                   kwargs={'pk': self.collection.id}))

    def test_wrong_default_language_serialization(self):
        # The following is wrong because we only accept the 'en-us' form.
        data = {'default_language': u'en_US'}
        serializer = CollectionSerializer(instance=self.collection, data=data,
                                          partial=True)
        eq_(serializer.is_valid(), False)
        ok_('default_language' in serializer.errors)

    def test_translation_deserialization(self):
        data = {
            'name': u'¿Dónde está la biblioteca?'
        }
        serializer = CollectionSerializer(instance=self.collection, data=data,
                                          partial=True)
        eq_(serializer.errors, {})
        ok_(serializer.is_valid())

    def test_translation_deserialization_multiples_locales(self):
        data = {
            'name': {
                'fr': u'Chat grincheux…',
                'en-US': u'Grumpy Cat...'
            }
        }
        serializer = CollectionSerializer(instance=self.collection, data=data,
                                          partial=True)
        eq_(serializer.errors, {})
        ok_(serializer.is_valid())

    def test_empty_choice_deserialization(self):
        # Build data from existing object.
        data = self.serializer.to_native(self.collection)
        data.pop('id')
        # Emulate empty values passed via POST.
        data.update({'carrier': '', 'region': ''})

        instance = self.serializer.from_native(data, None)
        eq_(self.serializer.errors, {})
        ok_(self.serializer.is_valid())
        eq_(instance.region, None)
        eq_(instance.carrier, None)

    def test_to_native_with_apps(self):
        apps = [amo.tests.app_factory() for n in xrange(1, 5)]
        data = self.test_to_native(apps=apps)
        keys = data['apps'][0].keys()
        ok_('name' in keys)
        ok_('id' in keys)
开发者ID:rhelmer,项目名称:zamboni,代码行数:89,代码来源:test_serializers.py


示例14: test_name_one_locale_must_be_non_empty

 def test_name_one_locale_must_be_non_empty(self):
     data = {"name": {"fr": u"", "en-US": u"Non-Empty Name"}}
     serializer = CollectionSerializer(instance=self.collection, data=data, partial=True)
     eq_(serializer.is_valid(), True)
开发者ID:gurumukhi,项目名称:zamboni,代码行数:4,代码来源:test_serializers.py


示例15: TestCollectionSerializer

class TestCollectionSerializer(CollectionDataMixin, amo.tests.TestCase):
    def setUp(self):
        minimal_context = {"request": RequestFactory().get("/whatever")}
        self.collection = Collection.objects.create(**self.collection_data)
        self.serializer = CollectionSerializer(self.collection, context=minimal_context)

    def test_metadata_is_serialized_to_json(self):
        ok_(json.dumps(self.serializer.metadata()))

    def test_to_native(self, apps=None):
        if apps:
            for app in apps:
                self.collection.add_app(app)
        else:
            apps = []

        data = self.serializer.to_native(self.collection)
        for name, value in self.collection_data.iteritems():
            eq_(self.collection_data[name], data[name])
        self.assertSetEqual(
            data.keys(),
            [
                "apps",
                "author",
                "background_color",
                "carrier",
                "category",
                "collection_type",
                "default_language",
                "description",
                "id",
                "image",
                "is_public",
                "name",
                "region",
                "slug",
                "text_color",
            ],
        )
        for order, app in enumerate(apps):
            eq_(data["apps"][order]["slug"], app.app_slug)
        return data

    def test_to_native_operator(self):
        self.collection.update(collection_type=COLLECTIONS_TYPE_OPERATOR)
        data = self.serializer.to_native(self.collection)
        ok_("can_be_hero" in data.keys())

    @patch("mkt.collections.serializers.build_id", "bbbbbb")
    def test_image(self):
        data = self.serializer.to_native(self.collection)
        eq_(data["image"], None)
        self.collection.update(has_image=True)
        data = self.serializer.to_native(self.collection)
        self.assertApiUrlEqual(data["image"], "/rocketfuel/collections/%s/image.png?bbbbbb" % self.collection.pk)

    def test_wrong_default_language_serialization(self):
        # The following is wrong because we only accept the 'en-us' form.
        data = {"default_language": u"en_US"}
        serializer = CollectionSerializer(instance=self.collection, data=data, partial=True)
        eq_(serializer.is_valid(), False)
        ok_("default_language" in serializer.errors)

    def test_translation_deserialization(self):
        data = {"name": u"¿Dónde está la biblioteca?"}
        serializer = CollectionSerializer(instance=self.collection, data=data, partial=True)
        eq_(serializer.errors, {})
        ok_(serializer.is_valid())

    def test_translation_deserialization_multiples_locales(self):
        data = {"name": {"fr": u"Chat grincheux…", "en-US": u"Grumpy Cat..."}}
        serializer = CollectionSerializer(instance=self.collection, data=data, partial=True)
        eq_(serializer.errors, {})
        ok_(serializer.is_valid())

    def test_empty_choice_deserialization(self):
        # Build data from existing object.
        data = self.serializer.to_native(self.collection)
        data.pop("id")
        # Emulate empty values passed via POST.
        data.update({"carrier": "", "region": ""})

        instance = self.serializer.from_native(data, None)
        eq_(self.serializer.errors, {})
        ok_(self.serializer.is_valid())
        eq_(instance.region, None)
        eq_(instance.carrier, None)

    def test_to_native_with_apps(self):
        apps = [amo.tests.app_factory() for n in xrange(1, 5)]
        data = self.test_to_native(apps=apps)
        keys = data["apps"][0].keys()
        ok_("name" in keys)
        ok_("id" in keys)

    def validate(self, **kwargs):
        return self.serializer.validate(kwargs)

    def test_validation_operatorshelf_category(self):
        category = Category.objects.create(name="BastaCorp", slug="basta", type=amo.ADDON_WEBAPP)
#.........这里部分代码省略.........
开发者ID:BIGGANI,项目名称:zamboni,代码行数:101,代码来源:test_serializers.py


示例16: TestCollectionSerializer

class TestCollectionSerializer(CollectionDataMixin, amo.tests.TestCase):
    def setUp(self):
        self.collection = Collection.objects.create(**self.collection_data)
        self.serializer = CollectionSerializer()

    def test_to_native(self, apps=None):
        if apps:
            for app in apps:
                self.collection.add_app(app)
        else:
            apps = []

        data = self.serializer.to_native(self.collection)
        for name, value in self.collection_data.iteritems():
            eq_(self.collection_data[name], data[name])
        self.assertSetEqual(
            data.keys(),
            [
                "id",
                "name",
                "description",
                "apps",
                "collection_type",
                "category",
                "region",
                "carrier",
                "author",
                "slug",
                "is_public",
                "default_language",
            ],
        )
        for order, app in enumerate(apps):
            eq_(data["apps"][order]["slug"], app.app_slug)
        return data

    def test_wrong_default_language_serialization(self):
        # The following is wrong because we only accept the 'en-us' form.
        data = {"default_language": u"en_US"}
        serializer = CollectionSerializer(instance=self.collection, data=data, partial=True)
        eq_(serializer.is_valid(), False)
        ok_("default_language" in serializer.errors)

    def test_translation_deserialization(self):
        data = {"name": u"¿Dónde está la biblioteca?"}
        serializer = CollectionSerializer(instance=self.collection, data=data, partial=True)
        eq_(serializer.errors, {})
        ok_(serializer.is_valid())

    def test_translation_deserialization_multiples_locales(self):
        data = {"name": {"fr": u"Chat grincheux…", "en-US": u"Grumpy Cat..."}}
        serializer = CollectionSerializer(instance=self.collection, data=data, partial=True)
        eq_(serializer.errors, {})
        ok_(serializer.is_valid())

    def test_to_native_with_apps(self):
        apps = [amo.tests.app_factory() for n in xrange(1, 5)]
        data = self.test_to_native(apps=apps)
        keys = data["apps"][0].keys()
        ok_("name" in keys)
        ok_("id" in keys)
开发者ID:l-hedgehog,项目名称:zamboni,代码行数:61,代码来源:test_serializers.py


示例17: TestCollectionSerializer

class TestCollectionSerializer(CollectionDataMixin, amo.tests.TestCase):
    def setUp(self):
        minimal_context = {"request": RequestFactory().get("/whatever")}
        minimal_context["request"].user = AnonymousUser()
        self.collection = Collection.objects.create(**self.collection_data)
        self.serializer = CollectionSerializer(self.collection, context=minimal_context)

    def test_metadata_is_serialized_to_json(self):
        ok_(json.dumps(self.serializer.metadata()))

    def test_to_native(self, apps=None):
        if apps:
            for app in apps:
                self.collection.add_app(app)
        else:
            apps = []

        data = self.serializer.to_native(self.collection)
        for name, value in self.collection_data.iteritems():
            eq_(self.collection_data[name], data[name])
        self.assertSetEqual(
            data.keys(),
            [
                "apps",
                "author",
                "background_color",
                "carrier",
                "category",
                "collection_type",
                "default_language",
                "description",
                "id",
                "image",
                "is_public",
                "name",
                "region",
                "slug",
                "text_color",
            ],
        )
        for order, app in enumerate(apps):
            eq_(data["apps"][order]["slug"], app.app_slug)
        return data

    def test_to_native_operator(self):
        self.collection.update(collection_type=COLLECTIONS_TYPE_OPERATOR)
        data = self.serializer.to_native(self.collection)
        ok_("can_be_hero" in data.keys())

    @override_settings(STATIC_URL="https://testserver-cdn/")
    def test_image(self):
        data = self.serializer.to_native(self.collection)
        eq_(data["image"], None)
        self.collection.update(image_hash="bbbbbb")
        data = self.serializer.to_native(self.collection)
        self.assertApiUrlEqual(
            data["image"],
            "/rocketfuel/collections/%s/image.png?bbbbbb" % self.collection.pk,
            scheme="https",
            netloc="testserver-cdn",
        )

    def test_wrong_default_language_serialization(self):
        # The following is wrong because we only accept the 'en-us' form.
        data = {"default_language": u"en_US"}
        serializer = CollectionSerializer(instance=self.collection, data=data, partial=True)
        eq_(serializer.is_valid(), False)
        ok_("default_language" in serializer.errors)

    def test_name_required(self):
        data = {"description": u"some description", "collection_type": u"1"}
        serializer = CollectionSerializer(instance=self.collection, data=data)
        eq_(serializer.is_valid(), False)
        ok_("name" in serializer.errors)

    def test_name_cannot_be_empty(self):
        data = {"name": u""}
        serializer = CollectionSerializer(instance=self.collection, data=data, partial=True)
        eq_(serializer.is_valid(), False)
        ok_("name" in serializer.errors)
        eq_(serializer.errors["name"], [u"The field must have a length of at least 1 characters."])

    def test_name_all_locales_cannot_be_empty(self):
        data = {"name": {"fr": u"", "en-US": u""}}
        serializer = CollectionSerializer(instance=self.collection, data=data, partial=True)
        eq_(serializer.is_valid(), False)
        ok_("name" in serializer.errors)

    def test_name_one_locale_must_be_non_empty(self):
        data = {"name": {"fr": u"", "en-US": u"Non-Empty Name"}}
        serializer = CollectionSerializer(instance=self.collection, data=data, partial=True)
        eq_(serializer.is_valid(), True)

    def test_translation_deserialization(self):
        data = {"name": u"¿Dónde está la biblioteca?"}
        serializer = CollectionSerializer(instance=self.collection, data=data, partial=True)
        eq_(serializer.errors, {})
        ok_(serializer.is_valid())

    def test_translation_deserialization_multiples_locales(self):
#.........这里部分代码省略.........
开发者ID:gurumukhi,项目名称:zamboni,代码行数:101,代码来源:test_serializers.py


示例18: TestCollectionSerializer

class TestCollectionSerializer(CollectionDataMixin, amo.tests.TestCase):

    def setUp(self):
        minimal_context = {
            'request': RequestFactory().get('/whatever')
        }
        minimal_context['request'].user = AnonymousUser()
        self.collection = Collection.objects.create(**self.collection_data)
        self.serializer = CollectionSerializer(self.collection,
                                               context=minimal_context)

    def test_metadata_is_serialized_to_json(self):
        ok_(json.dumps(self.serializer.metadata()))

    def test_to_native(self, apps=None):
        if apps:
            for app in apps:
                self.collection.add_app(app)
        else:
            apps = []

        data = self.serializer.to_native(self.collection)
        for name, value in self.collection_data.iteritems():
            eq_(self.collection_data[name], data[name])
        self.assertSetEqual(data.keys(), [
            'apps', 'author', 'background_color', 'carrier', 'category',
            'collection_type', 'default_language', 'description', 'id',
            'image', 'is_public', 'name', 'region', 'slug', 'text_color'
        ])
        for order, app in enumerate(apps):
            eq_(data['apps'][order]['slug'], app.app_slug)
        return data

    def test_to_native_operator(self):
        self.collection.update(collection_type=COLLECTIONS_TYPE_OPERATOR)
        data = self.serializer.to_native(self.collection)
        ok_('can_be_hero' in data.keys())

    @override_settings(STATIC_URL='https://testserver-cdn/')
    def test_image(self):
        data = self.serializer.to_native(self.collection)
        eq_(data['image'], None)
        self.collection.update(image_hash='bbbbbb')
        data = self.serializer.to_native(self.collection)
        self.assertApiUrlEqual(data['image'],
            '/rocketfuel/collections/%s/image.png?bbbbbb' % self.collection.pk,
            scheme='https', netloc='testserver-cdn')

    def test_wrong_default_language_serialization(self):
        # The following is wrong because we only accept the 'en-us' form.
        data = {'default_language': u'en_US'}
        serializer = CollectionSerializer(instance=self.collection, data=data,
                                          partial=True)
        eq_(serializer.is_valid(), False)
        ok_('default_language' in serializer.errors)

    def test_name_required(self):
        data = {
            'description': u'some description',
            'collection_type': u'1'
        }
        serializer = CollectionSerializer(instance=self.collection, data=data)
        eq_(serializer.is_valid(), False)
        ok_('name' in serializer.errors)

    def test_name_cannot_be_empty(self):
        data = {
            'name': u''
        }
        serializer = CollectionSerializer(instance=self.collection, data=data,
                                          partial=True)
        eq_(serializer.is_valid(), False)
        ok_('name' in serializer.errors)
        eq_(serializer.errors['name'],
            [u'The field must have a length of at least 1 characters.'])

    def test_name_all_locales_cannot_be_empty(self):
        data = {
            'name': {
                'fr': u'',
                'en-US': u''
            }
        }
        serializer = CollectionSerializer(instance=self.collection, data=data,
                                          partial=True)
        eq_(serializer.is_valid(), False)
        ok_('name' in serializer.errors)

    def test_name_one_locale_must_be_non_empty(self):
        data = {
            'name': {
                'fr': u'',
                'en-US': u'Non-Empty Name'
            }
        }
        serializer = CollectionSerializer(instance=self.collection, data=data,
                                          partial=True)
        eq_(serializer.is_valid(), True)

    def test_translation_deserialization(self):
#.........这里部分代码省略.........
开发者ID:rachelhathaway,项目名称:zamboni,代码行数:101,代码来源:test_serializers.py


示例19: test_name_required

 def test_name_required(self):
     data = {"description": u"some description", "collection_type": u"1"}
     serializer = CollectionSerializer(instance=self.collection, data=data)
     eq_(serializer.is_valid(), False)
     ok_("name" in serializer.errors)
开发者ID:gurumukhi,项目名称:zamboni,代码行数:5,代码来源:test_serializers.py


示例20: test_name_cannot_be_empty

 def test_name_cannot_be_empty(self):
     data = {"name": u""}
     serializer = CollectionSerializer(instance=self.collection, data=data, partial=True)
     eq_(serializer.is_valid(), False)
     ok_("name" in serializer.errors)
     eq_(serializer.errors["name"], [u"The field must have a length of at least 1 characters."])
开发者ID:gurumukhi,项目名称:zamboni,代码行数:6,代码来源:test_serializers.py



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Python utils.create_comm_note函数代码示例发布时间:2022-05-27
下一篇:
Python carriers.get_carrier函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

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

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

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