Beispiel #1
0
    async def test_get_options__with_deserialize(self):

        class Model(model.Model):
            foreign = fields.ForeignKey(to=self.model)

            class Meta:
                collection = uuid.uuid4().hex

            def __str__(self):
                return self.foreign.name

        name = 'test'
        instance = await self.model.objects.create(name=name)
        await Model.objects.create(foreign=instance)

        field = fields.ForeignKey(to=Model)

        self.assertEqual(
            name, (await field.get_options())['widget']['options'][0]['label']
        )
Beispiel #2
0
        class ThirdModel(model.Model):
            name = fields.String()
            related = fields.ForeignKey(to=SecondModel)

            class Meta:
                collection = 'test3'
Beispiel #3
0
        class CustomModel(model.Model):
            string = fields.String()
            related = fields.ForeignKey(to=RelatedModel, to_field='name')

            class Meta:
                collection = 'test'
Beispiel #4
0
    async def test_serialize__id(self):
        field = fields.ForeignKey(to=self.model)

        value = await field.serialize(self.instance)

        self.assertEqual(str(self.instance._id), value)
Beispiel #5
0
    async def test_validate__from_key(self):
        field = fields.ForeignKey(to=self.model, to_field='name')
        await field.validate(self.instance.name)

        self.assertIsInstance(self.instance, self.model)
Beispiel #6
0
    async def test_deserialize__from_string_id(self):
        field = fields.ForeignKey(to=self.model)
        value = await field.deserialize(self.instance._id)

        self.assertEqual(value.name, self.instance.name)
Beispiel #7
0
    async def test_deserialize__from_instance(self):
        field = fields.ForeignKey(to=self.model, to_field='name')
        value = await field.deserialize(self.instance)

        self.assertEqual(value.name, self.instance.name)
Beispiel #8
0
    async def test_deserialize__self(self):
        field = fields.ForeignKey(to='self')
        field.bind(model=self.model)
        value = await field.deserialize(self.instance._id)

        self.assertEqual(value._id, self.instance._id)
Beispiel #9
0
    def test_init__with_related_model_as_string__self(self):
        field = fields.ForeignKey(to='self')
        field.bind(model=TestModel)

        self.assertEqual(TestModel, field.get_related_model())
Beispiel #10
0
    def test_init__with_related_model_as_string(self):
        field = fields.ForeignKey(to='monstro.testing.TestModel')

        self.assertEqual(TestModel, field.get_related_model())