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)
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)
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)
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)
def test_not_equal_garage_cars(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) garage3 = Garage(rnd_town(), rnd_int(), None) car4 = Car(rnd_float(), rnd_car_type(), rnd_car_producer(), rnd_float()) cesar2 = Cesar(name, garages, register_id) cesar2.add_car(car4, garage3) self.assertNotEqual(cesar1, cesar2)
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) separator() debug_instance_yaml('garage', garage1, Garage)