コード例 #1
0
 def testCountPurchases(self):
     purchase = Purchase.countPurchases(dev_id=1)
     self.assertEqual(purchase[0]['sells'], 2,
                      'Getting the purchase number of a developer')
     # dev doesn't exist (return an empty queryset)
     purchase2 = Purchase.countPurchases(dev_id=2222)
     self.assertEqual(list(purchase2), [],
                      'Getting the purchase number of a developer')
     # invalid input
     purchase3 = Purchase.countPurchases(dev_id='panda')
     self.assertEqual(purchase3, None,
                      'Getting the purchase number of a developer')
コード例 #2
0
ファイル: views.py プロジェクト: shuangq/WSD-Project-2017
 def get(self, request):
     """
     Returns a list of sells for the user
     """
     if request.user.groups.get(name='devs'):
         dev_id = request.user.id
         sells = Purchase.countPurchases(dev_id)
         return Response(rest(list(sells)))
     else:
         message = 'Unauthorized request. What are you trying to do? Panda is not amused.'
         return Response({'message', message})