Esempio n. 1
0
    def test_list_filter_by_city_to(self):
        self.authenticate()
        now = timezone.now()
        tomorrow = now + timedelta(days=1)

        car = CarFactory.create(owner=self.user)
        ride1 = RideFactory.create(city_from=self.city1,
                                   city_to=self.city2,
                                   car=car,
                                   date_time=tomorrow)

        ride2 = RideFactory.create(car=car,
                                   date_time=tomorrow,
                                   stops_cities=[self.city2])

        ride3 = RideFactory.create(car=car, date_time=tomorrow)

        resp = self.client.get('/rides/ride/', {'city_to': self.city1.pk},
                               format='json')
        self.assertSuccessResponse(resp)
        self.assertEqual(len(resp.data), 0)

        resp = self.client.get('/rides/ride/', {'city_to': self.city2.pk},
                               format='json')
        self.assertSuccessResponse(resp)
        self.assertEqual(len(resp.data), 2)
        self.assertSetEqual({ride1.pk, ride2.pk},
                            set([ride['pk'] for ride in resp.data]))
Esempio n. 2
0
    def test_delete_car_with_rides(self):
        self.authenticate()
        RideFactory.create(car=self.car)

        resp = self.client.delete('/rides/car/{0}/'.format(self.car.pk))
        self.assertForbidden(resp)
        self.car.refresh_from_db()
        self.assertFalse(self.car.is_deleted)
Esempio n. 3
0
    def test_cancel_ride_by_driver(self, mock_ride_booking_refund):
        self.authenticate()
        ride = RideFactory.create(car=self.car)
        booking = RideBookingFactory.create(ride=ride, client=self.user)
        payed_booking = RideBookingFactory.create(
            ride=ride, client=self.user, status=RideBookingStatus.PAYED)
        canceled_booking = RideBookingFactory.create(
            ride=ride, client=self.user, status=RideBookingStatus.CANCELED)
        reason_text = 'test reason'

        self.assertEqual(ride.status, RideStatus.CREATED)
        resp = self.client.post('/rides/ride/{0}/cancel/'.format(ride.pk),
                                {'cancel_reason': reason_text})

        self.assertSuccessResponse(resp)
        self.assertEqual(mock_ride_booking_refund.call_count, 1)
        mock_ride_booking_refund.assert_called_with(payed_booking)

        booking.refresh_from_db()
        payed_booking.refresh_from_db()
        canceled_booking.refresh_from_db()
        ride.refresh_from_db()

        self.assertEqual(booking.status, RideBookingStatus.REVOKED)
        self.assertEqual(payed_booking.status, RideBookingStatus.REVOKED)
        self.assertEqual(canceled_booking.status, RideBookingStatus.CANCELED)
        self.assertEqual(ride.status, RideStatus.CANCELED)
        self.assertEqual(ride.cancel_reason, reason_text)
Esempio n. 4
0
    def test_my(self):
        self.authenticate()

        car = CarFactory.create(owner=self.user)

        my_ride_1 = RideFactory.create(number_of_seats=5, car=car)
        my_ride_2 = RideFactory.create(number_of_seats=5, car=car)

        another_user = UserFactory.create()
        another_car = CarFactory.create(owner=another_user)
        RideFactory.create(number_of_seats=5, car=another_car)

        resp = self.client.get('/rides/ride/my/', format='json')
        self.assertSuccessResponse(resp)
        self.assertSetEqual({my_ride_1.pk, my_ride_2.pk},
                            set([ride['pk'] for ride in resp.data]))
Esempio n. 5
0
    def setUp(self):
        super(TasksTest, self).setUp()
        now = timezone.now()
        previous_datetime = now - timedelta(days=2)

        self.ride1 = RideFactory.create(date_time=previous_datetime)
        self.booking1 = RideBookingFactory.create(
            ride=self.ride1, status=RideBookingStatus.PAYED)
        self.booking2 = RideBookingFactory.create(ride=self.ride1)
Esempio n. 6
0
    def test_get_ride_requests(self):
        now = timezone.now()
        tomorrow = now + timedelta(days=1)
        yesterday = now - timedelta(days=1)
        ride1 = RideFactory.create(car=self.car,
                                   city_from=self.city1,
                                   city_to=self.city2,
                                   date_time=tomorrow)
        ride2 = RideFactory.create(car=self.car,
                                   city_from=self.city2,
                                   city_to=self.city3,
                                   date_time=tomorrow)
        ride3 = RideFactory.create(car=self.car,
                                   city_from=self.city1,
                                   city_to=self.city3,
                                   stops_cities=[self.city4],
                                   date_time=tomorrow)
        request1 = RideRequestFactory.create(author=self.user,
                                             city_from=self.city1,
                                             city_to=self.city2,
                                             date_time=tomorrow)
        request2 = RideRequestFactory.create(author=self.user,
                                             city_from=self.city1,
                                             city_to=self.city4,
                                             date_time=tomorrow)
        request3 = RideRequestFactory.create(author=self.user,
                                             city_from=self.city1,
                                             city_to=self.city3,
                                             date_time=tomorrow)
        RideRequestFactory.create(author=self.user,
                                  city_from=self.city1,
                                  city_to=self.city2,
                                  date_time=yesterday)

        self.assertEqual(len(ride1.get_ride_requests()), 1)
        self.assertEqual(len(ride2.get_ride_requests()), 0)
        self.assertEqual(len(ride3.get_ride_requests()), 2)

        self.assertEqual(
            set(ride1.get_ride_requests().values_list('pk', flat=True)),
            {request1.pk})
        self.assertEqual(
            set(ride3.get_ride_requests().values_list('pk', flat=True)),
            {request2.pk, request3.pk})
Esempio n. 7
0
    def setUp(self):
        super(RideBookingViewSetTest, self).setUp()
        self.city1 = CityFactory.create()
        self.city2 = CityFactory.create()

        self.car = CarFactory.create(owner=self.user)

        self.ride = RideFactory.create(car=self.car)
        self.booking = RideBookingFactory.create(ride=self.ride,
                                                 client=self.user)
Esempio n. 8
0
    def test_request_driver_phone_by_driver_for_not_actual_failed(self):
        self.authenticate()
        ride = RideFactory.create(car=self.car, status=RideStatus.COMPLETED)
        RideBookingFactory.create(ride=ride,
                                  client=self.user,
                                  status=RideBookingStatus.PAYED)

        resp = self.client.post('/rides/ride/{0}/request_driver_phone/'.format(
            ride.pk))
        self.assertForbidden(resp)
Esempio n. 9
0
    def test_request_passenger_phone_by_driver_for_not_actual_failed(self):
        self.authenticate()
        ride = RideFactory.create(car=self.car, status=RideStatus.COMPLETED)
        client = UserFactory.create()
        booking = RideBookingFactory.create(ride=ride,
                                            client=client,
                                            status=RideBookingStatus.CREATED)

        resp = self.client.post(
            '/rides/booking/{0}/request_passenger_phone/'.format(booking.pk))
        self.assertForbidden(resp)
Esempio n. 10
0
    def test_list(self):
        self.authenticate()

        car = CarFactory.create(owner=self.user)
        now = timezone.now()
        tomorrow = now + timedelta(days=1)
        yesterday = now - timedelta(days=1)

        ride1 = RideFactory.create(number_of_seats=5,
                                   car=car,
                                   date_time=yesterday)

        ride2 = RideFactory.create(number_of_seats=5,
                                   car=car,
                                   date_time=tomorrow)

        resp = self.client.get('/rides/ride/', format='json')
        self.assertSuccessResponse(resp)

        self.assertEqual(len(resp.data), 1)
        self.assertEqual(resp.data[0]['pk'], ride2.pk)
Esempio n. 11
0
    def test_request_passenger_phone_by_not_driver_failed(self):
        self.authenticate()

        another_car = CarFactory.create()
        ride = RideFactory.create(car=another_car)
        booking = RideBookingFactory.create(ride=ride,
                                            client=self.user,
                                            status=RideBookingStatus.CREATED)

        resp = self.client.post(
            '/rides/booking/{0}/request_passenger_phone/'.format(booking.pk))
        self.assertForbidden(resp)
Esempio n. 12
0
    def handle(self, *args, **options):

        user1 = UserFactory.create(email='*****@*****.**')
        user2 = UserFactory.create(email='*****@*****.**')
        user3 = UserFactory.create(email='*****@*****.**')

        car = CarFactory.create(owner=user1)

        ride = RideFactory.create(car=car, number_of_seats=4, price=100)

        RideBookingFactory.create(ride=ride, client=user2, seats_count=2)
        RideBookingFactory.create(ride=ride, client=user3)
Esempio n. 13
0
    def test_ride_complaints_create(self):
        ride = RideFactory.create(car=self.car)
        RideBookingFactory.create(ride=ride, client=self.user)

        descr_text = 'Test text'
        complaint = RideComplaintFactory.create(ride=ride,
                                                user=self.user,
                                                description=descr_text)

        self.assertEqual(complaint.user, self.user)
        self.assertEqual(complaint.description, descr_text)
        self.assertEqual(complaint.status, RideComplaintStatus.NEW)
Esempio n. 14
0
    def test_cancel_payed_booking_not_in_cancelable_period_by_passenger(self):
        self.authenticate()
        ride = RideFactory.create(car=self.car,
                                  date_time=timezone.now() +
                                  timedelta(hours=1))
        payed_booking = RideBookingFactory.create(
            ride=ride, client=self.user, status=RideBookingStatus.PAYED)
        cancel_reason = 'test reason'

        resp = self.client.post(
            '/rides/booking/{0}/cancel/'.format(payed_booking.pk),
            {'cancel_reason': cancel_reason})
        self.assertForbidden(resp)
Esempio n. 15
0
    def test_request_driver_phone_by_driver_success(
            self, mock_create_proxy_phone_within_ride):
        mock_create_proxy_phone_within_ride.return_value = '+10000000000'

        self.authenticate()
        ride = RideFactory.create(car=self.car)
        RideBookingFactory.create(ride=ride,
                                  client=self.user,
                                  status=RideBookingStatus.PAYED)

        resp = self.client.post('/rides/ride/{0}/request_driver_phone/'.format(
            ride.pk))
        self.assertSuccessResponse(resp)
        self.assertEqual(resp.data['proxy_phone'], '+10000000000')
Esempio n. 16
0
    def test_list_ride(self):
        self._create_reviews()
        self.authenticate()
        new_car = CarFactory.create(owner=UserFactory.create())
        new_ride = RideFactory.create(car=new_car)

        resp = self.client.get('/reviews/?ride={0}'.format(new_ride.pk))
        self.assertSuccessResponse(resp)
        self.assertEqual(len(resp.data), 0)

        resp = self.client.get('/reviews/?ride={0}'.format(self.ride.pk))
        self.assertSuccessResponse(resp)
        self.assertEqual(len(resp.data), 4)
        self.assertSetEqual(set([item['pk'] for item in resp.data]), {
            self.review1.pk, self.review2.pk, self.review3.pk, self.review4.pk
        })
        self.assertEqual(self.user.get_rating()['value'], 3.5)
Esempio n. 17
0
    def test_cancel_payed_booking_in_cancelable_period_by_passenger(
            self, mock_ride_booking_refund):
        self.authenticate()
        ride = RideFactory.create(car=self.car,
                                  date_time=timezone.now() +
                                  timedelta(hours=25))
        payed_booking = RideBookingFactory.create(
            ride=ride, client=self.user, status=RideBookingStatus.PAYED)
        cancel_reason = 'test reason'

        resp = self.client.post(
            '/rides/booking/{0}/cancel/'.format(payed_booking.pk),
            {'cancel_reason': cancel_reason})
        self.assertSuccessResponse(resp)
        self.assertEqual(mock_ride_booking_refund.call_count, 1)
        mock_ride_booking_refund.assert_called_with(payed_booking)

        payed_booking.refresh_from_db()
        self.assertEqual(payed_booking.status, RideBookingStatus.CANCELED)
        self.assertEqual(payed_booking.cancel_reason, cancel_reason)
Esempio n. 18
0
 def setUp(self):
     super(ReviewViewSetTest, self).setUp()
     self.city1 = CityFactory.create()
     self.city2 = CityFactory.create()
     self.car = CarFactory.create(owner=self.user,
                                  brand='some',
                                  model='car',
                                  number_of_seats=5)
     self.ride = RideFactory.create(date_time=timezone.now() -
                                    datetime.timedelta(hours=1),
                                    car=self.car,
                                    city_from=self.city1,
                                    city_to=self.city2,
                                    status=RideStatus.COMPLETED)
     self.passenger1 = UserFactory.create(email='*****@*****.**',
                                          password='******')
     self.passenger2 = UserFactory.create(email='*****@*****.**',
                                          password='******')
     RideBookingFactory.create(ride=self.ride,
                               client=self.passenger1,
                               status=RideBookingStatus.PAYED)
     RideBookingFactory.create(ride=self.ride,
                               client=self.passenger2,
                               status=RideBookingStatus.PAYED)