Example #1
0
 def test_get_toilet_by_user_not_exists(self):
     toilet = Toilet()
     toilet.name = "New toilet"
     toilet.date = datetime.datetime.now()
     toilet.creator = self.user
     toilet.save()
     second_toilet = Toilet()
     second_toilet.name = "Second Toilet"
     second_toilet.date = datetime.datetime.now()
     second_toilet.creator = self.user
     second_toilet.save()
     response = self.client.post('/api/Toilet/get/', { 'filters' : json.dumps({'creator' : 666}), 'start' : 0, 'end' : 10}) 
     response_list = json.loads(response.content)
     #this should probably be a 404 error 
     self.assertEqual(response_list, [])
Example #2
0
 def test_get_toilet_by_user(self): 
     toilet = Toilet()
     toilet.name = "New toilet"
     toilet.date = datetime.datetime.now()
     toilet.creator = self.user
     toilet.save()
     second_toilet = Toilet()
     second_toilet.name = "Second Toilet"
     second_toilet.date = datetime.datetime.now()
     second_toilet.creator = self.user
     second_toilet.save()
     response = self.client.post('/api/Toilet/get/', { 'filters' : json.dumps({'creator' : self.user.id}), 'start' : 0, 'end' : 10}) 
     response_list = json.loads(response.content)
     pk_list = [pk_elm for pk_elm in [ elm_list['pk']
                                     for elm_list in response_list]]
     self.assertEqual(len(pk_list), 2)
     self.assertIn(toilet.pk, pk_list)
     self.assertIn(second_toilet.pk, pk_list)
Example #3
0
 def test_get_toilet_by_id(self):
     toilet = Toilet()
     toilet.name = "test"
     toilet.date = datetime.datetime.now()
     toilet.lat = 1
     toilet.lng = 1
     toilet.creator = self.user
     toilet.save()
     response = self.client.post('/api/Toilet/get/', { 'filters' : json.dumps({'id' : toilet.pk }), 'start' : 0, 'end' : 10}) 
     responsedict = json.loads(response.content)
     self.assertEqual(responsedict[0]['pk'], toilet.pk, "incorrect toilet return from server")