Пример #1
0
	def test_rescue_camp_string_representation(self):
		rescueCamp = RescueCamp(
			name="Kerala Flood Relief camp",
			location="Kottayam",
			district="ktm",
			contacts="Phone numbers: 123456789")
		self.assertEqual(str(rescueCamp), rescueCamp.name)
Пример #2
0
def relief_camps_data(request):
    try:
        offset = int(request.GET.get('offset'))
    except:
        offset = 0
    if RescueCamp.objects.exists():
        last_record = RescueCamp.objects.latest('id')
    else:
        last_record = RescueCamp(id=0)
    relief_camp_data = (RescueCamp.objects.filter(
        id__gt=offset).order_by('id')[:300]).values()
    description = 'select * from mainapp_rescuecamp where id > offset order by id limit 300'
    response = {
        'data': list(relief_camp_data),
        'meta': {
            'offset': offset,
            'limit': 300,
            'description': description,
            'last_record_id': last_record.id
        }
    }
    return JsonResponse(response, safe=False)
Пример #3
0
def relief_camps_data(request):
    try:
        offset = int(request.GET.get("offset"))
    except TypeError:
        offset = 0
    if RescueCamp.objects.exists():
        last_record = RescueCamp.objects.latest("id")
    else:
        last_record = RescueCamp(id=0)
    relief_camp_data = (RescueCamp.objects.filter(
        id__gt=offset).order_by("id")[:300]).values()
    description = "select * from mainapp_rescuecamp where id > offset order by id limit 300"
    response = {
        "data": list(relief_camp_data),
        "meta": {
            "offset": offset,
            "limit": 300,
            "description": description,
            "last_record_id": last_record.id,
        },
    }
    return JsonResponse(response, safe=False)
Пример #4
0
 def test_limit_query(self):
     client = Client()
     bulk_entries = []
     for i in range(400):
         bulk_entries.append(
             RescueCamp(
                 **{
                     'name': 'maloor lp school' + str(i),
                     'district': 'tcr',
                     'taluk': 'chalakudy' + str(i),
                     'village': 'maloor' + str(i),
                 }))
     _ = RescueCamp.objects.bulk_create(bulk_entries)
     response = client.get(self.url, {'offset': 110})
     self.assertEqual(response.status_code, 200)
     self.assertEqual(len(response.json()['data']), 300)
     self.assertEqual(response.json()['meta']['offset'], 110)
     self.assertEqual(response.json()['meta']['limit'], 300)
     self.assertEqual(
         response.json()['meta']['description'],
         'select * from mainapp_rescuecamp where id > offset order by id limit 300'
     )
     self.assertEqual(response.json()['meta']['last_record_id'], 500)
Пример #5
0
 def test_limit_query(self):
     client = Client()
     bulk_entries = []
     for i in range(400):
         bulk_entries.append(
             RescueCamp(
                 **{
                     "name": "maloor lp school" + str(i),
                     "district": "tcr",
                     "taluk": "chalakudy" + str(i),
                     "village": "maloor" + str(i),
                 }))
     _ = RescueCamp.objects.bulk_create(bulk_entries)
     response = client.get(self.url, {"offset": 110})
     self.assertEqual(response.status_code, 200)
     self.assertEqual(len(response.json()["data"]), 300)
     self.assertEqual(response.json()["meta"]["offset"], 110)
     self.assertEqual(response.json()["meta"]["limit"], 300)
     self.assertEqual(
         response.json()["meta"]["description"],
         "select * from mainapp_rescuecamp where id > offset order by id limit 300",
     )
     self.assertEqual(response.json()["meta"]["last_record_id"], 500)