Exemple #1
0
 def setUp(self):
     self.vehicle = VehicleFactory.create(
         'ABC1234',
         Customer('58355843690', 'Marcia Garcia', '*****@*****.**',
                  '76e67f3c40024dfd94bdb71976022839'),
         Model('HRV EX 1.8',
               Brand('Honda', 'e29ed583b9a246a8a7f1596593bb7888'),
               'b49aa1cb2082476bb3b6af601ec3ef9b'), 2018)
     self.vehicle_with_id = VehicleFactory.create(
         'ABC1234',
         Customer('58355843690', 'Marcia Garcia', '*****@*****.**',
                  '76e67f3c40024dfd94bdb71976022839'),
         Model('HRV EX 1.8',
               Brand('Honda', 'e29ed583b9a246a8a7f1596593bb7888'),
               'b49aa1cb2082476bb3b6af601ec3ef9b'), 2018,
         '9fd11778695b44368fd03258cbcc7b17')
     self.json = {
         "plate": "ABC1234",
         "owner": {
             "doc_id": "58355843690",
             "name": "Marcia Garcia",
             "email": "*****@*****.**",
             "_id": "76e67f3c40024dfd94bdb71976022839"
         },
         "model": {
             "name": "HRV EX 1.8",
             "brand": {
                 "name": "Honda",
                 "_id": "e29ed583b9a246a8a7f1596593bb7888"
             },
             "_id": "b49aa1cb2082476bb3b6af601ec3ef9b"
         },
         "model_year": 2018,
         "_id": "9fd11778695b44368fd03258cbcc7b17"
     }
Exemple #2
0
 def test_create_valid_model_year(self):
     vehicle_year_none = VehicleFactory.create(
         'ABC1234',
         Customer('58355843690', 'Marcia Garcia', '*****@*****.**',
                  '76e67f3c40024dfd94bdb71976022839'),
         Model('HRV EX 1.8',
               Brand('Honda', 'e29ed583b9a246a8a7f1596593bb7888'),
               'b49aa1cb2082476bb3b6af601ec3ef9b'), None)
     vehicle_next_year = VehicleFactory.create(
         'ABC1234',
         Customer('58355843690', 'Marcia Garcia', '*****@*****.**',
                  '76e67f3c40024dfd94bdb71976022839'),
         Model('HRV EX 1.8',
               Brand('Honda', 'e29ed583b9a246a8a7f1596593bb7888'),
               'b49aa1cb2082476bb3b6af601ec3ef9b'),
         datetime.date.today().year + 1)
     vehicle_old = VehicleFactory.create(
         'ABC1234',
         Customer('58355843690', 'Marcia Garcia', '*****@*****.**',
                  '76e67f3c40024dfd94bdb71976022839'),
         Model('HRV EX 1.8',
               Brand('Honda', 'e29ed583b9a246a8a7f1596593bb7888'),
               'b49aa1cb2082476bb3b6af601ec3ef9b'),
         datetime.date.today().year - 5)  # 5 years old
     self.assertIsInstance(vehicle_year_none, Vehicle)
     self.assertIsInstance(vehicle_next_year, Vehicle)
     self.assertIsInstance(vehicle_old, Vehicle)
Exemple #3
0
 def test_create_invalid_model(self):
     with self.assertRaises(VehicleExceptions) as e:
         VehicleFactory.create(
             'ABC1234',
             Customer('58355843690', 'Marcia Garcia',
                      '*****@*****.**',
                      '76e67f3c40024dfd94bdb71976022839'), None, 2018)
         e.msg = "invalid model - expected: None"
Exemple #4
0
 def test_create_model_year_as_string(self):
     with self.assertRaises(VehicleExceptions) as e:
         VehicleFactory.create(
             'ABC1234',
             Customer('58355843690', 'Marcia Garcia',
                      '*****@*****.**',
                      '76e67f3c40024dfd94bdb71976022839'),
             Model('HRV EX 1.8',
                   Brand('Honda', 'e29ed583b9a246a8a7f1596593bb7888'),
                   'b49aa1cb2082476bb3b6af601ec3ef9b'), 'new')
         e.msg = "invalid model year - expected: a string"
Exemple #5
0
 def __get_vehicle(self,
                   plate,
                   customer_id,
                   model_id,
                   model_year,
                   _id=None):
     owner = self.__customer_repo.get_by_id(customer_id)
     model = self.__model_repo.get_by_id(model_id)
     return VehicleFactory.create(plate, owner, model, model_year, _id)
Exemple #6
0
    def test_create_invalid_plate(self):
        with self.assertRaises(VehicleExceptions) as e:
            VehicleFactory.create(
                None,
                Customer('58355843690', 'Marcia Garcia',
                         '*****@*****.**',
                         '76e67f3c40024dfd94bdb71976022839'),
                Model('HRV EX 1.8',
                      Brand('Honda', 'e29ed583b9a246a8a7f1596593bb7888'),
                      'b49aa1cb2082476bb3b6af601ec3ef9b'), 2018)
            e.msg = "invalid plate - expected: None"

        with self.assertRaises(VehicleExceptions) as e:
            VehicleFactory.create(
                'AAB14',
                Customer('58355843690', 'Marcia Garcia',
                         '*****@*****.**',
                         '76e67f3c40024dfd94bdb71976022839'),
                Model('HRV EX 1.8',
                      Brand('Honda', 'e29ed583b9a246a8a7f1596593bb7888'),
                      'b49aa1cb2082476bb3b6af601ec3ef9b'), 2018)
            e.msg = "invalid plate - expected: a short plate"

        with self.assertRaises(VehicleExceptions) as e:
            VehicleFactory.create(
                'AB234',
                Customer('58355843690', 'Marcia Garcia',
                         '*****@*****.**',
                         '76e67f3c40024dfd94bdb71976022839'),
                Model('HRV EX 1.8',
                      Brand('Honda', 'e29ed583b9a246a8a7f1596593bb7888'),
                      'b49aa1cb2082476bb3b6af601ec3ef9b'), 2018)
            e.msg = "invalid plate - expected: a plate that no matching with format AAA1111 - 3 letters and 4 numbers"
Exemple #7
0
    def _convert_to_entity(self, json):
        if not json:
            return None

        owner = self.__customer_repo.get_by_id(json['owner_id'])
        model = self.__model_repo.get_by_id(json['model_id'])

        return VehicleFactory.create_from_db({
            '_id': json['_id'],
            'plate': json['plate'],
            'owner': owner,
            'model': model,
            'model_year': json['model_year']
        })
Exemple #8
0
 def test_create_from_db(self):
     vehicle = VehicleFactory.create_from_db(self.json)
     self.assertIsInstance(vehicle, Vehicle)
     self.assertEqual(vehicle._id, self.vehicle_with_id._id)