def setUp(self):
     self.carpool_request_application_service = \
         CarpoolRequestApplicationService()
     self.user = User(email="TEST", password="******")
     self.user.save()
     self.rider = Rider(user=self.user)
     self.rider.save()
Пример #2
0
class CarpoolRequestApplicationServiceTestCase(TestCase):

    def setUp(self):
        self.carpool_request_application_service = \
            CarpoolRequestApplicationService()
        self.user = User(email="TEST", password="******")
        self.user.save()
        self.rider = Rider(user=self.user)
        self.rider.save()

    def test_create(self):
        from_location = "TEST_FROM"
        to_location = "TEST_TO"
        minimum_passenger = "TEST_PASSENGER"
        rider_id = 1
        result = self.carpool_request_application_service.create(
            from_location, to_location, minimum_passenger, rider_id
        )
        self.assertEqual(result.from_location, from_location)
        self.assertEqual(result.to_location, to_location)
        self.assertEqual(result.minimum_passenger, minimum_passenger)
        self.assertEqual(result.rider_id, rider_id)

    # TODO: assert after delete
    def test_del(self):
        from_location = "TEST_FROM"
        to_location = "TEST_TO"
        minimum_passenger = "TEST_PASSENGER"
        rider_id = 1
        self.carpool_request_application_service.create(
            from_location, to_location, minimum_passenger, rider_id
        )
        request_id = 1
        result = self.carpool_request_application_service.delete(
            request_id
        )
        self.assertEqual(result[0], 1)

    # TODO: assert after get
    def test_get(self):
        from_location = "TEST_FROM"
        to_location = "TEST_TO"
        minimum_passenger = "TEST_PASSENGER"
        rider_id = 1
        self.carpool_request_application_service.create(
            from_location, to_location, minimum_passenger, rider_id
        )
        request_id = 1
        result = self.carpool_request_application_service.get(
            request_id=request_id
        )

        self.assertEqual(result.from_location, from_location)
        self.assertEqual(result.to_location, to_location)
        self.assertEqual(result.minimum_passenger, minimum_passenger)
        self.assertEqual(result.rider_id, rider_id)
    def setUp(self):
        self.FROM_LOCATION = 'SNU Station'
        self.TO_LOCATION = '301 Building'

        self.group_application_service = GroupApplicationService()
        self.group = Group(from_location=self.FROM_LOCATION,
                           to_location=self.TO_LOCATION)
        self.group.save()
        EMAIL = '*****@*****.**'
        PASSWORD = 1234

        user = User(email=EMAIL, password=PASSWORD)
        user.save()

        self.rider1 = Rider(user=user, group=self.group)
        self.rider2 = Rider(user=user, group=self.group)
        self.rider3 = Rider(user=user, group=self.group)
        self.rider4 = Rider(user=user, group=self.group)

        self.rider1.save()
        self.rider2.save()
        self.rider3.save()
        self.rider4.save()
class GroupApplicationServiceTestCase(TestCase):

    # TODO: set different user!
    def setUp(self):
        self.FROM_LOCATION = 'SNU Station'
        self.TO_LOCATION = '301 Building'

        self.group_application_service = GroupApplicationService()
        self.group = Group(from_location=self.FROM_LOCATION,
                           to_location=self.TO_LOCATION)
        self.group.save()
        EMAIL = '*****@*****.**'
        PASSWORD = 1234

        user = User(email=EMAIL, password=PASSWORD)
        user.save()

        self.rider1 = Rider(user=user, group=self.group)
        self.rider2 = Rider(user=user, group=self.group)
        self.rider3 = Rider(user=user, group=self.group)
        self.rider4 = Rider(user=user, group=self.group)

        self.rider1.save()
        self.rider2.save()
        self.rider3.save()
        self.rider4.save()

    def test_create_group(self):
        RIDER_ID_LIST = [
            self.rider1.id, self.rider2.id, self.rider3.id, self.rider4.id
        ]
        FROM_LOCATION = 'SNU Station'
        TO_LOCATION = '301 Building'

        result = self.group_application_service.create_group(
            rider_id_list=RIDER_ID_LIST,
            from_location=FROM_LOCATION,
            to_location=TO_LOCATION)

        self.assertEqual(result['from_location'], FROM_LOCATION)
        self.assertEqual(result['to_location'], TO_LOCATION)

    @patch.object(RedisMessagePublisher, 'publish_message')
    def test_driver_update_group(self, publish_message_fn):
        EMAIL = '*****@*****.**'
        PASSWORD = 1234

        user = User(email=EMAIL, password=PASSWORD)
        user.save()
        driver = Driver(user=user)
        driver.save()

        result = self.group_application_service.driver_update_group(
            group_id=self.group.id, driver_id=driver.id)

        self.assertEqual(result['id'], self.group.id)
        self.assertEqual(result['driver']['id'], driver.id)

        args, kwargs = publish_message_fn.call_args
        self.assertEqual(args[0].group_id, self.group.id)
        self.assertEqual(args[0].driver_id, driver.id)
        self.assertEqual(
            args[0].rider_id_list,
            [self.rider1.id, self.rider2.id, self.rider3.id, self.rider4.id])
        self.assertEqual(args[0].from_location, self.FROM_LOCATION)
        self.assertEqual(args[0].to_location, self.TO_LOCATION)

    @patch.object(RedisMessagePublisher, 'publish_message')
    def test_cost_update_group(self, publish_message_fn):
        #RIDER_ID_LIST = [1, 2, 3, 4]
        FROM_LOCATION = 'SNU Station'
        TO_LOCATION = '301 Building'
        COST = 5000
        RIDER_COST = math.ceil(COST / 4 / 100) * 100

        result = self.group_application_service.cost_update_group(
            group_id=self.group.id, cost=COST)

        self.assertEqual(result['id'], self.group.id)
        self.assertEqual(result['cost'], COST)

        #self.assertEqual(result['total_cost'], COST)
        #self.asserEqual(result['rider_cost'], RIDER_COST)

        args, kwargs = publish_message_fn.call_args
        self.assertEqual(args[0].group_id, self.group.id)
        self.assertEqual(args[0].total_cost, COST)
        self.assertEqual(
            args[0].rider_id_list,
            [self.rider1.id, self.rider2.id, self.rider3.id, self.rider4.id])
        self.assertEqual(args[0].rider_cost, RIDER_COST)