def test_render_as_slugs_many(self): obj = Mock() obj.attached = [self.app] field = SlugOrPrimaryKeyRelatedField(render_as='slug', slug_field='app_slug', many=True) eq_(field.field_to_native(obj, 'attached'), [self.app.app_slug])
def test_render_as_slug(self): obj = Mock() obj.attached = self.app field = SlugOrPrimaryKeyRelatedField(render_as='slug', slug_field='app_slug') eq_(field.field_to_native(obj, 'attached'), self.app.app_slug)
def test_render_as_pks(self): app = Webapp.objects.get(pk=337141) c1 = Category.objects.create(name="delicious", slug="foo", type=amo.ADDON_WEBAPP) c2 = Category.objects.create(name="scrumptious", slug="baz", type=amo.ADDON_WEBAPP) AddonCategory.objects.create(addon=app, category=c1) AddonCategory.objects.create(addon=app, category=c2) field = SlugOrPrimaryKeyRelatedField(queryset=Category.objects.all(), many=True) eq_(field.field_to_native(app, "categories"), [c1.pk, c2.pk])
def test_render_as_slugs(self): app = Webapp.objects.get(pk=337141) c1 = Category.objects.create(name='delicious', slug='foo', type=amo.ADDON_WEBAPP) c2 = Category.objects.create(name='scrumptious', slug='baz', type=amo.ADDON_WEBAPP) AddonCategory.objects.create(addon=app, category=c1) AddonCategory.objects.create(addon=app, category=c2) field = SlugOrPrimaryKeyRelatedField(queryset=Category.objects.all(), render_as='slug', slug_field='slug', many=True) eq_(field.field_to_native(app, 'categories'), [c1.slug, c2.slug])
def test_render_as_pks(self): app = Webapp.objects.get(pk=337141) c1 = Category.objects.create(name='delicious', slug='foo', type=amo.ADDON_WEBAPP) c2 = Category.objects.create(name='scrumptious', slug='baz', type=amo.ADDON_WEBAPP) AddonCategory.objects.create(addon=app, category=c1) AddonCategory.objects.create(addon=app, category=c2) field = SlugOrPrimaryKeyRelatedField(queryset=Category.objects.all(), many=True) eq_(field.field_to_native(app, 'categories'), [c1.pk, c2.pk])
def test_render_as_slug(self): v = Version.objects.get(pk=1268829) field = SlugOrPrimaryKeyRelatedField(queryset=Webapp.objects.all(), render_as='slug', slug_field='app_slug') eq_(field.field_to_native(v, 'addon'), v.addon.app_slug)
def test_render_as_pk(self): v = Version.objects.get(pk=1268829) field = SlugOrPrimaryKeyRelatedField(queryset=Webapp.objects.all()) eq_(field.field_to_native(v, 'addon'), v.addon.pk)
def test_render_as_pks_many(self): obj = Mock() obj.attached = [self.app] field = SlugOrPrimaryKeyRelatedField(many=True) eq_(field.field_to_native(obj, 'attached'), [self.app.pk])
def test_render_as_pk(self): obj = Mock() obj.attached = self.app field = SlugOrPrimaryKeyRelatedField() eq_(field.field_to_native(obj, 'attached'), self.app.pk)