Esempio n. 1
0
class EndRouteTest(TestCase):
    """ test for end route url """

    def setUp(self):
        """ this method will automatically call for every single test """

        self.userId = "067e6162-3b6f-4ae2-a171-2470b63dff00"

        self.helper = TestHelper(self)

        self.service = "507"
        self.licencePlate = "PABJ45"

        self.helper.insertServicesOnDatabase([self.service])

    def test_endRouteWithValidActiveToken(self):
        """ finish active travel """

        travelKey = self.helper.getInBusWithLicencePlate(self.userId, self.service, Constants.DUMMY_LICENSE_PLATE)
        self.helper.sendFakeTrajectoryOfToken(travelKey)

        jsonResponse = self.helper.endRoute(travelKey)

        self.assertEqual(jsonResponse["response"], "Trip ended.")

    def test_endRouteWithInvalidActiveToken(self):
        """ finish unactive travel """

        travelKey = self.helper.getInBusWithLicencePlate(self.userId, self.service, Constants.DUMMY_LICENSE_PLATE)
        self.helper.sendFakeTrajectoryOfToken(travelKey)

        self.helper.endRoute(travelKey)

        jsonResponse = self.helper.endRoute(travelKey)

        self.assertEqual(jsonResponse["response"], "Token doesn't exist.")
Esempio n. 2
0
class DevicePositionInTimeTest(TransactionTestCase):
    """ test for DevicePositionInTime model """

    def setUp(self):
        """ this method will automatically call for every single test """
        # for testing requests inside the project
        self.factory = RequestFactory()

        self.userId = "067e6162-3b6f-4ae2-a171-2470b63dff00"

        # inital config for DevicePositionInTime
        self.time = timezone.now()
        DevicePositionInTime.objects.create(
            userId=self.userId,
            longitud=3.5,
            latitud=5.2,
            timeStamp=self.time)
        DevicePositionInTime.objects.create(
            userId=self.userId,
            longitud=3.4,
            latitud=5.2,
            timeStamp=self.time)
        # this should not be answered
        DevicePositionInTime.objects.create(userId=self.userId, longitud=3.3, latitud=4.2, timeStamp=self.time
                                            - timezone.timedelta(minutes=11))

        # initial config for ActiveToken

        self.test = TestHelper(self)

        self.test.insertEventsOnDatabase()

        # add dummy  bus
        Bus.objects.create(
            registrationPlate='AA1111',
            service='507',
            uuid='159fc6b7-7a20-477e-b5c7-af421e1e0e16')
        # add dummy bus stop
        busStop = BusStop.objects.create(
            code='PA459', name='bla', longitud=0, latitud=0)

        # add dummy service and its path
        # '#00a0f0'color_id = models.IntegerField(default = 0)
        Service.objects.create(
            service='507',
            origin='origin_test',
            destiny='destination_test')
        ServiceStopDistance.objects.create(
            busStop=busStop, service='507I', distance=5)
        ServiceLocation.objects.create(
            service='507I', distance=1, longitud=4, latitud=5)
        ServiceLocation.objects.create(
            service='507I', distance=2, longitud=5, latitud=5)
        ServiceLocation.objects.create(
            service='507I', distance=3, longitud=6, latitud=5)
        ServiceLocation.objects.create(
            service='507I', distance=4, longitud=7, latitud=5)
        ServiceLocation.objects.create(
            service='507I', distance=5, longitud=8, latitud=5)
        ServiceLocation.objects.create(
            service='507I', distance=6, longitud=9, latitud=5)

    def test_consistencyModelDevicePositionInTime(self):
        '''This method test the database for the DevicePositionInTime model'''

        longituds = [3.5, 3.4, 3.3]
        latituds = [5.2, 5.2, 4.2]
        timeStamps = [
            self.time,
            self.time,
            self.time -
            timezone.timedelta(
                minutes=11)]

        for cont in range(3):
            devicePosition = DevicePositionInTime.objects.get(
                longitud=longituds[cont])
            self.assertEqual(devicePosition.latitud, latituds[cont])
            self.assertEqual(devicePosition.timeStamp, timeStamps[cont])

    def test_consistencyModelActiveToken(self):
        '''This method test the database for the ActiveToken model'''

        service = '503'
        licencePlate = 'ZZZZ00'
        travelToken = self.test.getInBusWithLicencePlate(
            self.userId, service, licencePlate)

        # the created token is an active token
        self.assertEqual(
            ActiveToken.objects.filter(
                token=travelToken).exists(), True)
        # the created token exist in the table of token
        self.assertEqual(
            Token.objects.filter(
                token=travelToken).exists(), True)

        jsonResponse = self.test.endRoute(travelToken)

        self.assertEqual(jsonResponse['response'], 'Trip ended.')

        # activeToken has to be missing but token has to exists
        self.assertEqual(
            ActiveToken.objects.filter(
                token=travelToken).exists(), False)
        self.assertEqual(
            Token.objects.filter(
                token=travelToken).exists(), True)

    def test_consistencyModelPoseInTrajectoryOfToken(self):
        '''this method test the PoseInTrajectoryOfToken'''

        service = '503'
        licencePlate = 'ZZZZ00'
        testToken = self.test.getInBusWithLicencePlate(
            self.userId, service, licencePlate)

        jsonResponse = self.test.sendFakeTrajectoryOfToken(testToken)

        self.assertEqual(jsonResponse['response'], 'Poses were register.')

        # remove the token
        self.test.endRoute(testToken)

        jsonResponse = self.test.sendFakeTrajectoryOfToken(testToken)

        self.assertEqual(jsonResponse['response'], 'Token doesn\'t exist.')

    def test_EventsByBusStopReportNegativelyForFistTime(self):
        """ report stop event negatively for fist time """

        busStopCode = 'PA459'
        eventCode = 'evn00001'

        jsonResponse = self.test.confirmOrDeclineStopEvent(
            self.userId, busStopCode, eventCode, 'decline')

        self.assertEqual(jsonResponse['codeBusStop'], busStopCode)
        self.assertEqual(jsonResponse['events'][0]['eventDecline'], 1)
        self.assertEqual(jsonResponse['events'][0]['eventConfirm'], 0)
        self.assertEqual(jsonResponse['events'][0]['eventcode'], eventCode)

    def test_EventsByBusStop(self):
        '''This method test two thing, the posibility to report an event and asking
        the events for the specific busStop'''

        busStopCode = 'PA459'
        eventCode = 'evn00001'
        # submitting some events to the server
        jsonResponse = self.test.reportStopEvent(
            self.userId, busStopCode, eventCode)

        # report one event, and confirm it
        self.assertEqual(jsonResponse['codeBusStop'], busStopCode)
        self.assertEqual(jsonResponse['events'][0]['eventDecline'], 0)
        self.assertEqual(jsonResponse['events'][0]['eventConfirm'], 1)
        self.assertEqual(jsonResponse['events'][0]['eventcode'], eventCode)

        # do event +1 to the event
        jsonResponse = self.test.confirmOrDeclineStopEvent(
            self.userId, busStopCode, eventCode, 'confirm')

        self.assertEqual(jsonResponse['codeBusStop'], busStopCode)
        self.assertEqual(jsonResponse['events'][0]['eventDecline'], 0)
        self.assertEqual(jsonResponse['events'][0]['eventConfirm'], 2)
        self.assertEqual(jsonResponse['events'][0]['eventcode'], eventCode)

        # do event -1 to the event
        jsonResponse = self.test.confirmOrDeclineStopEvent(
            self.userId, busStopCode, eventCode, 'decline')

        self.assertEqual(jsonResponse['codeBusStop'], busStopCode)
        self.assertEqual(jsonResponse['events'][0]['eventDecline'], 1)
        self.assertEqual(jsonResponse['events'][0]['eventConfirm'], 2)
        self.assertEqual(jsonResponse['events'][0]['eventcode'], eventCode)

        # change manualy the timeStamp to simulate an event that has expired
        busStop = BusStop.objects.get(code=busStopCode)
        event = Event.objects.get(id=eventCode)
        anEvent = EventForBusStop.objects.get(busStop=busStop, event=event)

        anEvent.timeStamp = anEvent.timeCreation - \
            timezone.timedelta(minutes=event.lifespam)
        anEvent.save()

        # ask for ecents and the answere should be none
        jsonResponse = self.test.reportStopEvent(
            self.userId, busStopCode, eventCode)
        self.assertEqual(jsonResponse['events'][0]['eventDecline'], 0)
        self.assertEqual(jsonResponse['events'][0]['eventConfirm'], 1)
        self.assertEqual(jsonResponse['events'][0]['eventcode'], eventCode)

    def test_registerPose(self):
        request = self.factory.get('/android/userPosition')
        request.user = AnonymousUser()
        lat = 45
        lon = 46
        response = views.userPosition(request, self.userId, lat, lon)

        self.assertEqual(response.status_code, 200)

        self.assertEqual(
            DevicePositionInTime.objects.filter(
                longitud=lon,
                latitud=lat).exists(),
            True)

    def test_preferPositionOfPersonInsideABus(self):

        # Bus.objects.create(registrationPlate = 'AA1111', service = '507')
        thebus = Busv2.objects.create(registrationPlate='AA1111')
        Busassignment.objects.create(service='507', uuid=thebus)

        timeStampNow = str(timezone.localtime(timezone.now()))
        timeStampNow = timeStampNow[0:19]
        userLatitud = -33.458771
        userLongitud = -70.676266

        # first we test the position of the bus without passsangers
        # bus = Bus.objects.get(registrationPlate='AA1111', service='507')
        bus = Busv2.objects.get(registrationPlate='AA1111')
        busassignment = Busassignment.objects.get(service='507', uuid=bus)

        busPose = busassignment.getLocation()

        self.assertTrue(busPose['random'])
        self.assertEqual(busPose['latitude'], -500)
        self.assertEqual(busPose['longitude'], -500)
        self.assertEqual(busPose['passengers'], 0)

        # add the position of a passanger inside the bus
        service = '507'
        licencePlate = 'AA1111'
        testToken = self.test.getInBusWithLicencePlate(
            self.userId, service, licencePlate)

        testPoses = {"poses": [
            {"latitud": userLatitud, "longitud": userLongitud, "timeStamp": str(timeStampNow), "inVehicleOrNot": "vehicle"}]}

        jsonResponse = self.test.sendFakeTrajectoryOfToken(
            testToken, testPoses)

        self.assertEqual(jsonResponse['response'], 'Poses were register.')

        # ask the position of the bus whit a passanger
        bus = Busv2.objects.get(registrationPlate=licencePlate)
        busassignment = Busassignment.objects.get(uuid=bus, service=service)

        busPose = busassignment.getLocation()

        self.assertEqual(busPose['latitude'], userLatitud)
        self.assertEqual(busPose['longitude'], userLongitud)
        self.assertEqual(busPose['random'], False)
        self.assertEqual(busPose['passengers'] > 0, True)

        self.test.endRoute(testToken)
class SetDirectionTest(TestCase):
    """ test for Setdirection url """

    def setUp(self):
        """ this method will automatically call for every single test """
        # for testing requests inside the project
        self.factory = RequestFactory()

        self.userId = "067e6162-3b6f-4ae2-a171-2470b63dff00"

        self.helper = TestHelper(self)

        self.service = '507'
        self.licencePlate = 'PABJ45'
        self.busStop = 'PA459'

        self.helper.insertServicesOnDatabase([self.service])
        self.helper.insertBusstopsOnDatabase([self.busStop])
        self.helper.insertServicesByBusstopsOnDatabase([self.busStop])

    def test_setDirectionWithActiveTokenWithDummyLicencePlate(self):
        """ set direction of travel has not been finished with dummy licence plate """

        travelKey = self.helper.getInBusWithLicencePlate(
            self.userId, self.service, Constants.DUMMY_LICENSE_PLATE)
        self.helper.sendFakeTrajectoryOfToken(travelKey)

        directions = ["I", "R"]
        for direction in directions:
            jsonResponse = self.helper.setDirection(travelKey, direction)

            self.assertEqual(jsonResponse['valid'], True)
            self.assertEqual(
                jsonResponse['message'],
                "User bus direction updated.")

        self.helper.endRoute(travelKey)

    def test_setDirectionWithActiveToken(self):
        """ set direction of travel has not been finished """

        travelKey = self.helper.getInBusWithLicencePlate(
            self.userId, self.service, self.licencePlate)
        self.helper.sendFakeTrajectoryOfToken(travelKey)

        directions = ["I", "R"]
        for direction in directions:
            jsonResponse = self.helper.setDirection(travelKey, direction)

            self.assertEqual(jsonResponse['valid'], True)
            self.assertEqual(
                jsonResponse['message'],
                "User bus direction updated.")

        self.helper.endRoute(travelKey)

    def test_setDirectionWithoutActiveToken(self):
        """ set direction of travel has been finished """

        travelKey = self.helper.getInBusWithLicencePlate(
            self.userId, self.service, self.licencePlate)
        self.helper.sendFakeTrajectoryOfToken(travelKey)
        self.helper.endRoute(travelKey)

        directions = ["I", "R"]
        for direction in directions:
            jsonResponse = self.helper.setDirection(travelKey, direction)

            self.assertEqual(jsonResponse['valid'], False)
            self.assertEqual(jsonResponse['message'], "Token doesn't exist.")

    def test_setDirectionWithoutActiveTokenWithDummyLicencePlate(self):
        """ set direction of travel has been finished """

        travelKey = self.helper.getInBusWithLicencePlate(
            self.userId, self.service, Constants.DUMMY_LICENSE_PLATE)
        self.helper.sendFakeTrajectoryOfToken(travelKey)
        self.helper.endRoute(travelKey)

        directions = ["I", "R"]
        for direction in directions:
            jsonResponse = self.helper.setDirection(travelKey, direction)

            self.assertEqual(jsonResponse['valid'], False)
            self.assertEqual(jsonResponse['message'], "Token doesn't exist.")

    def test_setDirectionWithWrongDirection(self):
        """ set direction of travel has been finished """

        travelKey = self.helper.getInBusWithLicencePlate(
            self.userId, self.service, self.licencePlate)
        self.helper.sendFakeTrajectoryOfToken(travelKey)

        directions = ["Z", "S", "other things"]
        for direction in directions:
            jsonResponse = self.helper.setDirection(travelKey, direction)

            self.assertEqual(jsonResponse['valid'], False)
            self.assertEqual(jsonResponse['message'], "Invalid direction.")

        self.helper.endRoute(travelKey)
class NearbyBusTest(TestCase):
    """ test for DevicePositionInTime model """

    def setUp(self):
        """ this method will automatically call for every single test """
        # for testing requests inside the project
        self.factory = RequestFactory()

        self.userId = "067e6162-3b6f-4ae2-a171-2470b63dff00"
        self.userId2 = "971087e3-b64c-4c22-88c2-2e1300ffd855"

        self.helper = TestHelper(self)

        self.service = '507'
        self.busStop = 'PA459'

        self.helper.insertServicesOnDatabase([self.service])
        self.helper.insertBusstopsOnDatabase([self.busStop])
        self.helper.insertServicesByBusstopsOnDatabase([self.busStop])

    def test_nearbyBuses(self):
        request = self.factory.get('/android/nearbyBuses')
        request.user = AnonymousUser()

        busStopCodeThis = 'PA459'
        self.helper.insertServicesByBusstopsOnDatabase([busStopCodeThis])

        response = views.nearbyBuses(request, self.userId, busStopCodeThis)

        self.assertEqual(response.status_code, 200)

        jsonResponse = json.loads(response.content)

        if (jsonResponse['DTPMError'] != ""):
            self.assertEqual(jsonResponse['DTPMError'],
                    "You do not have permission to do this! >:(.")
        else:
            self.assertEqual('servicios' in jsonResponse, True)
            self.assertEqual('eventos' in jsonResponse, True)

    def test_nearbyBusesWithFakeAuthorityInfoWithoutUserBuses(self):
        """ test methods used that uses nearbyBuses url. case: only authority buses """

        self.helper.insertServicesOnDatabase(['506', '506e', '506v', '509'])
        busStopCode = 'PA433'
        self.helper.insertServicesByBusstopsOnDatabase([busStopCode])

        # TODO: FALTA TOMAR UNA URL REAL Y LA FORMATEADA
        fakeAuthorityAnswer = '{"horaConsulta": "10:12", "servicios": [{"servicio": "506", "patente": "BJFB-28", "tiempo": "Menos de 5 min.", "valido": 1, "distancia": "1691  mts."}, {"servicio": "506", "patente": "BJFC-56", "tiempo": "Entre 03 Y 07 min. ", "valido": 1, "distancia": "1921  mts."}, {"servicio": "506E", "patente": "BJFH-28", "tiempo": "Menos de 5 min.", "valido": 1, "distancia": "771  mts."}, {"servicio": "506E", "patente": null, "tiempo": null, "valido": 1, "distancia": "None  mts."}, {"servicio": "506V", "patente": "FDJX-64", "tiempo": "Menos de 5 min.", "valido": 1, "distancia": "1922  mts."}, {"servicio": "506V", "patente": "BFKB-96", "tiempo": "Entre 04 Y 08 min. ", "valido": 1, "distancia": "1572  mts."}, {"servicio": "507", "patente": "BJFH-27", "tiempo": "Entre 11 Y 17 min. ", "valido": 1, "distancia": "3194  mts."}, {"servicio": "507", "patente": "BJFC-20", "tiempo": "Entre 20 Y 30 min. ", "valido": 1, "distancia": "6094  mts."}, {"servicio": "509", "patente": "FLXC-45", "tiempo": "Entre 04 Y 08 min. ", "valido": 1, "distancia": "1953  mts."}, {"servicio": "509", "patente": "FLXD-43", "tiempo": "Entre 08 Y 14 min. ", "valido": 1, "distancia": "3273  mts."}], "webTransId": "TSPP00000000000000219461", "error": null, "descripcion": "PARADA 1 / ESCUELA   DE INGENIERIA", "fechaConsulta": "2016-11-02", "id": "PA433"}'

        fakeJsonAuthorityAnswer = json.loads(fakeAuthorityAnswer)

        userBuses = views.getUserBuses(busStopCode, self.userId2)
        authBuses = views.getAuthorityBuses(fakeJsonAuthorityAnswer)

        buses = views.mergeBuses(userBuses, authBuses)

        jsonUrlAnswer = json.loads('{"eventos": [], "servicios": [{"servicio": "506", "eventos": [], "tiempo": "Menos de 5 min.", "random": false, "busId": "417d8ef0-aaac-4c91-b9c2-3835060ece89", "distancia": "1691  mts.", "patente": "BJFB28", "valido": 1, "lon": -70.6817326, "distanciaV2": "1.69Km", "color": 7, "tienePasajeros": 0, "tiempoV2": "0 a 5 min", "lat": -33.45898995, "direction": "I", "sentido": "right", "distanciaMts": 1691}, {"servicio": "506", "eventos": [], "tiempo": "Entre 03 Y 07 min. ", "random": false, "busId": "e86d3567-3a5d-48d3-b4a4-f0a139ab3825", "distancia": "1921  mts.", "patente": "BJFC56", "valido": 1, "lon": -70.68422918, "distanciaV2": "1.92Km", "color": 7, "tienePasajeros": 0, "tiempoV2": "03 a 07 min", "lat": -33.45909322, "direction": "I", "sentido": "right", "distanciaMts": 1921}, {"servicio": "506e", "eventos": [], "tiempo": "Menos de 5 min.", "random": false, "busId": "2c88087e-1c8d-4c47-9ccc-f4a28a25dba3", "distancia": "771  mts.", "patente": "BJFH28", "valido": 1, "lon": -70.67206943, "distanciaV2": "771m", "color": 7, "tienePasajeros": 0, "tiempoV2": "0 a 5 min", "lat": -33.45841956, "direction": "I", "sentido": "right", "distanciaMts": 771}, {"servicio": "506v", "eventos": [], "tiempo": "Menos de 5 min.", "random": false, "busId": "9db62e10-37a7-4cc4-8ee8-d66718e3d9f2", "distancia": "1922  mts.", "patente": "FDJX64", "valido": 1, "lon": -70.68417605, "distanciaV2": "1.92Km", "color": 7, "tienePasajeros": 0, "tiempoV2": "0 a 5 min", "lat": -33.45909223, "direction": "I", "sentido": "right", "distanciaMts": 1922}, {"servicio": "506v", "eventos": [], "tiempo": "Entre 04 Y 08 min. ", "random": false, "busId": "33c58d9e-355c-42db-9962-48150f17bb91", "distancia": "1572  mts.", "patente": "BFKB96", "valido": 1, "lon": -70.68060597, "distanciaV2": "1.57Km", "color": 7, "tienePasajeros": 0, "tiempoV2": "04 a 08 min", "lat": -33.4589299, "direction": "I", "sentido": "right", "distanciaMts": 1572}, {"servicio": "507", "eventos": [], "tiempo": "Entre 11 Y 17 min. ", "random": false, "busId": "7978130a-1458-4415-8224-4b9e2a645da2", "distancia": "3194  mts.", "patente": "BJFH27", "valido": 1, "lon": -70.67964937, "distanciaV2": "3.19Km", "color": 7, "tienePasajeros": 0, "tiempoV2": "11 a 17 min", "lat": -33.44337385, "direction": "I", "sentido": "right", "distanciaMts": 3194}, {"servicio": "507", "eventos": [], "tiempo": "Entre 20 Y 30 min. ", "random": false, "busId": "710b2e84-bc2c-44bc-829f-dbb07af0efb0", "distancia": "6094  mts.", "patente": "BJFC20", "valido": 1, "lon": -70.69886029, "distanciaV2": "6.09Km", "color": 7, "tienePasajeros": 0, "tiempoV2": "20 a 30 min", "lat": -33.4318278, "direction": "I", "sentido": "right", "distanciaMts": 6094}, {"servicio": "509", "eventos": [], "tiempo": "Entre 04 Y 08 min. ", "random": false, "busId": "84a6dcf9-d69a-4ca2-8e83-8f996711a31f", "distancia": "1953  mts.", "patente": "FLXC45", "valido": 1, "lon": -70.68453181, "distanciaV2": "1.95Km", "color": 7, "tienePasajeros": 0, "tiempoV2": "04 a 08 min", "lat": -33.45909886, "direction": "I", "sentido": "right", "distanciaMts": 1953}, {"servicio": "509", "eventos": [], "tiempo": "Entre 08 Y 14 min. ", "random": false, "busId": "1c5104a7-ae01-485c-9687-533d46ad965f", "distancia": "3273  mts.", "patente": "FLXD43", "valido": 1, "lon": -70.69789113, "distanciaV2": "3.27Km", "color": 7, "tienePasajeros": 0, "tiempoV2": "08 a 14 min", "lat": -33.46160623, "direction": "I", "sentido": "right", "distanciaMts": 3273}], "DTPMError": ""}')['servicios']

        self.assertEqual(buses[0]['patente'], jsonUrlAnswer[0]['patente'])
        self.assertEqual(buses[1]['patente'], jsonUrlAnswer[1]['patente'])
        self.assertEqual(buses[2]['patente'], jsonUrlAnswer[2]['patente'])
        self.assertEqual(buses[3]['patente'], jsonUrlAnswer[3]['patente'])
        self.assertEqual(buses[4]['patente'], jsonUrlAnswer[4]['patente'])
        self.assertEqual(buses[5]['patente'], jsonUrlAnswer[5]['patente'])
        self.assertEqual(buses[6]['patente'], jsonUrlAnswer[6]['patente'])
        self.assertEqual(buses[7]['patente'], jsonUrlAnswer[7]['patente'])
        self.assertEqual(buses[8]['patente'], jsonUrlAnswer[8]['patente'])

    def test_nearbyBusesWithFakeAuthorityInfoWithOneUserBus(self):
        """ test methods that uses nearbyBuses url. case: authority buses with one user bus"""

        direction = "I"
        busStopCode = 'PA433'
        self.helper.insertBusstopsOnDatabase([busStopCode])
        self.helper.insertServicesOnDatabase(['506', '506e', '506v', '509'])
        self.helper.insertServicesByBusstopsOnDatabase([busStopCode])

        travelKey = self.helper.getInBusWithLicencePlate(
            self.userId, self.service, Constants.DUMMY_LICENSE_PLATE)
        self.helper.sendFakeTrajectoryOfToken(travelKey)
        self.helper.setDirection(travelKey, direction)

        fakeAuthorityAnswer = '{"horaConsulta": "10:12", "servicios": [{"servicio": "506", "patente": "BJFB-28", "tiempo": "Menos de 5 min.", "valido": 1, "distancia": "1691  mts."}, {"servicio": "506", "patente": "BJFC-56", "tiempo": "Entre 03 Y 07 min. ", "valido": 1, "distancia": "1921  mts."}, {"servicio": "506E", "patente": "BJFH-28", "tiempo": "Menos de 5 min.", "valido": 1, "distancia": "771  mts."}, {"servicio": "506E", "patente": null, "tiempo": null, "valido": 1, "distancia": "None  mts."}, {"servicio": "506V", "patente": "FDJX-64", "tiempo": "Menos de 5 min.", "valido": 1, "distancia": "1922  mts."}, {"servicio": "506V", "patente": "BFKB-96", "tiempo": "Entre 04 Y 08 min. ", "valido": 1, "distancia": "1572  mts."}, {"servicio": "507", "patente": "BJFH-27", "tiempo": "Entre 11 Y 17 min. ", "valido": 1, "distancia": "3194  mts."}, {"servicio": "507", "patente": "BJFC-20", "tiempo": "Entre 20 Y 30 min. ", "valido": 1, "distancia": "6094  mts."}, {"servicio": "509", "patente": "FLXC-45", "tiempo": "Entre 04 Y 08 min. ", "valido": 1, "distancia": "1953  mts."}, {"servicio": "509", "patente": "FLXD-43", "tiempo": "Entre 08 Y 14 min. ", "valido": 1, "distancia": "3273  mts."}], "webTransId": "TSPP00000000000000219461", "error": null, "descripcion": "PARADA 1 / ESCUELA   DE INGENIERIA", "fechaConsulta": "2016-11-02", "id": "PA433"}'

        fakeJsonAuthorityAnswer = json.loads(fakeAuthorityAnswer)

        userBuses = views.getUserBuses(busStopCode, self.userId2)
        authBuses = views.getAuthorityBuses(fakeJsonAuthorityAnswer)
        buses = views.mergeBuses(userBuses, authBuses)

        self.assertEqual(len(buses), 9 + 1)
        self.assertEqual(buses[0]['patente'], Constants.DUMMY_LICENSE_PLATE)
        self.assertEqual(buses[0]['servicio'], self.service)
        self.assertEqual(buses[0]['direction'], direction)
        self.assertEqual(
            buses[1]['patente'],
            fakeJsonAuthorityAnswer['servicios'][0]['patente'])
        self.assertEqual(
            buses[2]['patente'],
            fakeJsonAuthorityAnswer['servicios'][1]['patente'])
        self.assertEqual(
            buses[3]['patente'],
            fakeJsonAuthorityAnswer['servicios'][2]['patente'])
        self.assertEqual(
            buses[4]['patente'],
            fakeJsonAuthorityAnswer['servicios'][4]['patente'])
        self.assertEqual(
            buses[5]['patente'],
            fakeJsonAuthorityAnswer['servicios'][5]['patente'])
        self.assertEqual(
            buses[6]['patente'],
            fakeJsonAuthorityAnswer['servicios'][6]['patente'])
        self.assertEqual(
            buses[7]['patente'],
            fakeJsonAuthorityAnswer['servicios'][7]['patente'])
        self.assertEqual(
            buses[8]['patente'],
            fakeJsonAuthorityAnswer['servicios'][8]['patente'])
        self.assertEqual(
            buses[9]['patente'],
            fakeJsonAuthorityAnswer['servicios'][9]['patente'])

    def test_nearbyBusesWithFakeAuthorityInfoWithTwoUserBus(self):
        """ test methods that uses nearbyBuses url. case: authority buses with two dummy user bus"""

        busStopCode = 'PA433'
        self.helper.insertBusstopsOnDatabase([busStopCode])
        self.helper.insertServicesOnDatabase(['506', '506e', '506v', '509'])
        self.helper.insertServicesByBusstopsOnDatabase([busStopCode])

        # first user
        direction1 = "I"
        travelKey1 = self.helper.getInBusWithLicencePlate(
            self.userId, self.service, Constants.DUMMY_LICENSE_PLATE)
        self.helper.sendFakeTrajectoryOfToken(travelKey1)
        self.helper.setDirection(travelKey1, direction1)
        # second user
        userId2 = 'ce102dcd-0670-4086-a543-b3e6e58e8f58'
        direction2 = "I"
        travelKey2 = self.helper.getInBusWithLicencePlate(
            userId2, self.service, Constants.DUMMY_LICENSE_PLATE)
        self.helper.sendFakeTrajectoryOfToken(travelKey2)
        self.helper.setDirection(travelKey2, direction2)

        fakeAuthorityAnswer = '{"horaConsulta": "10:12", "servicios": [{"servicio": "506", "patente": "BJFB-28", "tiempo": "Menos de 5 min.", "valido": 1, "distancia": "1691  mts."}, {"servicio": "506", "patente": "BJFC-56", "tiempo": "Entre 03 Y 07 min. ", "valido": 1, "distancia": "1921  mts."}, {"servicio": "506E", "patente": "BJFH-28", "tiempo": "Menos de 5 min.", "valido": 1, "distancia": "771  mts."}, {"servicio": "506E", "patente": null, "tiempo": null, "valido": 1, "distancia": "None  mts."}, {"servicio": "506V", "patente": "FDJX-64", "tiempo": "Menos de 5 min.", "valido": 1, "distancia": "1922  mts."}, {"servicio": "506V", "patente": "BFKB-96", "tiempo": "Entre 04 Y 08 min. ", "valido": 1, "distancia": "1572  mts."}, {"servicio": "507", "patente": "BJFH-27", "tiempo": "Entre 11 Y 17 min. ", "valido": 1, "distancia": "3194  mts."}, {"servicio": "507", "patente": "BJFC-20", "tiempo": "Entre 20 Y 30 min. ", "valido": 1, "distancia": "6094  mts."}, {"servicio": "509", "patente": "FLXC-45", "tiempo": "Entre 04 Y 08 min. ", "valido": 1, "distancia": "1953  mts."}, {"servicio": "509", "patente": "FLXD-43", "tiempo": "Entre 08 Y 14 min. ", "valido": 1, "distancia": "3273  mts."}], "webTransId": "TSPP00000000000000219461", "error": null, "descripcion": "PARADA 1 / ESCUELA   DE INGENIERIA", "fechaConsulta": "2016-11-02", "id": "PA433"}'

        fakeJsonAuthorityAnswer = json.loads(fakeAuthorityAnswer)

        userBuses = views.getUserBuses(busStopCode, self.userId2)
        authBuses = views.getAuthorityBuses(fakeJsonAuthorityAnswer)
        buses = views.mergeBuses(userBuses, authBuses)

        self.assertEqual(len(buses), 9 + 1 + 1)
        self.assertEqual(buses[0]['patente'], Constants.DUMMY_LICENSE_PLATE)
        self.assertEqual(buses[0]['servicio'], self.service)
        self.assertEqual(buses[0]['direction'], direction1)
        self.assertEqual(buses[1]['patente'], Constants.DUMMY_LICENSE_PLATE)
        self.assertEqual(buses[1]['servicio'], self.service)
        self.assertEqual(buses[1]['direction'], direction2)
        self.assertEqual(
            buses[2]['patente'],
            fakeJsonAuthorityAnswer['servicios'][0]['patente'])
        self.assertEqual(
            buses[3]['patente'],
            fakeJsonAuthorityAnswer['servicios'][1]['patente'])
        self.assertEqual(
            buses[4]['patente'],
            fakeJsonAuthorityAnswer['servicios'][2]['patente'])
        self.assertEqual(
            buses[5]['patente'],
            fakeJsonAuthorityAnswer['servicios'][4]['patente'])
        self.assertEqual(
            buses[6]['patente'],
            fakeJsonAuthorityAnswer['servicios'][5]['patente'])
        self.assertEqual(
            buses[7]['patente'],
            fakeJsonAuthorityAnswer['servicios'][6]['patente'])
        self.assertEqual(
            buses[8]['patente'],
            fakeJsonAuthorityAnswer['servicios'][7]['patente'])
        self.assertEqual(
            buses[9]['patente'],
            fakeJsonAuthorityAnswer['servicios'][8]['patente'])
        self.assertEqual(
            buses[10]['patente'],
            fakeJsonAuthorityAnswer['servicios'][9]['patente'])

    def test_nearbyBusesWithFakeAuthorityInfoWithTwoUserInTheSameBus(self):
        """ test methods that uses nearbyBuses url. case: authority buses with two user in the same bus"""

        direction1 = "I"
        direction2 = "I"
        busStopCode = 'PA433'
        self.helper.insertBusstopsOnDatabase([busStopCode])
        self.helper.insertServicesOnDatabase(['506', '506e', '506v', '509'])
        self.helper.insertServicesByBusstopsOnDatabase([busStopCode])

        licencePlate = 'bjfb28'
        service = '506'
        # first user
        travelKey1 = self.helper.getInBusWithLicencePlate(
            self.userId, service, licencePlate)
        self.helper.sendFakeTrajectoryOfToken(travelKey1)
        self.helper.setDirection(travelKey1, direction1)
        # second user
        userId2 = 'ce102dcd-0670-4086-a543-b3e6e58e8f58'
        travelKey2 = self.helper.getInBusWithLicencePlate(
            userId2, service, licencePlate)
        self.helper.sendFakeTrajectoryOfToken(travelKey2)
        self.helper.setDirection(travelKey2, direction2)

        fakeAuthorityAnswer = '{"horaConsulta": "10:12", "servicios": [{"servicio": "506", "patente": "BJFB-28", "tiempo": "Menos de 5 min.", "valido": 1, "distancia": "1691  mts."}, {"servicio": "506", "patente": "BJFC-56", "tiempo": "Entre 03 Y 07 min. ", "valido": 1, "distancia": "1921  mts."}, {"servicio": "506E", "patente": "BJFH-28", "tiempo": "Menos de 5 min.", "valido": 1, "distancia": "771  mts."}, {"servicio": "506E", "patente": null, "tiempo": null, "valido": 1, "distancia": "None  mts."}, {"servicio": "506V", "patente": "FDJX-64", "tiempo": "Menos de 5 min.", "valido": 1, "distancia": "1922  mts."}, {"servicio": "506V", "patente": "BFKB-96", "tiempo": "Entre 04 Y 08 min. ", "valido": 1, "distancia": "1572  mts."}, {"servicio": "507", "patente": "BJFH-27", "tiempo": "Entre 11 Y 17 min. ", "valido": 1, "distancia": "3194  mts."}, {"servicio": "507", "patente": "BJFC-20", "tiempo": "Entre 20 Y 30 min. ", "valido": 1, "distancia": "6094  mts."}, {"servicio": "509", "patente": "FLXC-45", "tiempo": "Entre 04 Y 08 min. ", "valido": 1, "distancia": "1953  mts."}, {"servicio": "509", "patente": "FLXD-43", "tiempo": "Entre 08 Y 14 min. ", "valido": 1, "distancia": "3273  mts."}], "webTransId": "TSPP00000000000000219461", "error": null, "descripcion": "PARADA 1 / ESCUELA   DE INGENIERIA", "fechaConsulta": "2016-11-02", "id": "PA433"}'

        fakeJsonAuthorityAnswer = json.loads(fakeAuthorityAnswer)
        userBuses = views.getUserBuses(busStopCode, self.userId2)
        authBuses = views.getAuthorityBuses(fakeJsonAuthorityAnswer)
        buses = views.mergeBuses(userBuses, authBuses)
        self.assertEqual(len(buses), 9)
        self.assertEqual(buses[0]['patente'], licencePlate.upper())
        self.assertEqual(buses[0]['servicio'], service)
        self.assertEqual(buses[0]['tienePasajeros'], 2)
        self.assertEqual(buses[0]['distanciaMts'], 1691)
        self.assertEqual(buses[0]['tiempoV2'], "0 a 5 min")
        self.assertEqual(buses[0]['distanciaV2'], "1.69Km")
        self.assertEqual(buses[0]['direction'], "I")
        self.assertEqual(
            buses[1]['patente'],
            fakeJsonAuthorityAnswer['servicios'][1]['patente'])
        self.assertEqual(
            buses[2]['patente'],
            fakeJsonAuthorityAnswer['servicios'][2]['patente'])
        self.assertEqual(
            buses[3]['patente'],
            fakeJsonAuthorityAnswer['servicios'][4]['patente'])
        self.assertEqual(
            buses[4]['patente'],
            fakeJsonAuthorityAnswer['servicios'][5]['patente'])
        self.assertEqual(
            buses[5]['patente'],
            fakeJsonAuthorityAnswer['servicios'][6]['patente'])
        self.assertEqual(
            buses[6]['patente'],
            fakeJsonAuthorityAnswer['servicios'][7]['patente'])
        self.assertEqual(
            buses[7]['patente'],
            fakeJsonAuthorityAnswer['servicios'][8]['patente'])
        self.assertEqual(
            buses[8]['patente'],
            fakeJsonAuthorityAnswer['servicios'][9]['patente'])

    def test_nearbyBusesWithFakeAuthorityInfoWithUserBusThatMatchWithAuthorityBus(
            self):
        """ test methods that uses nearbyBuses url. case: authority buses with user bus that match with authority bus """

        busStopCode = 'PA433'
        self.helper.insertBusstopsOnDatabase([busStopCode])
        self.helper.insertServicesOnDatabase(['506', '506e', '506v', '509'])
        self.helper.insertServicesByBusstopsOnDatabase([busStopCode])

        direction = "I"
        licencePlate = 'bjFb28'
        service = '506'
        travelKey = self.helper.getInBusWithLicencePlate(
            self.userId, service, licencePlate)
        self.helper.sendFakeTrajectoryOfToken(travelKey)
        self.helper.setDirection(travelKey, direction)

        fakeAuthorityAnswer = '{"horaConsulta": "10:12", "servicios": [{"servicio": "506", "patente": "BJFB-28", "tiempo": "Menos de 5 min.", "valido": 1, "distancia": "1691  mts."}, {"servicio": "506", "patente": "BJFC-56", "tiempo": "Entre 03 Y 07 min. ", "valido": 1, "distancia": "1921  mts."}, {"servicio": "506E", "patente": "BJFH-28", "tiempo": "Menos de 5 min.", "valido": 1, "distancia": "771  mts."}, {"servicio": "506E", "patente": null, "tiempo": null, "valido": 1, "distancia": "None  mts."}, {"servicio": "506V", "patente": "FDJX-64", "tiempo": "Menos de 5 min.", "valido": 1, "distancia": "1922  mts."}, {"servicio": "506V", "patente": "BFKB-96", "tiempo": "Entre 04 Y 08 min. ", "valido": 1, "distancia": "1572  mts."}, {"servicio": "507", "patente": "BJFH-27", "tiempo": "Entre 11 Y 17 min. ", "valido": 1, "distancia": "3194  mts."}, {"servicio": "507", "patente": "BJFC-20", "tiempo": "Entre 20 Y 30 min. ", "valido": 1, "distancia": "6094  mts."}, {"servicio": "509", "patente": "FLXC-45", "tiempo": "Entre 04 Y 08 min. ", "valido": 1, "distancia": "1953  mts."}, {"servicio": "509", "patente": "FLXD-43", "tiempo": "Entre 08 Y 14 min. ", "valido": 1, "distancia": "3273  mts."}], "webTransId": "TSPP00000000000000219461", "error": null, "descripcion": "PARADA 1 / ESCUELA   DE INGENIERIA", "fechaConsulta": "2016-11-02", "id": "PA433"}'

        fakeJsonAuthorityAnswer = json.loads(fakeAuthorityAnswer)

        userBuses = views.getUserBuses(busStopCode, self.userId2)
        authBuses = views.getAuthorityBuses(fakeJsonAuthorityAnswer)
        buses = views.mergeBuses(userBuses, authBuses)

        self.assertEqual(len(buses), 9)
        self.assertEqual(buses[0]['patente'], licencePlate.upper())
        self.assertEqual(buses[0]['servicio'], service)
        self.assertEqual(buses[0]['tienePasajeros'], 1)
        self.assertEqual(buses[0]['direction'], direction)
        self.assertEqual(
            buses[1]['patente'],
            fakeJsonAuthorityAnswer['servicios'][1]['patente'])
        self.assertEqual(
            buses[2]['patente'],
            fakeJsonAuthorityAnswer['servicios'][2]['patente'])
        self.assertEqual(
            buses[3]['patente'],
            fakeJsonAuthorityAnswer['servicios'][4]['patente'])
        self.assertEqual(
            buses[4]['patente'],
            fakeJsonAuthorityAnswer['servicios'][5]['patente'])
        self.assertEqual(
            buses[5]['patente'],
            fakeJsonAuthorityAnswer['servicios'][6]['patente'])
        self.assertEqual(
            buses[6]['patente'],
            fakeJsonAuthorityAnswer['servicios'][7]['patente'])
        self.assertEqual(
            buses[7]['patente'],
            fakeJsonAuthorityAnswer['servicios'][8]['patente'])
        self.assertEqual(
            buses[8]['patente'],
            fakeJsonAuthorityAnswer['servicios'][9]['patente'])

    def test_nearbyBusesWithFakeAuthorityInfoWithUserBusWithoutDirection(self):
        """ test methods that uses nearbyBuses url. case: authority buses with user bus without direction, so the user bus should not see in the list of buses """

        busStopCode = 'PA433'
        self.helper.insertBusstopsOnDatabase([busStopCode])
        self.helper.insertServicesOnDatabase(['506', '506e', '506v', '509'])
        self.helper.insertServicesByBusstopsOnDatabase([busStopCode])

        # licencePlate = 'bjFb28'
        service = '506'
        travelKey = self.helper.getInBusWithLicencePlate(
            self.userId, service, Constants.DUMMY_LICENSE_PLATE)
        self.helper.sendFakeTrajectoryOfToken(travelKey)
        # self.helper.setDirection(travelKey, direction)

        fakeAuthorityAnswer = '{"horaConsulta": "10:12", "servicios": [{"servicio": "506", "patente": "BJFB-28", "tiempo": "Menos de 5 min.", "valido": 1, "distancia": "1691  mts."}, {"servicio": "506", "patente": "BJFC-56", "tiempo": "Entre 03 Y 07 min. ", "valido": 1, "distancia": "1921  mts."}, {"servicio": "506E", "patente": "BJFH-28", "tiempo": "Menos de 5 min.", "valido": 1, "distancia": "771  mts."}, {"servicio": "506E", "patente": null, "tiempo": null, "valido": 1, "distancia": "None  mts."}, {"servicio": "506V", "patente": "FDJX-64", "tiempo": "Menos de 5 min.", "valido": 1, "distancia": "1922  mts."}, {"servicio": "506V", "patente": "BFKB-96", "tiempo": "Entre 04 Y 08 min. ", "valido": 1, "distancia": "1572  mts."}, {"servicio": "507", "patente": "BJFH-27", "tiempo": "Entre 11 Y 17 min. ", "valido": 1, "distancia": "3194  mts."}, {"servicio": "507", "patente": "BJFC-20", "tiempo": "Entre 20 Y 30 min. ", "valido": 1, "distancia": "6094  mts."}, {"servicio": "509", "patente": "FLXC-45", "tiempo": "Entre 04 Y 08 min. ", "valido": 1, "distancia": "1953  mts."}, {"servicio": "509", "patente": "FLXD-43", "tiempo": "Entre 08 Y 14 min. ", "valido": 1, "distancia": "3273  mts."}], "webTransId": "TSPP00000000000000219461", "error": null, "descripcion": "PARADA 1 / ESCUELA   DE INGENIERIA", "fechaConsulta": "2016-11-02", "id": "PA433"}'

        fakeJsonAuthorityAnswer = json.loads(fakeAuthorityAnswer)

        userBuses = views.getUserBuses(busStopCode, self.userId2)
        authBuses = views.getAuthorityBuses(fakeJsonAuthorityAnswer)
        buses = views.mergeBuses(userBuses, authBuses)

        self.assertEqual(len(buses), 9)
        self.assertEqual(
            buses[0]['patente'],
            fakeJsonAuthorityAnswer['servicios'][0]['patente'])
        self.assertEqual(
            buses[1]['patente'],
            fakeJsonAuthorityAnswer['servicios'][1]['patente'])
        self.assertEqual(
            buses[2]['patente'],
            fakeJsonAuthorityAnswer['servicios'][2]['patente'])
        self.assertEqual(
            buses[3]['patente'],
            fakeJsonAuthorityAnswer['servicios'][4]['patente'])
        self.assertEqual(
            buses[4]['patente'],
            fakeJsonAuthorityAnswer['servicios'][5]['patente'])
        self.assertEqual(
            buses[5]['patente'],
            fakeJsonAuthorityAnswer['servicios'][6]['patente'])
        self.assertEqual(
            buses[6]['patente'],
            fakeJsonAuthorityAnswer['servicios'][7]['patente'])
        self.assertEqual(
            buses[7]['patente'],
            fakeJsonAuthorityAnswer['servicios'][8]['patente'])
        self.assertEqual(
            buses[8]['patente'],
            fakeJsonAuthorityAnswer['servicios'][9]['patente'])

    def test_nearbyBusesWhenUserIsOnTheBus(self):
        """ test methods that uses nearbyBuses url.
        case: ask for buses when the user is in one of bus that goes to the bus stop asked """

        busStopCode = 'PA433'
        self.helper.insertBusstopsOnDatabase([busStopCode])
        self.helper.insertServicesOnDatabase(['506', '506e', '506v', '509'])
        self.helper.insertServicesByBusstopsOnDatabase([busStopCode])

        direction = "I"
        licencePlate = 'bjFb28'
        service = '506'
        travelKey = self.helper.getInBusWithLicencePlate(
            self.userId, service, licencePlate)
        self.helper.sendFakeTrajectoryOfToken(travelKey)
        self.helper.setDirection(travelKey, direction)

        fakeAuthorityAnswer = '{"horaConsulta": "10:12", "servicios": [{"servicio": "506", "patente": "BJFB-28", "tiempo": "Menos de 5 min.", "valido": 1, "distancia": "1691  mts."}, {"servicio": "506", "patente": "BJFC-56", "tiempo": "Entre 03 Y 07 min. ", "valido": 1, "distancia": "1921  mts."}, {"servicio": "506E", "patente": "BJFH-28", "tiempo": "Menos de 5 min.", "valido": 1, "distancia": "771  mts."}, {"servicio": "506E", "patente": null, "tiempo": null, "valido": 1, "distancia": "None  mts."}, {"servicio": "506V", "patente": "FDJX-64", "tiempo": "Menos de 5 min.", "valido": 1, "distancia": "1922  mts."}, {"servicio": "506V", "patente": "BFKB-96", "tiempo": "Entre 04 Y 08 min. ", "valido": 1, "distancia": "1572  mts."}, {"servicio": "507", "patente": "BJFH-27", "tiempo": "Entre 11 Y 17 min. ", "valido": 1, "distancia": "3194  mts."}, {"servicio": "507", "patente": "BJFC-20", "tiempo": "Entre 20 Y 30 min. ", "valido": 1, "distancia": "6094  mts."}, {"servicio": "509", "patente": "FLXC-45", "tiempo": "Entre 04 Y 08 min. ", "valido": 1, "distancia": "1953  mts."}, {"servicio": "509", "patente": "FLXD-43", "tiempo": "Entre 08 Y 14 min. ", "valido": 1, "distancia": "3273  mts."}], "webTransId": "TSPP00000000000000219461", "error": null, "descripcion": "PARADA 1 / ESCUELA   DE INGENIERIA", "fechaConsulta": "2016-11-02", "id": "PA433"}'

        fakeJsonAuthorityAnswer = json.loads(fakeAuthorityAnswer)

        userBuses = views.getUserBuses(busStopCode, self.userId)
        authBuses = views.getAuthorityBuses(fakeJsonAuthorityAnswer)
        buses = views.mergeBuses(userBuses, authBuses)

        self.assertEqual(len(buses), 8)
        self.assertEqual(
            buses[0]['patente'],
            fakeJsonAuthorityAnswer['servicios'][1]['patente'])
        self.assertEqual(
            buses[1]['patente'],
            fakeJsonAuthorityAnswer['servicios'][2]['patente'])
        self.assertEqual(
            buses[2]['patente'],
            fakeJsonAuthorityAnswer['servicios'][4]['patente'])
        self.assertEqual(
            buses[3]['patente'],
            fakeJsonAuthorityAnswer['servicios'][5]['patente'])
        self.assertEqual(
            buses[4]['patente'],
            fakeJsonAuthorityAnswer['servicios'][6]['patente'])
        self.assertEqual(
            buses[5]['patente'],
            fakeJsonAuthorityAnswer['servicios'][7]['patente'])
        self.assertEqual(
            buses[6]['patente'],
            fakeJsonAuthorityAnswer['servicios'][8]['patente'])
        self.assertEqual(
            buses[7]['patente'],
            fakeJsonAuthorityAnswer['servicios'][9]['patente'])

    def test_nearbyBusesWhenUserIsOnTheDummyBus(self):
        """ test methods that uses nearbyBuses url.
        case: ask for buses when the user is in one of bus that stops in the bus stop asked """

        busStopCode = 'PA433'
        self.helper.insertBusstopsOnDatabase([busStopCode])
        self.helper.insertServicesOnDatabase(['506', '506e', '506v', '509'])
        self.helper.insertServicesByBusstopsOnDatabase([busStopCode])

        direction = "I"
        # licencePlate = 'bjFb28'
        service = '506'
        travelKey = self.helper.getInBusWithLicencePlate(
            self.userId, service, Constants.DUMMY_LICENSE_PLATE)
        self.helper.sendFakeTrajectoryOfToken(travelKey)
        self.helper.setDirection(travelKey, direction)

        fakeAuthorityAnswer = '{"horaConsulta": "10:12", "servicios": [{"servicio": "506", "patente": "BJFB-28", "tiempo": "Menos de 5 min.", "valido": 1, "distancia": "1691  mts."}, {"servicio": "506", "patente": "BJFC-56", "tiempo": "Entre 03 Y 07 min. ", "valido": 1, "distancia": "1921  mts."}, {"servicio": "506E", "patente": "BJFH-28", "tiempo": "Menos de 5 min.", "valido": 1, "distancia": "771  mts."}, {"servicio": "506E", "patente": null, "tiempo": null, "valido": 1, "distancia": "None  mts."}, {"servicio": "506V", "patente": "FDJX-64", "tiempo": "Menos de 5 min.", "valido": 1, "distancia": "1922  mts."}, {"servicio": "506V", "patente": "BFKB-96", "tiempo": "Entre 04 Y 08 min. ", "valido": 1, "distancia": "1572  mts."}, {"servicio": "507", "patente": "BJFH-27", "tiempo": "Entre 11 Y 17 min. ", "valido": 1, "distancia": "3194  mts."}, {"servicio": "507", "patente": "BJFC-20", "tiempo": "Entre 20 Y 30 min. ", "valido": 1, "distancia": "6094  mts."}, {"servicio": "509", "patente": "FLXC-45", "tiempo": "Entre 04 Y 08 min. ", "valido": 1, "distancia": "1953  mts."}, {"servicio": "509", "patente": "FLXD-43", "tiempo": "Entre 08 Y 14 min. ", "valido": 1, "distancia": "3273  mts."}], "webTransId": "TSPP00000000000000219461", "error": null, "descripcion": "PARADA 1 / ESCUELA   DE INGENIERIA", "fechaConsulta": "2016-11-02", "id": "PA433"}'

        fakeJsonAuthorityAnswer = json.loads(fakeAuthorityAnswer)

        userBuses = views.getUserBuses(busStopCode, self.userId)
        authBuses = views.getAuthorityBuses(fakeJsonAuthorityAnswer)
        buses = views.mergeBuses(userBuses, authBuses)

        self.assertEqual(len(buses), 9)
        self.assertEqual(
            buses[0]['patente'],
            fakeJsonAuthorityAnswer['servicios'][0]['patente'])
        self.assertEqual(
            buses[1]['patente'],
            fakeJsonAuthorityAnswer['servicios'][1]['patente'])
        self.assertEqual(
            buses[2]['patente'],
            fakeJsonAuthorityAnswer['servicios'][2]['patente'])
        self.assertEqual(
            buses[3]['patente'],
            fakeJsonAuthorityAnswer['servicios'][4]['patente'])
        self.assertEqual(
            buses[4]['patente'],
            fakeJsonAuthorityAnswer['servicios'][5]['patente'])
        self.assertEqual(
            buses[5]['patente'],
            fakeJsonAuthorityAnswer['servicios'][6]['patente'])
        self.assertEqual(
            buses[6]['patente'],
            fakeJsonAuthorityAnswer['servicios'][7]['patente'])
        self.assertEqual(
            buses[7]['patente'],
            fakeJsonAuthorityAnswer['servicios'][8]['patente'])

    def test_nearbyBusesFormatDistance(self):
        """ test method that apply distance format  """
        distanceLessThan1000 = 585
        distanceGreaterThan1000NotInt = 1856
        distanceGreaterThan1000Int = 2000

        self.assertEqual(views.formatDistance(distanceLessThan1000), "585m")
        self.assertEqual(views.formatDistance(
            distanceGreaterThan1000NotInt), "1.86Km")
        self.assertEqual(views.formatDistance(
            distanceGreaterThan1000Int), "2Km")

    def test_nearbyBusesFormatServiceName(self):
        """ test method that apply service format to service names """
        serviceName1 = "506E"
        serviceName2 = "506N"
        serviceName3 = "D03N"
        serviceName4 = "D03E"
        serviceName5 = "D03"
        serviceName6 = "N50"
        serviceName7 = "506"

        self.assertEqual(views.formatServiceName(serviceName1), "506e")
        self.assertEqual(views.formatServiceName(serviceName2), "506N")
        self.assertEqual(views.formatServiceName(serviceName3), "D03N")
        self.assertEqual(views.formatServiceName(serviceName4), "D03e")
        self.assertEqual(views.formatServiceName(serviceName5), "D03")
        self.assertEqual(views.formatServiceName(serviceName6), "N50")
        self.assertEqual(views.formatServiceName(serviceName7), "506")

    def test_nearbyBusesFormatTime(self):
        """ test method that apply time format """

        times = [
            "Menos de 5 min.",
            "Entre 19 Y 29 min.",
            "Mas de 45 min.",
            "En menos de 10 min.",
            "Otro caso"]
        distances = [50, 150]

        answers = [
            "Llegando",
            "0 a 5 min",
            "19 a 29 min",
            "19 a 29 min",
            "+ de 45 min",
            "+ de 45 min",
            "Llegando",
            "0 a 10 min",
            "Otro caso",
            "Otro caso"]
        index = 0
        for time in times:
            for distance in distances:
                self.assertEqual(
                    views.formatTime(
                        time,
                        distance),
                    answers[index])
                index += 1