finish off user faker

This commit is contained in:
b1ek 2023-05-15 13:18:08 +10:00
parent ec152afe55
commit d9384f0b33
Signed by: blek
GPG Key ID: 14546221E3595D0C
1 changed files with 9 additions and 7 deletions

View File

@ -19,12 +19,14 @@ class PhoneNumber(factory.declarations.BaseDeclaration):
class CSV(factory.declarations.BaseDeclaration):
def __init__(self, min, max, count_min, count_max):
self.min = min; self.max = max;
self.count_min = count_min; self.count_max: count_max;
self.count_min = count_min;
self.count_max = count_max;
super().__init__();
def evaluate(self, instance, step, extra):
len_ = random.randint(self.count_min, self.count_max);
out = [];
for i in range(len): out.append(random.randint(self.min, self.max));
for i in range(len_): out.append(str(random.randint(self.min, self.max)));
return ','.join(out);
class Random(factory.declarations.BaseDeclaration):
@ -37,7 +39,7 @@ class Random(factory.declarations.BaseDeclaration):
self.max = max;
self.multiply = multiply;
self.list = list;
super().__init__(self);
super().__init__();
def evaluate(self, instance, step, extra):
if (type(self.list) == list):
@ -49,10 +51,10 @@ class Random(factory.declarations.BaseDeclaration):
class Date(factory.declarations.BaseDeclaration):
def __init__(self, min_year = 2022, max_year = datetime.date().year):
def __init__(self, min_year = 2022, max_year = datetime.date.today().year):
self.min_year = min_year;
self.max_year = max_year;
super().__init__(self);
super().__init__();
def evaluate(self, instance, step, extra):
return datetime.datetime(random.randint(self.min_year, self.max_year), random.randint(1,12), random.randint(1,27)).strftime("%G-%m-%d");
@ -111,10 +113,10 @@ class UserFactory(factory.django.DjangoModelFactory):
class Meta:
model = User
favorites_aparments = CSV(1, 100, 1, 16);
favorites_apartments = CSV(1, 100, 1, 16);
comparison_apartments = CSV(1, 100, 1, 5);
psych_test_result = Random(20, 90);
vvsu_id = OpenID_Address();
openid_addr = OpenID_Address();
name = factory.faker.Faker('name');
date_of_birth = Date(1980, 2006);
about_me = factory.faker.Faker('sentence');