Exemple #1
0
class AcceptLoadSuccessfulTest(TestCase):
    def setUp(self):
        self.shipper_user, self.shipper = createUser(True)
        self.carrier_user, self.carrier = createUser(False)

        self.client = setAuthClient(self.carrier_user)

        self.obj = Load(
            pickup_date='2019-04-17',
            ref=123,
            origin_city='Miami Gardens, FL, USA',
            destination_city='Florida City, FL, USA',
            price=50.0,
            status="available",
            suggested_price=67.04,
            shipper=self.shipper,
        )
        self.obj.save()
        self.response = self.client.put(r('api:accept_load',
                                          pk_load=self.obj.pk),
                                        format='json')

    def test_status_code(self):
        self.assertEqual(self.response.status_code, 200)

    def test_accepted_load(self):
        self.assertTrue(
            Load.objects.filter(carrier=self.carrier,
                                status='accepted').count())

    def test_json_successful(self):
        self.assertEqual(self.response.data,
                         {'success': 'Load accepted successfully'})
Exemple #2
0
class ListCarrierRejectedLoads(TestCase):
    def setUp(self):
        self.shipper_user, self.shipper = createUser(True)
        self.carrier_user, self.carrier = createUser(False)

        self.client = setAuthClient(self.carrier_user)

        self.obj = Load(
            pickup_date='2019-04-17',
            ref=123,
            origin_city='Miami Gardens, FL, USA',
            destination_city='Florida City, FL, USA',
            price=50.0,
            status="available",
            suggested_price=67.04,
            shipper=self.shipper,
        )
        self.obj.save()

        self.obj_rejected = RejectedLoad(load=self.obj, carrier=self.carrier)
        self.obj_rejected.save()

        self.response = self.client.get(r('api:list_carrier_rejected'),
                                        format='json')

    def test_status_code(self):
        self.assertEqual(self.response.status_code, 200)

    def test_rejected_loads(self):
        self.assertEqual(
            len(self.response.data['results']),
            RejectedLoad.objects.filter(carrier=self.carrier,
                                        load=self.obj).count())

    def test_json(self):
        self.assertEqual(
            self.response.json()['results'][0], {
                'id': 1,
                'pickup_date': '2019-04-17',
                'ref': '123',
                'origin_city': 'Miami Gardens, FL, USA',
                'destination_city': 'Florida City, FL, USA',
                'price': 47.5,
                'status': 'available',
                'shipper': 'shipper teste',
                'carrier': None
            })
Exemple #3
0
class DropLoadUnsuccessfulTest(TestCase):
    def setUp(self):
        self.shipper_user, self.shipper = createUser(True)
        self.carrier_user, self.carrier = createUser(False)

        self.client = setAuthClient(self.carrier_user)

        another_user = User.objects.create(email='*****@*****.**',
                                           first_name='carrier 2',
                                           last_name='teste',
                                           password='******')
        another_carrier = CarrierUser.objects.create(user=another_user,
                                                     MC_number=456)
        another_carrier.save()

        self.obj = Load(pickup_date='2019-04-17',
                        ref=123,
                        origin_city='Miami Gardens, FL, USA',
                        destination_city='Florida City, FL, USA',
                        price=50.0,
                        status="accepted",
                        suggested_price=67.04,
                        shipper=self.shipper,
                        carrier=another_carrier)
        self.obj.save()
        self.response = self.client.put(r('api:drop_load',
                                          pk_load=self.obj.pk),
                                        format='json')

    def test_status_code(self):
        self.assertEqual(self.response.status_code, 404)

    def test_rejected_load(self):
        self.assertFalse(
            RejectedLoad.objects.filter(carrier=self.carrier,
                                        load=self.obj).count())

    def test_json_unsuccessful(self):
        self.assertEqual(
            self.response.data,
            {'error': 'Load not found or Load is not accepted by you'})
Exemple #4
0
class EditPriceGet(TestCase):
    def setUp(self):
        user, shipper = createUser()
        self.client.force_login(user)

        self.obj = Load(pickup_date='2019-04-17',
                        ref=123,
                        origin_city='Miami Gardens, FL, USA',
                        destination_city='Florida City, FL, USA',
                        price=50.0,
                        status="available",
                        suggested_price=67.04,
                        shipper=shipper)
        self.obj.save()

        self.response = self.client.get(r('shipper:edit_price', self.obj.pk))

    def test_template(self):
        self.assertTemplateUsed(self.response, 'edit_price_modal.html')

    def test_get(self):
        self.assertEqual(200, self.response.status_code)
Exemple #5
0
class CancelLoadDelete(TestCase):
    def setUp(self):
        user, shipper = createUser()
        self.client.force_login(user)

        self.obj = Load(pickup_date='2019-04-17',
                        ref=123,
                        origin_city='Miami Gardens, FL, USA',
                        destination_city='Florida City, FL, USA',
                        price=50.0,
                        status="available",
                        suggested_price=67.04,
                        shipper=shipper)
        self.obj.save()
        self.response = self.client.post(
            r('shipper:cancel_load', pk=self.obj.pk))

    def test_status_code(self):
        self.assertEqual(self.response.status_code, 302)

    def test_update(self):
        self.assertFalse(Load.objects.exists())
def createLoad():
    user = User.objects.create(
        email='*****@*****.**',
        first_name='shipper',
        last_name='teste')
    user.save()
    shipper = ShipperUser.objects.create(user=user)
    shipper.save()

    load = Load(
        pickup_date='2019-06-10',
        ref=123,
        origin_city='Miami Gardens, FL, USA',
        destination_city='Florida City, FL, USA',
        price=50.0,
        status="available",
        suggested_price=67.04,
        shipper=shipper,
    )
    load.save()

    return load
class PostModelLoadTest(TestCase):
    def setUp(self):
        user, shipper = createUser()
        self.obj = Load(pickup_date=str(datetime.date.today()),
                        ref=123,
                        origin_city='Miami Gardens, FL, USA',
                        destination_city='Florida City, FL, USA',
                        price=50.0,
                        status="available",
                        suggested_price=67.04,
                        shipper=shipper)
        self.obj.save()

    def test_create(self):
        ''' Data from valid Post must exist in database'''
        self.assertTrue(Load.objects.exists())

    def test_str(self):
        test_str = "Pickup date: {}, REF: {}, Origin City: {}, Destination city: {}, Price: {}, Carrier: {}, Shipper: {}".format(
            self.obj.pickup_date, self.obj.ref, self.obj.origin_city,
            self.obj.destination_city, self.obj.price, self.obj.carrier,
            self.obj.shipper)
        self.assertEqual(str(self.obj), test_str)
Exemple #8
0
class EditPricePut(TestCase):
    def setUp(self):
        user, shipper = createUser()
        self.client.force_login(user)

        self.obj = Load(pickup_date='2019-04-17',
                        ref=123,
                        origin_city='Miami Gardens, FL, USA',
                        destination_city='Florida City, FL, USA',
                        price=50.0,
                        status="available",
                        suggested_price=67.04,
                        shipper=shipper)
        self.obj.save()

        self.response = self.client.post(r('shipper:edit_price', self.obj.pk),
                                         {'price': 67.04})
        self.obj.refresh_from_db()

    def test_status_code(self):
        self.assertEqual(self.response.status_code, 302)

    def test_update(self):
        self.assertEqual(self.obj.price, 67.04)