legacy/pairent_backend/pairent_app/factories.py

84 lines
2.7 KiB
Python
Raw Normal View History

2023-05-05 13:03:33 +02:00
import factory
2023-05-07 08:35:50 +02:00
import random
import time, datetime
from django.db import models
2023-05-05 13:03:33 +02:00
from pairent_app.models import Apartament
2023-05-05 14:08:27 +02:00
factory.Faker.override_default_locale('ru_RU');
2023-05-07 08:35:50 +02:00
class PhoneNumber(factory.declarations.BaseDeclaration):
def evaluate(self, instance, step, extra):
return '+799' + str(random.randint(0, 99999999)).zfill(8);
class Random(factory.declarations.BaseDeclaration):
def __init__(self, min, max = None, multiply = 1):
if (max == None):
self.min = 0;
self.max = min;
else:
self.min = min;
self.max = max;
self.multiply = multiply;
super().__init__();
def evaluate(self, instance, step, extra):
if (self.multiply != None):
return random.randint(self.min, self.max) * self.multiply;
return random.randint(self.min, self.max);
class Date(factory.declarations.BaseDeclaration):
def evaluate(self, instance, step, extra):
# year_before = time.time() - (60 * 60 * 24 * 30 * 12);
return datetime.datetime(2023, random.randint(1,12), random.randint(1,27)).strftime("%G-%m-%d");
2023-05-05 13:03:33 +02:00
class ApartmentFactory(factory.django.DjangoModelFactory):
class Meta:
model = Apartament
# Base data
2023-05-07 08:35:50 +02:00
price = Random(3,10,5000);
lastPrice = Random(3,10,5000);
bail = Random(2,10,1000);
agencyCommission = Random(3,5,2500);
utilitiesPrice = Random(4,8,1000)
minimumLeasePeriod = Random(1,2,6);
address = factory.Faker('address', locale='ru_RU');
description = factory.Faker('sentence', locale='ru_RU');
perimetrs = Random(15,40);
rooms = Random(0,4);
ceilingHeight = Random(3,5);
floorHouse = Random(2,20);
floor = Random(2,20);
2023-05-05 13:03:33 +02:00
2023-05-07 08:35:50 +02:00
phoneNumber = PhoneNumber()
2023-05-05 13:03:33 +02:00
2023-05-07 08:35:50 +02:00
timeToBus = Random(1, 12, 5);
timeToTrain = Random(1, 12, 5);
2023-05-05 13:03:33 +02:00
# Apartment props
2023-05-07 08:35:50 +02:00
isFurniture = Random(0, 1);
isAnimal = Random(0, 1);
isTelevision = Random(0, 1);
isChild = Random(0, 1);
isInternet = Random(0, 1);
isBathroom = Random(0, 1);
isRefrigerator = Random(0, 1);
isWasher = Random(0, 1);
isAirConditioning = Random(0, 1);
isFreshRepair = Random(0, 1);
2023-05-05 13:03:33 +02:00
# House props
2023-05-07 08:35:50 +02:00
isElevator = Random(0, 1);
isParking = Random(0, 1);
isGarbageChute = Random(0, 1);
isConcierge = Random(0, 1);
2023-05-05 13:03:33 +02:00
2023-05-07 08:35:50 +02:00
# views = [] # factory.Faker('random_number')
2023-05-05 13:03:33 +02:00
2023-05-07 08:35:50 +02:00
dateCreate = Date()