Opened 18 years ago

Last modified 17 years ago

#3638 closed

loading python fixtures is broken — at Version 4

Reported by: donlaverty Owned by: nobody
Component: Testing framework Version: dev
Severity: Keywords: fixture
Cc: Triage Stage: Accepted
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description (last modified by Malcolm Tredinnick)

Reproduce:
Use this fixture:

[{"pk": "1", "model": "main.category", "fields": {"link_name": "all", "name": "\/", "parent": null, "description": ""}}, {"pk": "2", "model": "main.category", "fields": {"link_name": "accessoires", "name": "Accessoires", "parent": 1, "description": ""}}, {"pk": "3", "model": "main.category", "fields": {"link_name": "art_and_design", "name": "Art & Design", "parent": 1, "description": ""}}]

with this model:

class Category(models.Model):
    class Admin:
        pass

    class Meta:
        ordering =['name']

    name        = models.CharField(maxlength=50)
    link_name   = models.SlugField(unique=True)
    description = models.TextField(blank=True)
    parent      = models.ForeignKey('self',blank=True,null=True)

    
    def tree(self,tree=[]):
        tree.append( self )
        children = self.category_set.all()
        child_tree = []
        for c in children:
            if c.name != '/':
                c.tree(child_tree)
        if not child_tree == []:
            tree.append(child_tree)
        return tree

    def link(self):
        return str(self)[2:]

    def __str__(self):
        if not self.parent  :
            return self.name
        return str(self.parent) + '/' + self.name

now try to load it via syncdb

(while you are at it you could clarify in the documentation that python fixtures need to carry the extension .python

Change History (4)

comment:1 by anonymous, 18 years ago

Component: Core frameworkUnit test system

comment:2 by donlaverty, 18 years ago

sorry, i ignored the wiki syntax - my ticket is barely readable - so once more:

Reproduce:

Use this fixture:

[{"pk": "1", "model": "main.category", "fields": {"link_name": "all", "name": "\/", "parent": null, "description": ""}}, {"pk": "2", "model": "main.category", "fields": {"link_name": "accessoires", "name": "Accessoires", "parent": 1, "description": ""}}, {"pk": "3", "model": "main.category", "fields": {"link_name": "art_and_design", "name": "Art & Design", "parent": 1, "description": ""}}]

with this model:

class Category(models.Model):
    class Admin:
        pass

    class Meta:
        ordering =['name']

    name        = models.CharField(maxlength=50)
    link_name   = models.SlugField(unique=True)
    description = models.TextField(blank=True)
    parent      = models.ForeignKey('self',blank=True,null=True)

    
    def tree(self,tree=[]):
        tree.append( self )
        children = self.category_set.all()
        child_tree = []
        for c in children:
            if c.name != '/':
                c.tree(child_tree)
        if not child_tree == []:
            tree.append(child_tree)
        return tree

    def link(self):
        return str(self)[2:]

    def __str__(self):
        if not self.parent  :
            return self.name
        return str(self.parent) + '/' + self.name

now try to load it via syncdb

(while you are at it you could clarify in the documentation that python fixtures need to carry the extension .python

comment:3 by Simon G. <dev@…>, 18 years ago

Triage Stage: UnreviewedAccepted

comment:4 by Malcolm Tredinnick, 18 years ago

Description: modified (diff)
Note: See TracTickets for help on using tickets.
Back to Top