def test_get_bill_24h13min_call(client, db): Call.create( id=1, source='99988526423', destination='9933468278', start_timestamp=datetime(2018, 2, 28, 21, 57, 13), end_timestamp=datetime(2018, 3, 1, 22, 10, 56), ) resp = client.get('/api/v1/calls/99988526423/2018/3') data = resp.json assert len(data['calls']) == 1 assert data['calls'][0] == { 'call_start_date': '2018-02-28', 'call_start_time': '21:57:13', 'destination': '9933468278', 'duration': '24h13min43s', 'price': 86.94 }
def populate_calls(db): now = datetime.now() now_01 = datetime(now.year, now.month, 1) prev_month = previous_month(now) prev_prev_month = previous_month(prev_month) id = 0 # ---- Ligações do mês - 2 id += 1 date = prev_prev_month + timedelta(days=3, hours=5, minutes=50) Call.create( id=id, source='10987654321', destination='1122334455', start_timestamp=date, end_timestamp=date + timedelta(minutes=20, seconds=15), ) id += 1 date = prev_prev_month + timedelta( days=15, hours=12, minutes=30, seconds=30) Call.create( id=id, source='12345678901', destination='87654321', start_timestamp=date, end_timestamp=date + timedelta(minutes=20, seconds=15), ) id += 1 date = prev_prev_month + timedelta( days=16, hours=13, minutes=30, seconds=30) Call.create( id=id, source='23456789012', destination='3344556677', start_timestamp=date, end_timestamp=date + timedelta(minutes=20, seconds=15), ) # ---- Ligações do mês - 1 id += 1 date = prev_month - timedelta(minutes=30, seconds=30) Call.create( id=id, source='12345678901', destination='2233445566', start_timestamp=date, end_timestamp=date + timedelta(minutes=45, seconds=15), ) id += 1 date = prev_month + timedelta(days=15, hours=5, minutes=50) Call.create( id=id, source='12345678901', destination='2233445566', start_timestamp=date, end_timestamp=date + timedelta(minutes=20, seconds=15), ) id += 1 date = prev_month + timedelta(days=1, hours=12, minutes=30, seconds=30) Call.create( id=id, source='12345678901', destination='7890123456', start_timestamp=date, end_timestamp=date + timedelta(minutes=30, seconds=15), ) id += 1 date = prev_month + timedelta(days=16, hours=13, minutes=30, seconds=30) Call.create( id=id, source='23456789012', destination='3344556677', start_timestamp=date, end_timestamp=date + timedelta(minutes=20, seconds=15), ) # ---- Ligações do mês id += 1 date = now_01 - timedelta(minutes=30, seconds=30) Call.create( id=id, source='12345678901', destination='4455667788', start_timestamp=date, end_timestamp=date + timedelta(minutes=40, seconds=25), ) id += 1 date = now_01 + timedelta(hours=5, minutes=50) Call.create( id=id, source='33445566778', destination='7890123456', start_timestamp=date, end_timestamp=date + timedelta(minutes=25, seconds=15), ) id += 1 date = now_01 + timedelta(days=15, hours=12, minutes=30, seconds=30) Call.create( id=id, source='12345678901', destination='7890123456', start_timestamp=date, end_timestamp=date + timedelta(minutes=31, seconds=15), ) id += 1 date = now_01 + timedelta(days=16, hours=13, minutes=30, seconds=30) Call.create( id=id, source='23456789012', destination='3344556677', start_timestamp=date, end_timestamp=date + timedelta(minutes=22, seconds=29), )