Ejemplo n.º 1
0
    def handle(self, *args, **options):
        driver_group = Group.objects.get(name=Groups.Driver.name)
        passenger_group = Group.objects.get(name=Groups.Passenger.name)

        self.stdout.write(self.style.SUCCESS('Creating 5 cars'))
        for _ in tqdm(range(5)):
            CarFactory.create()

        self.stdout.write(self.style.SUCCESS('Creating 5 drivers'))
        drivers = []
        for _ in tqdm(range(5)):
            drivers.append(UserFactory.create(groups=[driver_group]).username)

        passengers = []
        self.stdout.write(self.style.SUCCESS('Creating 10 passengers'))
        for _ in tqdm(range(10)):
            passengers.append(
                UserFactory.create(groups=[passenger_group]).username)

        self.stdout.write(self.style.SUCCESS('Creating 5 projects'))
        for _ in tqdm(range(5)):
            ProjectFactory.create()

        self.stdout.write(self.style.SUCCESS('Creating 50 drives'))
        all_drivers = list(User.objects.filter(groups=driver_group))
        all_passengers = list(User.objects.filter(groups=passenger_group))
        all_projects = list(Project.objects.all())

        for _ in tqdm(range(50)):
            DriveFactory.create(
                passenger=random.choice(all_passengers),
                project=random.choice(all_projects),
                driver=random.choice(all_drivers),
            )

        self.stdout.write(
            self.style.SUCCESS('Database successfully populated'))

        self.stdout.write('=' * 50)
        self.stdout.write(self.style.SUCCESS('Newly created drivers:'))
        for index, username in enumerate(drivers):
            self.stdout.write(
                self.style.SUCCESS('{index}. {username}'.format(
                    index=index,
                    username=username,
                )))

        self.stdout.write(self.style.SUCCESS('Newly created passengers:'))
        for index, username in enumerate(passengers):
            self.stdout.write(
                self.style.SUCCESS('{index}. {username}'.format(
                    index=index,
                    username=username,
                )))

        default_user = User.objects.filter(
            email='*****@*****.**').first()

        driver_group.user_set.add(default_user)
        passenger_group.user_set.add(default_user)
Ejemplo n.º 2
0
    def setUp(self):
        self.url = reverse("refuels")
        self.user = UserFactory.create(
            groups=[Group.objects.get(name=Groups.Driver.name)])
        self.refuels = RefuelFactory.create_batch(size=3)

        self.car = CarFactory.create()
        self.driver = UserFactory.create()
        self.total_cost = Money(25, "PLN")
Ejemplo n.º 3
0
    def handle(self, *args, **options):
        """Populate database with fake objects."""

        self.stdout.write(self.style.SUCCESS('Creating 30 cars'))
        for _ in tqdm(range(30)):
            CarFactory.create()

        self.stdout.write(self.style.SUCCESS('Creating 50 users'))
        usernames = []
        for _ in tqdm(range(50)):
            usernames.append(UserFactory.create().username)

        self.stdout.write(self.style.SUCCESS('Creating 150 passengers'))
        for _ in tqdm(range(150)):
            PassengerFactory.create()

        self.stdout.write(self.style.SUCCESS('Creating 30 projects'))
        for _ in tqdm(range(30)):
            ProjectFactory.create()

        self.stdout.write(self.style.SUCCESS('Creating 500 drives'))
        all_users = list(User.objects.all())
        all_passengers = list(Passenger.objects.all())
        all_projects = list(Project.objects.all())

        for _ in tqdm(range(500)):
            DriveFactory.create(
                passengers=random.sample(all_passengers, random.randint(1, 4)),
                project=random.choice(all_projects),
                driver=random.choice(all_users),
            )

        self.stdout.write(
            self.style.SUCCESS('Database successfully populated'))

        self.stdout.write('=' * 50)
        self.stdout.write(self.style.SUCCESS('Newly created users:'))
        for index, username in enumerate(usernames):
            self.stdout.write(
                self.style.SUCCESS('{index}. {username}'.format(
                    index=index,
                    username=username,
                )))
Ejemplo n.º 4
0
    def setUp(self):
        self.url = reverse("drives")
        self.drivers_group = Group.objects.get(name=Groups.Driver.name)
        self.passengers_group = Group.objects.get(name=Groups.Passenger.name)

        self.car = CarFactory.make(id=29)
        self.project = ProjectFactory.make(id=42, country="UA")
        self.driver = UserFactory.make(id=51, groups=[self.drivers_group])
        self.passenger = UserFactory.make(
            id=35,
            rsa_pub_e=257,
            rsa_priv_d=30593,
            rsa_modulus_n=50927,
            groups=[self.passengers_group],
        )
        self.drives = DriveFactory.make_batch(size=10,
                                              driver=self.driver,
                                              passenger=self.passenger)
Ejemplo n.º 5
0
 def setUp(self):
     self.url = reverse("cars")
     self.user = UserFactory.make(
         groups=[Group.objects.get(name=Groups.Driver.name)])
     self.cars = CarFactory.make_batch(size=3, country=self.user.country)
Ejemplo n.º 6
0
    def handle(self, *args, **options):
        driver_group = Group.objects.get(name=Groups.Driver.name)
        passenger_group = Group.objects.get(name=Groups.Passenger.name)

        def info(message):
            self.stdout.write(self.style.SUCCESS(message))

        cars = [
            CarFactory.create(
                plates="UA000000",
                description="Default Car",
                fuel_consumption=10.0,
                country="UA",
            ),
        ]
        info("Creating 5 random cars")
        for _ in tqdm(range(5)):
            cars.append(CarFactory.create())

        drivers = [
            UserFactory.create(
                username="******",
                first_name="Default",
                last_name="Driver",
                country="UA",
                groups=[driver_group],
            ),
        ]
        info("Creating 5 random drivers")
        for _ in tqdm(range(5)):
            drivers.append(UserFactory.create(groups=[driver_group]))

        passengers = [
            UserFactory.create(
                username="******",
                first_name="Default",
                last_name="Passenger",
                country="UA",
                groups=[passenger_group],
            ),
        ]
        info("Creating 5 random passengers")
        for _ in tqdm(range(5)):
            passengers.append(UserFactory.create(groups=[passenger_group]))

        projects = [
            ProjectFactory.create(
                title="Default Project", description="Default Project", country="UA",
            )
        ]
        info("Creating 5 random projects")
        for _ in tqdm(range(5)):
            projects.append(ProjectFactory.create())

        DriveFactory.create(
            driver=drivers[0],
            project=projects[0],
            passenger=passengers[0],
            car=cars[0],
            start_mileage=1,
            end_mileage=100,
            description="Default verified drive",
            start_location="Start",
            end_location="End",
            is_verified=True,
        )
        DriveFactory.create(
            driver=drivers[0],
            project=projects[0],
            passenger=passengers[0],
            car=cars[0],
            start_mileage=1,
            end_mileage=100,
            description="Default unverified drive",
            start_location="Start",
            end_location="End",
            is_verified=False,
        )
        info("Creating 50 random drives")
        for _ in tqdm(range(50)):
            DriveFactory.create(
                passenger=random.choice(passengers),
                project=random.choice(projects),
                driver=random.choice(drivers),
                car=random.choice(cars),
            )

        info("Database successfully populated with random data")
        info("=" * 60)

        info(f"{'Newly created drivers (username : password)':>56}")
        for index, user in enumerate(drivers, start=1):
            info(f"{index:02d}. {user.username:>40} : {UserFactory.password}")

        info("=" * 60)

        info(f"{'Newly created passengers (username : password)':>56}")
        for index, user in enumerate(passengers, start=1):
            info(f"{index:02d}. {user.username:>40} : {UserFactory.password}")