示例#1
0
    def test_calculate_price_on_reduced_hours_max_edge(self):
        start_timestamp = pendulum.datetime(2018, 1, 1, 5, 59)
        end_timestamp = pendulum.datetime(2018, 1, 1, 6)

        CallRecordStartFactory.create(timestamp=start_timestamp)
        CallRecordEndFactory.create(timestamp=end_timestamp)

        bill = Bill.objects.first()

        self.assertEqual(bill.price, Decimal('0.45'))
示例#2
0
    def test_calculate_price_on_fractioned_time_without_complete_cycle(self):
        start_timestamp = pendulum.datetime(2018, 1, 1, 8, 33, 1)
        end_timestamp = pendulum.datetime(2018, 1, 1, 8, 33, 58)

        CallRecordStartFactory.create(timestamp=start_timestamp)
        CallRecordEndFactory.create(timestamp=end_timestamp)

        bill = Bill.objects.first()

        self.assertEqual(bill.price, Decimal('0.0'))
示例#3
0
    def test_calculate_price_on_standard_hours_and_reduced_hours(self):
        start_timestamp = pendulum.datetime(2018, 1, 1, 0)
        end_timestamp = pendulum.datetime(2018, 1, 2, 0)

        CallRecordStartFactory.create(timestamp=start_timestamp)
        CallRecordEndFactory.create(timestamp=end_timestamp)

        bill = Bill.objects.first()

        self.assertEqual(bill.price, Decimal('86.76'))
示例#4
0
    def test_calculate_price_without_duration(self):
        start_timestamp = pendulum.datetime(2018, 1, 1)
        end_timestamp = pendulum.datetime(2018, 1, 1)

        CallRecordStartFactory.create(timestamp=start_timestamp)
        CallRecordEndFactory.create(timestamp=end_timestamp)

        bill = Bill.objects.first()

        self.assertEqual(bill.price, Decimal('0.0'))
    def test_create_start_record_call_id_duplicated(self):
        CallRecordStartFactory.create(call_id=1)

        response = self.client.post(
            '/call-record/', {
                'call_id': 1,
                'type': CallRecord.START_RECORD,
                'timestamp': '2016-02-29T12:00:00Z',
                'source': '99988526423',
                'destination': '9933468278'
            })

        self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
        self.assertDictEqual(
            response.json(), {
                'non_field_errors':
                ['The fields type, call_id must make a unique set.']
            })
    def test_create_end_record_timestamp_less_than_start_record(self):
        timestamp = dateparse.parse_datetime('2016-02-29T12:00:01Z')
        CallRecordStartFactory.create(timestamp=timestamp)

        response = self.client.post(
            '/call-record/', {
                'call_id': 1,
                'type': CallRecord.END_RECORD,
                'timestamp': '2016-02-29T12:00:00Z'
            })

        self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
        self.assertDictEqual(
            response.json(), {
                'timestamp': [
                    'Ensure this field is greater than the start record timestamp'
                ],
            })
    def test_create_end_record_with_already_start_record_created(self):
        CallRecordStartFactory.create(
            call_id=1,
            timestamp=dateparse.parse_datetime('2016-02-29T12:00:00Z'))

        response = self.client.post(
            '/call-record/', {
                'call_id': 1,
                'type': CallRecord.END_RECORD,
                'timestamp': '2016-02-29T14:00:00Z'
            })

        self.assertEqual(response.status_code, status.HTTP_201_CREATED)
        self.assertDictEqual(
            response.json(), {
                'id': 2,
                'type': 1,
                'timestamp': '2016-02-29T14:00:00Z',
                'call_id': '1'
            })
示例#8
0
    def test_post_save_create_bill_on_end_pair_founded(self):
        start_record = CallRecordStartFactory.create()
        end_record = CallRecordEndFactory.create()

        self.assertTrue(Bill.objects.filter(start_record=start_record, end_record=end_record).exists())
示例#9
0
    def test_post_save_does_not_create_bill_without_end_pair(self):
        CallRecordStartFactory.create()

        self.assertEqual(Bill.objects.count(), 0)