Esempio n. 1
0
    def test_init_add_car_instance(self):
        cesar = Cesar(rnd_name())
        car = Car(rnd_float(), rnd_car_type(), rnd_car_producer(), rnd_float())

        for value in [1000, 'some string', [car]]:
            with self.assertRaises(TypeError):
                cesar.add_car(value)
Esempio n. 2
0
    def test_set_register_id(self):
        cesar = Cesar(rnd_name())
        new_register_id = rnd_uuid()
        cesar.set_register_id(new_register_id)

        self.assertEqual(cesar.register_id, new_register_id)
        self.assertIsInstance(cesar.register_id, uuid.UUID)
Esempio n. 3
0
    def test_yaml_serialize(self):
        filename = 'cesar.yaml'

        cesar_from_yaml = Cesar.from_yaml_file(filename)

        with open(get_dump_path(filename)) as f:
            cesar_json = yaml.load(f.read(), Loader=yaml.FullLoader)

        garages = []
        for garage_json in cesar_json.get('garages'):
            cars = []
            for car_json in garage_json.get('cars'):
                car = Car(price=car_json.get('price'),
                          car_type=car_json.get('car_type'),
                          producer=car_json.get('producer'),
                          mileage=car_json.get('mileage'),
                          number=car_json.get('number'))
                cars.append(car)
            garage = Garage(town=garage_json.get('town'),
                            places=garage_json.get('places'),
                            owner=garage_json.get('owner'),
                            cars=cars,
                            number=garage_json.get('number'))
            garages.append(garage)
        cesar = Cesar(name=cesar_json.get('name'),
                      garages=garages,
                      register_id=cesar_json.get('register_id'))

        self.assertEqual(cesar, cesar_from_yaml)
Esempio n. 4
0
    def test_init_add_garage_instance(self):
        cesar = Cesar(rnd_name())
        garage = Garage(rnd_town(), rnd_int())

        for value in [1000, 'some string', [garage]]:
            with self.assertRaises(TypeError):
                cesar.add_garage(value)
Esempio n. 5
0
    def test_init_add_car_garage_instance(self):
        cesar = Cesar(rnd_name())
        garage = Garage(rnd_town(), rnd_int(), rnd_uuid())
        car = Car(rnd_float(), rnd_car_type(), rnd_car_producer(), rnd_float())

        for value in [1000, 'some string', [garage]]:
            with self.assertRaises(TypeError):
                cesar.add_car(car, value)
Esempio n. 6
0
    def test_hit_hat(self):
        car1 = Car(1000.0, rnd_car_type(), rnd_car_producer(), rnd_float())
        car2 = Car(2000.0, rnd_car_type(), rnd_car_producer(), rnd_float())
        car3 = Car(3000.0, rnd_car_type(), rnd_car_producer(), rnd_float())

        garage1 = Garage(rnd_town(), rnd_int(), rnd_uuid(), [car1])
        garage2 = Garage(rnd_town(), rnd_int(), rnd_uuid(), [car2, car3])
        cesar = Cesar(rnd_name(), [garage1, garage2])

        self.assertEqual(cesar.hit_hat(), 6000)
Esempio n. 7
0
    def test_cars_count(self):
        car1 = Car(rnd_float(), rnd_car_type(), rnd_car_producer(),
                   rnd_float())
        car2 = Car(rnd_float(), rnd_car_type(), rnd_car_producer(),
                   rnd_float())
        car3 = Car(rnd_float(), rnd_car_type(), rnd_car_producer(),
                   rnd_float())

        garage1 = Garage(rnd_town(), rnd_int(), rnd_uuid(), [car1])
        garage2 = Garage(rnd_town(), rnd_int(), rnd_uuid(), [car2, car3])
        cesar = Cesar(rnd_name(), [garage1, garage2])

        self.assertEqual(cesar.cars_count(), 3)
Esempio n. 8
0
    def test_init_add_garage(self):
        garage1 = Garage(rnd_town(), rnd_int())
        garage2 = Garage(rnd_town(), rnd_int())
        cesar = Cesar(rnd_name(), [garage1])

        self.assertFalse(cesar.add_garage(garage1))
        self.assertTrue(cesar.add_garage(garage2))

        self.assertEqual(cesar.register_id, garage1.owner)
        self.assertEqual(cesar.register_id, garage2.owner)

        self.assertTrue(garage1.number in cesar.garages)
        self.assertTrue(garage2.number in cesar.garages)
Esempio n. 9
0
    def test_not_equal_register_id(self):
        car1 = Car(rnd_float(), rnd_car_type(), rnd_car_producer(),
                   rnd_float())
        car2 = Car(rnd_float(), rnd_car_type(), rnd_car_producer(),
                   rnd_float())
        car3 = Car(rnd_float(), rnd_car_type(), rnd_car_producer(),
                   rnd_float())
        garage1 = Garage(rnd_town(), rnd_int(), None, [car1, car2])
        garage2 = Garage(rnd_town(), rnd_int(), None, [car3])

        name = rnd_name()
        garages = [garage1, garage2]
        register_id = rnd_uuid()

        cesar1 = Cesar(name, garages, register_id)
        cesar2 = Cesar(name, garages, rnd_uuid())
        self.assertNotEqual(cesar1, cesar2)
Esempio n. 10
0
    def test_comparison(self):
        car1 = Car(1000.0, rnd_car_type(), rnd_car_producer(), rnd_float())
        car2 = Car(2000.0, rnd_car_type(), rnd_car_producer(), rnd_float())
        garage1 = Garage(rnd_town(), rnd_int(), rnd_uuid(), [car1, car2])
        cesar1 = Cesar(rnd_name(), [garage1])

        car1 = Car(1000.0, rnd_car_type(), rnd_car_producer(), rnd_float())
        car2 = Car(3000.0, rnd_car_type(), rnd_car_producer(), rnd_float())
        garage1 = Garage(rnd_town(), rnd_int(), rnd_uuid(), [car1, car2])
        cesar2 = Cesar(rnd_name(), [garage1])

        car1 = Car(2000.0, rnd_car_type(), rnd_car_producer(), rnd_float())
        car2 = Car(1000.0, rnd_car_type(), rnd_car_producer(), rnd_float())
        garage1 = Garage(rnd_town(), rnd_int(), rnd_uuid(), [car1, car2])
        cesar3 = Cesar(rnd_name(), [garage1])

        self.assertGreater(cesar2, cesar1)
        self.assertGreaterEqual(cesar1, cesar3)
        self.assertLess(cesar1, cesar2)
        self.assertLessEqual(cesar1, cesar3)
Esempio n. 11
0
    def test_set_owner(self):
        garage = Garage(rnd_town(), rnd_int(), rnd_uuid())

        new_owner = rnd_uuid()
        garage.set_owner(new_owner)
        self.assertEqual(garage.owner, new_owner)
        self.assertIsInstance(garage.owner, uuid.UUID)

        cesar = Cesar('Test')
        garage.set_owner(cesar)
        self.assertEqual(garage.owner, cesar.register_id)
        self.assertIsInstance(garage.owner, uuid.UUID)
Esempio n. 12
0
    def test_init_add_car(self):
        garage1 = Garage(rnd_town(), 1)
        garage2 = Garage(rnd_town(), 2)
        cesar = Cesar(rnd_name(), [garage1])

        car1 = Car(rnd_float(), rnd_car_type(), rnd_car_producer(),
                   rnd_float())
        car2 = Car(rnd_float(), rnd_car_type(), rnd_car_producer(),
                   rnd_float())
        car3 = Car(rnd_float(), rnd_car_type(), rnd_car_producer(),
                   rnd_float())

        cesar.add_car(car1, garage1)
        cesar.add_car(car2, garage2)
        cesar.add_car(car3, garage2)

        self.assertEqual(cesar.register_id, garage1.owner)
        self.assertEqual(cesar.register_id, garage2.owner)

        self.assertEqual(garage1.cars_count(), 1)
        self.assertEqual(garage2.cars_count(), 2)

        self.assertTrue(car1.number in garage1.cars)
        self.assertTrue(car2.number in garage2.cars)
        self.assertTrue(car3.number in garage2.cars)
Esempio n. 13
0
    def test_init_add_car_emptiest_garage(self):
        garage1 = Garage(rnd_town(), 1, rnd_uuid())
        garage2 = Garage(rnd_town(), 2, rnd_uuid())
        garage3 = Garage(rnd_town(), 3, rnd_uuid())
        cesar = Cesar(rnd_name(), [garage1, garage2, garage3])

        car1 = Car(rnd_float(), rnd_car_type(), rnd_car_producer(),
                   rnd_float())
        car2 = Car(rnd_float(), rnd_car_type(), rnd_car_producer(),
                   rnd_float())

        cesar.add_car(car1)
        self.assertEqual(garage1.places_count(), 1)
        self.assertEqual(garage2.places_count(), 2)
        self.assertEqual(garage3.places_count(), 2)

        cesar.add_car(car2)
        self.assertEqual(garage1.places_count(), 1)
        self.assertEqual(garage2.places_count(), 1)
        self.assertEqual(garage3.places_count(), 2)
Esempio n. 14
0
               producer=random.choice(CARS_PRODUCER),
               mileage=random.uniform(1000, 5000))
    car3 = Car(price=random.uniform(5000, 50000),
               car_type=random.choice(CARS_TYPES),
               producer=random.choice(CARS_PRODUCER),
               mileage=random.uniform(1000, 5000))
    car4 = Car(price=random.uniform(5000, 50000),
               car_type=random.choice(CARS_TYPES),
               producer=random.choice(CARS_PRODUCER),
               mileage=random.uniform(1000, 5000))

    garage1 = Garage(town=random.choice(TOWNS), places=2)
    garage2 = Garage(town=random.choice(TOWNS), places=3)
    garage3 = Garage(town=random.choice(TOWNS), places=4)

    cesar1 = Cesar(name="John")

    cesar1.add_car(car1, garage1)
    cesar1.add_car(car2, garage1)
    cesar1.add_car(car3, garage2)
    cesar1.add_car(car4, garage3)

    print("\n\t ### JSON ###")
    debug_instance_json('car', car1, Car)
    separator()
    debug_instance_json('garage', garage1, Garage)
    separator()
    debug_instance_json('cesar', cesar1, Cesar)

    print("\n\t ### YAML ###")
    debug_instance_yaml('car', car1, Car)
Esempio n. 15
0
 def test_init_with_invalid_name(self):
     for value in [1000, 11.23, False]:
         with self.assertRaises(ValueError):
             Cesar(value)
Esempio n. 16
0
 def test_init_with_invalid_garages(self):
     garage1 = Garage(rnd_town(), rnd_int(), rnd_uuid())
     for value in ['My Garage', garage1, {'garage': garage1}]:
         with self.assertRaises(ValueError):
             Cesar(rnd_name(), [], value)
Esempio n. 17
0
 def test_init_with_invalid_register_id(self):
     for value in [1000, 'some string']:
         with self.assertRaises(ValueError):
             Cesar(rnd_name(), [], value)
Esempio n. 18
0
    def test_garages_count(self):
        garage1 = Garage(rnd_town(), rnd_int())
        garage2 = Garage(rnd_town(), rnd_int())
        cesar = Cesar(rnd_name(), [garage1, garage2])

        self.assertEqual(cesar.garages_count(), 2)