コード例 #1
0
	def create_scheduled_item(self, feeder, receiver):
		scheduledItem = ScheduledItem(
			feeder=feeder,
			receiver=receiver,
			start=self.timezone.localize(datetime(1970, 1, 1, 0, 0, 0)),
			end=self.timezone.localize(datetime(1970, 1, 1, 0, 30, 0)))
		scheduledItem.save()
		return scheduledItem
コード例 #2
0
	def test_scheduled_item_slot_available_fail_slot_end_greater_than_item_start_function(self):
		self.create_client_feeder_receiver()
		start = self.timezone.localize(datetime(1970, 1, 1, 0, 0, 0))
		end = self.timezone.localize(datetime(1970, 1, 1, 0, 30, 0))
		ScheduledItem.objects.create(feeder=self.feeder, receiver=self.receiver, start=start, end=end)
		start_req = self.timezone.localize(datetime(1969, 12, 31, 23, 59, 59))
		end_req = self.timezone.localize(datetime(1970, 1, 1, 0, 0, 1))
		slot_request = ScheduledItem(feeder=self.feeder, receiver=self.receiver, start=start_req, end=end_req)
		self.assertFalse(slot_request.slot_available())
コード例 #3
0
	def test_scheduled_item_slot_available_pass_slot_in_future_function(self):
		self.create_client_feeder_receiver()
		start = self.timezone.localize(datetime(1970, 1, 1, 0, 0, 0))
		end = self.timezone.localize(datetime(1970, 1, 1, 0, 30, 0))
		ScheduledItem.objects.create(feeder=self.feeder, receiver=self.receiver, start=start, end=end)
		start_req = self.timezone.localize(datetime(1970, 1, 1, 0, 40, 0))
		end_req = self.timezone.localize(datetime(1970, 1, 1, 0, 50, 0))
		slot_request = ScheduledItem(feeder=self.feeder, receiver=self.receiver, start=start_req, end=end_req)
		self.assertTrue(slot_request.slot_available())
コード例 #4
0
def api_scheduled_item_add(request, feeder_id, receiver_id):

    if request.method == 'POST' and request.user.is_authenticated:

        timezone = pytz.timezone(settings.TIME_ZONE)

        try:
            post_data = json.loads(request.body.decode('utf-8'))
        except ValueError as error:
            return JsonResponse({
                'status': 400,
                'data': 'data not in json format'
            })

        if set(['start', 'end']).issubset(post_data) == False:
            return default400(request)

        receiver = Receiver.objects.get(id=receiver_id)

        if request.user.id != receiver.client.id:
            return JsonResponse({
                'status':
                400,
                'data':
                'you are not the client for this receiver'
            })

        feeder = Feeder.objects.get(id=feeder_id)

        try:
            start = timezone.localize(
                datetime.strptime(post_data['start'], '%Y/%m/%d %H:%M:%S'))
            end = timezone.localize(
                datetime.strptime(post_data['end'], '%Y/%m/%d %H:%M:%S'))
        except ValueError as error:
            return JsonResponse({'status': 400, 'data': str(error)})

        scheduledItem = ScheduledItem(feeder=feeder,
                                      receiver=receiver,
                                      start=start,
                                      end=end)

        if scheduledItem.save() == False:
            return JsonResponse({'status': 400, 'data': 'slot unavailable'})

        return default201(request)

    return default404(request)
コード例 #5
0
	def test_scheduled_item_sensible_range_pass_function(self):
		self.create_client_feeder_receiver()
		start = self.timezone.localize(datetime(1970, 1, 1, 0, 0, 0))
		end = self.timezone.localize(datetime(1970, 1, 1, 0, 30, 0))
		scheduledItem = ScheduledItem(feeder=self.feeder, receiver=self.receiver, start=start, end=end)
		self.assertTrue(scheduledItem.sensible_range())
コード例 #6
0
	def test_scheduled_item_sensible_range_fail_no_end_function(self):
		self.create_client_feeder_receiver()
		start = self.timezone.localize(datetime(1970, 1, 1, 0, 0, 0))
		scheduledItem = ScheduledItem(feeder=self.feeder, receiver=self.receiver,start=start)
		self.assertFalse(scheduledItem.sensible_range())
コード例 #7
0
	def test_scheduled_item_sensible_range_fail_no_start_or_end_function(self):
		self.create_client_feeder_receiver()
		scheduledItem = ScheduledItem(feeder=self.feeder, receiver=self.receiver)
		self.assertFalse(scheduledItem.sensible_range())