Пример #1
0
Файл: sql.py Проект: xpqz/sovoc
def document():
    doc = {
        '_id':
        uuid.uuid4().hex,
        '_rev':
        uuid.uuid4().hex,
        'description':
        chance.paragraph(),
        'date':
        chance.date(year=0, month=0, day=0, hour=0, minutes=0,
                    minyear=1985).strftime("%Y-%m-%d %H:%M:%S"),
        'firstname':
        chance.first(),
        'lastname':
        chance.last(),
        'email':
        chance.email(),
        'ip':
        chance.ip(),
        'rating': {
            'imdb': randint(0, 9),
            'rottentomatoes': randint(0, 9),
            'empire': randint(0, 9),
            'totalfilm': randint(0, 9),
            'guardian': randint(0, 9)
        },
        'data': [randint(0, 9) for _ in range(0, 10)]
    }

    return doc
Пример #2
0
 def create_user(self):
     user = User(
         first_name=chance.first(gender='m', language='ru'),
         last_name=chance.last(gender='m', language='ru'),
         email=chance.email(),
         is_active=True,
         is_email_confirmed=True,
     )
     user.set_password("@120804a")
     user.save()
     self.stdout.write('Successfully created user (%s)' % (user.email, ))
     return user
Пример #3
0
 def handle(self, *args, **kwargs):
     print("Starting Portal OpenStack Dev population script...")
     for p in range(0, 20):
         projectname = chance.word().upper()
         projectdescription = chance.sentence(language='en')
         department = chance.word().upper()
         username = chance.first().upper()
         password = pwdgen.get_random_string()
         firstname = username
         familyname = chance.last()
         emailaddress = chance.email()
         telephone = chance.phone(formatted=False)
         tos = True
         date_now = datetime.date.today()
         date = str(date_now)
         keystone = osauth.connect()
         keystone.projects.create(name=projectname,
                                  domain=settings.OPENSTACK_SANDBOX_DOMAIN,
                                  description=projectdescription,
                                  enabled=True,
                                  department=department,
                                  username=username,
                                  firstname=firstname,
                                  familyname=familyname,
                                  emailaddress=emailaddress,
                                  telephone=telephone,
                                  tos=tos,
                                  createddate=date,
                                  sandbox=True)
         project_id = keystone.projects.find(name=projectname).id
         keystone.users.create(name=username,
                               domain=settings.OPENSTACK_SANDBOX_DOMAIN,
                               default_project=project_id,
                               password=password,
                               email=emailaddress,
                               description="Sandbox User",
                               firstname=firstname,
                               familyname=familyname,
                               emailaddress=emailaddress,
                               telephone=telephone,
                               enabled=True,
                               createddate=date,
                               sandbox=True)
         role_id = keystone.roles.find(name='Member')
         user_id = keystone.users.find(name=username).id
         keystone.roles.grant(role_id, user=user_id, project=project_id)
Пример #4
0
def generate_data(input_names):
    # Mandatory data
    output_data = {}
    output_data["first_name"] = chance.pickone(input_names)
    output_data["last_name"] = chance.last()
    output_data["age"] = chance.age()
    output_data["email"] = chance.email()

    # Optional data
    optional_data = ["phone", "twitter", "country"]
    number_of_optional_data = random.randint(0, len(optional_data))
    for _ in range(number_of_optional_data):
        # Picks a random data to input
        random_index = random.randint(0, len(optional_data) - 1)
        random_choice = optional_data.pop(random_index)
        random_method = getattr(chance, random_choice)
        output_data[random_choice] = random_method()
    return output_data