On 25/08/11 11:34, Torsten wrote:
Hi

How do I do that right ?

I have a class like:

class Invoice
...
def __unicode__(self):
         return unicode(str(self.created_at.year)+'/'+str(self.id))

and an test here:


def test_invoice_number(self):
         invoice = Invoice.objects.create(created_at="2011-07-28",
customer_id=1, payable_at='2012-12-12')
         invoice.save()
         self.assertEqual("Invoice: 2011/1", invoice)


with the follwoing result:

File "/Users/torsten/PycharmProjects/invoiz/invoice/tests.py", line
22, in test_invoice_number
    self.assertEqual("2011/1", invoice)
AssertionError: '2011/1' !=<Invoice: 2011/1>


Thanks for help

Torsten

You want to compare the unicode string for the object, so use the unicode function. The following should work:

self.assertEqual("Invoice: 2011/1", unicode(invoice))


Regards,
Alasdair

--
Alasdair Nicol
Developer, MEMSET

mail: alasd...@memset.com
 web: http://www.memset.com/

Memset Ltd., registration number 4504980. 25 Frederick Sanger Road, Guildford, 
Surrey, GU2 7YD, UK.

--
You received this message because you are subscribed to the Google Groups "Django 
users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.

Reply via email to