How do I test Django QuerySets are equal?

前端 未结 6 750
挽巷
挽巷 2020-12-17 07:40

I am trying to test my Django views. This view passes a QuerySet to the template:

def merchant_home(request, slug):
  merchant = Merchant.objects.get(slug=sl         


        
6条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-17 08:15

    I just had the same problem. The second argument of assertQuerysetEqual needs to be a list of the expected repr()s as strings. Here is an example from the Django test suite:

    self.assertQuerysetEqual(c1.tags.all(), ["", ""], ordered=False)
    

提交回复
热议问题