Beispiel #1
0
 def setUp(self):
     date = previous_month_date(False)
     make_phone_call(self.client, make_timestamp(hour=21, minute=57, second=13,
                                                 day=date.day, month=date.month, year=date.year))
     make_phone_call(self.client, make_timestamp(hour=22, minute=17, second=53,
                                                 day=date.day, month=date.month, year=date.year), type='end')
     self.view = PhoneBillingViewSet.as_view({'post': 'report'})
Beispiel #2
0
 def test_start_call_after_end_call(self):
     '''Well, something wrong happens! We have a start phone call that happened after the end! We ignore this in the phone bill.'''
     make_phone_call(self.client,
                     make_timestamp(hour=22, minute=57, second=13))
     make_phone_call(self.client,
                     make_timestamp(hour=20, minute=0, second=0),
                     type='end')
     self.assertFalse(Billing.objects.exists())
Beispiel #3
0
 def test_call_free_time_should_calculate_right(self):
     '''We have a call on the free time, let's check if it's calculating correctly'''
     make_phone_call(self.client,
                     make_timestamp(hour=21, minute=57, second=13))
     make_phone_call(self.client,
                     make_timestamp(hour=22, minute=17, second=53),
                     type='end')
     self.assertTrue(Billing.objects.exists())
     self.assertEqual(Decimal('0.54'), Billing.objects.get().price)
Beispiel #4
0
 def test_he_spent_all_night_long_connected(self):
     '''We have a call on the free time, let's check if it's calculating correctly'''
     make_phone_call(self.client,
                     make_timestamp(hour=21, minute=57, second=13, day=1))
     make_phone_call(self.client,
                     make_timestamp(hour=7, minute=17, second=53, day=2),
                     type='end')
     self.assertTrue(Billing.objects.exists())
     self.assertEqual(Decimal('7.56'), Billing.objects.get().price)
Beispiel #5
0
 def test_five_days_connected_with_payable_minutes(self):
     '''We have a very long connection (5 days), let's check if it's calculating correctly'''
     make_phone_call(self.client,
                     make_timestamp(hour=21, minute=57, second=13, day=1))
     make_phone_call(self.client,
                     make_timestamp(hour=7, minute=17, second=53, day=5),
                     type='end')
     self.assertTrue(Billing.objects.exists())
     self.assertEqual(Decimal('266.76'), Billing.objects.get().price)
Beispiel #6
0
 def test_call_full_free_time_should_calculate_right_limit_test(self):
     '''Start exactly at free time (22h) and finish exactly at free time (next day 6h)'''
     make_phone_call(self.client,
                     make_timestamp(hour=22, minute=0, second=0, day=1))
     make_phone_call(self.client,
                     make_timestamp(hour=6, minute=0, second=0, day=2),
                     type='end')
     self.assertTrue(Billing.objects.exists())
     self.assertEqual(Decimal('0.36'), Billing.objects.get().price)
Beispiel #7
0
 def test_call_just_one_hour_normal_time(self):
     '''We have a call with just one hour inside payable hours'''
     make_phone_call(self.client, make_timestamp(hour=9, minute=0,
                                                 second=0))
     make_phone_call(self.client,
                     make_timestamp(hour=10, minute=0, second=0),
                     type='end')
     self.assertTrue(Billing.objects.exists())
     self.assertEqual(Decimal('5.76'), Billing.objects.get().price)
Beispiel #8
0
 def test_usual_flow_save_bill(self):
     '''Phone call started and some minutes latter. Make sure that the billing is correct'''
     make_phone_call(self.client,
                     time_stamp=make_timestamp(hour=11),
                     type='start')
     make_phone_call(self.client,
                     time_stamp=make_timestamp(hour=12),
                     type='end')
     self.assertTrue(Billing.objects.exists())
Beispiel #9
0
 def test_only_free_minutes_call_charge_just_for_standing_charge(self):
     '''We have the full call inside free time'''
     make_phone_call(self.client,
                     make_timestamp(hour=23, minute=0, second=13, day=1))
     make_phone_call(self.client,
                     make_timestamp(hour=5, minute=1, second=0, day=2),
                     type='end')
     self.assertTrue(Billing.objects.exists())
     self.assertEqual(Decimal('0.36'), Billing.objects.get().price)
Beispiel #10
0
 def test_five_days_connected_connection_closed_before_free_time(self):
     '''We have a very long connection (5 days) and the connection was closed at 5'''
     make_phone_call(self.client,
                     make_timestamp(hour=21, minute=57, second=13, day=1))
     make_phone_call(self.client,
                     make_timestamp(hour=21, minute=0, second=0, day=5),
                     type='end')
     self.assertTrue(Billing.objects.exists())
     self.assertEqual(Decimal('340.74'), Billing.objects.get().price)
Beispiel #11
0
 def test_call_night_free_time_should_calculate_right_limit_test(self):
     '''Start exactly at free time (22h) one hour later, don't charge the minutes'''
     make_phone_call(self.client, make_timestamp(hour=22,
                                                 minute=0,
                                                 second=0))
     make_phone_call(self.client,
                     make_timestamp(hour=23, minute=0, second=0),
                     type='end')
     self.assertTrue(Billing.objects.exists())
     self.assertEqual(Decimal('0.36'), Billing.objects.get().price)
Beispiel #12
0
 def test_call_free_time_should_calculate_right_morning_time_some_minutes_remaining_limit_test(
         self):
     '''Let's check if it's calculating morning prices correctly with a fractionated minute'''
     make_phone_call(self.client, make_timestamp(hour=5, minute=0,
                                                 second=0))
     make_phone_call(self.client,
                     make_timestamp(hour=5, minute=59, second=26),
                     type='end')
     self.assertTrue(Billing.objects.exists())
     self.assertEqual(Decimal('0.36'), Billing.objects.get().price)
Beispiel #13
0
 def test_call_free_time_should_calculate_right_morning_time_limit_test(
         self):
     '''This is a trick situation for my algoritm. Let's check if it's calculating morning prices correctly'''
     make_phone_call(self.client, make_timestamp(hour=5, minute=0,
                                                 second=0))
     make_phone_call(self.client,
                     make_timestamp(hour=6, minute=0, second=0),
                     type='end')
     self.assertTrue(Billing.objects.exists())
     self.assertEqual(Decimal('0.36'), Billing.objects.get().price)
Beispiel #14
0
 def test_call_fractionated_minute_dont_pay_minute_just_call(self):
     '''We have a call with just one hour inside payable hours'''
     make_phone_call(self.client, make_timestamp(hour=9,
                                                 minute=0,
                                                 second=13))
     make_phone_call(self.client,
                     make_timestamp(hour=9, minute=1, second=0),
                     type='end')
     self.assertTrue(Billing.objects.exists())
     self.assertEqual(Decimal('0.36'), Billing.objects.get().price)
Beispiel #15
0
 def test_double_end_call(self):
     '''Phone call started and some minutes latter. Make sure that the billing is correct'''
     make_phone_call(self.client,
                     time_stamp=make_timestamp(hour=11),
                     type='start')
     make_phone_call(self.client,
                     time_stamp=make_timestamp(hour=12),
                     type='end')
     self.assertEqual(
         status.HTTP_400_BAD_REQUEST,
         make_phone_call(self.client,
                         time_stamp=make_timestamp(hour=12),
                         type='end').status_code)
     self.assertTrue(Billing.objects.exists())
Beispiel #16
0
    def test_existent_subscriber_period_not_informed(self):
        make_phone_call(self.client, make_timestamp(hour=21, minute=57, second=13, year=2017), call_id=71)
        make_phone_call(self.client, make_timestamp(hour=22, minute=17, second=53, year=2017), call_id=71, type='end')

        request = APIRequestFactory().post('', data={'subscriber': '5512345678'})
        response = self.view(request)

        self.assertEqual(status.HTTP_200_OK, response.status_code)
        self.assertEqual(1, len(response.data))
        self.assertDictEqual({
            "id": 1,
            "subscriber": "5512345678",
            "time_stamp": {"start_time": "21:57:13", "start_date": previous_month_date()},
            "duration": "00h20m40s",
            "price": "R$ 0.54"
        }, dict(response.data[0]))
Beispiel #17
0
 def test_invalid_type(self):
     '''Phone call started and some minutes latter. Make sure that the billing is correct'''
     self.assertEqual(
         status.HTTP_400_BAD_REQUEST,
         make_phone_call(self.client,
                         time_stamp=make_timestamp(hour=11),
                         type='invalid.type').status_code)
Beispiel #18
0
 def test_only_end_call_entry__dont_save_bill(self):
     '''We received only end phone call entry. So we don't save anything in the billing yet'''
     make_phone_call(self.client, make_timestamp(hour=12), type='end')
     self.assertFalse(Billing.objects.exists())