lundi 7 octobre 2019

Polymorphic model fixtures fail when loading from Django tests

I'm running a few test using fixtures to create initial data I need. The fixtures dump/load correctly to populate the actual db, but when loading the fixtures during tests I get the error: polymorphic.models.PolymorphicTypeInvalid: ContentType 9 for <class 'attributes.models.Attribute'> #5 does not point to a subclass!

Here is that fixture:

- model: items.item
  pk: 1
  fields:
    polymorphic_ctype: 12
    name: White T-Shirt
    plural_name: White T-Shirts
- model: items.item
  pk: 2
  fields:
    polymorphic_ctype: 12
    name: Black Jeans
    plural_name: Black Jeans
- model: items.item
  pk: 3
  fields:
    polymorphic_ctype: 11
    name: Firebomb
    plural_name: Firebombs
- model: items.item
  pk: 4
  fields:
    polymorphic_ctype: 10
    name: Gold
    plural_name: Gold
- model: items.item
  pk: 5
  fields:
    polymorphic_ctype: 9
    name: Fork
    plural_name: Forks
- model: items.weaponitem
  pk: 5
  fields: {}
- model: items.apparelitem
  pk: 1
  fields: {}
- model: items.apparelitem
  pk: 2
  fields: {}
- model: items.combatitem
  pk: 3
  fields: {}
- model: items.materialitem
  pk: 4
  fields: {}

Here is the actual line where the test fails:

    fixtures = ['characters/fixtures/tests', 'items/fixtures/tests', 'skills/fixtures/tests']

    user_character = None

    def setUp(self):
        human_class = CharacterClass.objects.get(name='Human')
        self.user_character = UserCharacter.objects.create(name="Ratboi", character_class=human_class)

    def test_inventory_methods(self):
        user = self.user_character
        fork = WeaponItem.objects.get(name='Fork')```

Fails here at last line, getting "fork".

The other fixtures load appropriately, but items are the only models currently using polymorphic models.

Aucun commentaire:

Enregistrer un commentaire