Ejemplo n.º 1
0
    def test_get_authors_update_exists(self):
        xml = etree.fromstring(xml_string_insert_new)
        authors = get_authors(xml)
        xml_string = '''
        <authors>
            <author>
                <name>Name</name>
                <alias>Alias</alias>
            </author>
            <author>
                <name>  
                </name>
            </author>
            <author>
                <name>Name2</name>
                <alias>Alias </alias>
            </author>
            <author>
                <name></name>
                <alias>Alias2</alias>
            </author>
            <author>
                <name>Name1 </name>
                <alias>Alias6</alias>
                <alias>Alias7</alias>
                <alias>Alias9</alias>
            </author>
        </authors>'''
        
        xml = etree.fromstring(xml_string)
        authors = get_authors(xml)

        author = Author.objects.get(name='Name')
        alias = AuthorAlias.objects.get(name='Alias')
        self.failUnlessEqual(author.alias.all()[0].id, alias.id)

        author = Author.objects.get(name='Name1')
        self.failUnlessEqual(author.alias.count(), 4)
        self.failUnlessEqual(author.alias.all()[3].name, 'Alias9')
Ejemplo n.º 2
0
    def test_get_authors_inser_new(self):
        xml = etree.fromstring(xml_string_insert_new)
        authors = (get_authors(xml))[0]
#        authors.order_by(id)

        author = authors[0]
        self.failUnlessEqual(author.name, 'Name')
        self.failUnlessEqual(author.alias.count(), 0)

        author = authors[1]
        self.failUnlessEqual(author.name, 'Name2')
        self.failUnlessEqual(author.alias.all()[0].name, 'Alias')
        self.failUnlessEqual(author.alias.count(), 1)

        author = authors[2]
        self.failUnlessEqual(author.name, 'Name1')
        self.failUnlessEqual(author.alias.all()[0].name, 'Alias6')
        self.failUnlessEqual(author.alias.all()[1].name, 'Alias7')
        self.failUnlessEqual(author.alias.all()[2].name, 'Alias8')
        self.failUnlessEqual(author.alias.count(), 3)