def run():
    person = Person()
    text = Text()
    internet = Internet()
    dateTime = Datetime()

    for i in range(100):
        User.objects.create(password="******",
                            username=person.username(),
                            first_name=person.name(),
                            last_name=person.last_name(),
                            email=person.email())

    users = User.objects.all()

    for i in range(100):
        Post.objects.create(author=choice(users),
                            link=internet.home_page(),
                            title=text.title(),
                            description=text.text())

    posts = Post.objects.all()

    for i in range(100):
        Comment.objects.create(author=choice(users),
                               post=choice(posts),
                               description=text.text())
Esempio n. 2
0
class CSVData:
    def __init__(self):
        self.person = Person(locale='zh')
        self.address = Address(locale='zh')
        self.code = Code()
        self.business = Business(locale='zh')
        self.text = Text(locale='zh')
        self.datetime = Datetime(locale='zh')
        self.file = File()
        self.path = Path()
        self.internet = Internet()
        self.structure = Structure()

    def mime_data(self):
        # col1 = self.person.full_name()
        col1 = self.person.last_name() + self.person.first_name()
        col2 = self.address.city()
        col3 = self.address.street_name()
        col4 = self.address.calling_code()
        col5 = self.address.longitude()
        col6 = self.code.imei()
        col7 = self.business.company()
        col8 = self.text.hex_color()
        col9 = self.datetime.formatted_datetime()
        col10 = self.datetime.time()

        col11 = self.file.file_name()
        col12 = self.path.dev_dir()
        col13 = self.internet.ip_v4()
        col14 = self.internet.ip_v6()
        col15 = self.internet.home_page()
        col16 = self.internet.stock_image()
        col17 = self.internet.user_agent()
        col18 = self.internet.mac_address()
        col19 = self.person.email()
        col20 = self.person.telephone()

        col21 = self.code.issn()
        col22 = self.person.social_media_profile()
        col23 = self.structure.html()

        line = '\"{0}\", \"{1}\", \"{2}\", \"{3}\", {4}, \"{5}\", \"{6}\" , \"{7}\" , \"{8}\" , \"{9}\" , \"{10}\" , \"{11}\" , \"{12}\" , \"{13}\" , \"{14}\" , \"{15}\" , \"{16}\" , \"{17}\" , \"{18}\" , \"{19}\" , \"{20}\" , \"{21}\" , \"{22}\"\n'.format(
                col1, col2, col3, col4, col5, col6, col7, col8, col9, col10, col11, col12, col13, col14, col15, col16, col17, col18, col19, col20, col21, col22, col23)

        # line = "mime data"
        # print(line)
        return line
Esempio n. 3
0
def generate():
    inserts = []
    counter = 350

    business = Business('en')
    address = Address('en')
    internet = Internet('en')

    for index in range(counter, 15000, 1):
        inserts.append(
            template.substitute(id=index,
                                name=business.company().replace("'", "''"),
                                address=address.address().replace("'", "''"),
                                credit=random.randint(300, 1000000),
                                website=internet.home_page().replace(
                                    "'", "''")))

    inserts_file = open('result_scripts/customers.sql', 'w', encoding='utf-8')
    inserts_file.writelines('\n'.join(inserts))
    inserts_file.close()
Esempio n. 4
0
 def handle(self, *args, **kwargs):
     internet = Internet()
     text = Text()
     total = kwargs['total']
     for i in range(total):
         project = Project(title=text.title(),
                           repository=internet.home_page(),
                           text=text.words(quantity=5))
         project.save()
         random_user_list = []
         for _ in range(random.randint(1, 5)):
             random_user_list.append(
                 str(random.choice(User.objects.values_list('uuid'))[0]))
         project.users.set(random_user_list)
         for _ in range(random.randint(1, 5)):
             todo = Todo(
                 todo=text.title(),
                 text=text.text(quantity=2),
                 project=project,
                 user=User.objects.get(uuid=random.choice(
                     User.objects.values_list('uuid'))[0]),
             )
             todo.save()
Esempio n. 5
0
    def setUpClass(cls):
        """Generate some fake data."""
        cls.app = Flask('test')
        util.init_app(cls.app)
        cls.app.config['CLASSIC_DATABASE_URI'] = 'sqlite:///test.db'
        cls.app.config['CLASSIC_SESSION_HASH'] = 'foohash'
        cls.app.config['CLASSIC_SESSION_TIMEOUT'] = '36000'

        with cls.app.app_context():
            util.create_all()
            COUNT = 50

            cls.users = []

            _users = []
            _domain_users = []
            for i in range(COUNT):
                with util.transaction() as session:
                    locale = _get_locale()
                    person = Person(locale)
                    net = Internet(locale)
                    ip_addr = net.ip_v4()
                    email = person.email()
                    approved = 1 if _prob(90) else 0
                    deleted = 1 if _prob(2) else 0
                    banned = 1 if random.randint(0, 100) <= 1 else 0
                    first_name = person.name()
                    last_name = person.surname()
                    suffix_name = person.title()
                    name = (first_name, last_name, suffix_name)
                    joined_date = util.epoch(
                        Datetime(locale).datetime().replace(tzinfo=EASTERN))
                    db_user = models.DBUser(
                        first_name=first_name,
                        last_name=last_name,
                        suffix_name=suffix_name,
                        share_first_name=1,
                        share_last_name=1,
                        email=email,
                        flag_approved=approved,
                        flag_deleted=deleted,
                        flag_banned=banned,
                        flag_edit_users=0,
                        flag_edit_system=0,
                        flag_email_verified=1,
                        share_email=8,
                        email_bouncing=0,
                        policy_class=2,  # Public user. TODO: consider admin.
                        joined_date=joined_date,
                        joined_ip_num=ip_addr,
                        joined_remote_host=ip_addr)
                    session.add(db_user)

                    # Create a username.
                    username_is_valid = 1 if _prob(90) else 0
                    username = person.username()
                    db_nick = models.DBUserNickname(
                        user=db_user,
                        nickname=username,
                        flag_valid=username_is_valid,
                        flag_primary=1)

                    # Create the user's profile.
                    archive, subject_class = _random_category()
                    db_profile = models.DBProfile(
                        user=db_user,
                        country=locale,
                        affiliation=person.university(),
                        url=net.home_page(),
                        rank=random.randint(1, 5),
                        archive=archive,
                        subject_class=subject_class,
                        original_subject_classes='',
                        flag_group_math=1 if _prob(5) else 0,
                        flag_group_cs=1 if _prob(5) else 0,
                        flag_group_nlin=1 if _prob(5) else 0,
                        flag_group_q_bio=1 if _prob(5) else 0,
                        flag_group_q_fin=1 if _prob(5) else 0,
                        flag_group_stat=1 if _prob(5) else 0)

                    # Set the user's password.
                    password = person.password()
                    db_password = models.DBUserPassword(
                        user=db_user,
                        password_storage=2,
                        password_enc=util.hash_password(password))

                    # Create some endorsements.
                    archive, subject_class = _random_category()
                    net_points = 0
                    for _ in range(0, random.randint(1, 4)):
                        etype = random.choice(['auto', 'user', 'admin'])
                        point_value = random.randint(-10, 10)
                        net_points += point_value
                        if len(_users) > 0 and etype == 'auto':
                            endorser_id = random.choice(_users).user_id
                        else:
                            endorser_id = None
                        issued_when = util.epoch(
                            Datetime(locale).datetime().replace(
                                tzinfo=EASTERN))
                        session.add(
                            models.DBEndorsement(endorsee=db_user,
                                                 endorser_id=endorser_id,
                                                 archive=archive,
                                                 subject_class=subject_class,
                                                 flag_valid=1,
                                                 endorsement_type=etype,
                                                 point_value=point_value,
                                                 issued_when=issued_when))

                    session.add(db_password)
                    session.add(db_nick)
                    session.add(db_profile)
                    _users.append(db_user)
                    _domain_users.append(
                        (domain.User(user_id=str(db_user.user_id),
                                     username=db_nick.nickname,
                                     email=db_user.email,
                                     name=domain.UserFullName(
                                         forename=db_user.first_name,
                                         surname=db_user.last_name,
                                         suffix=db_user.suffix_name),
                                     verified=bool(
                                         db_user.flag_email_verified)),
                         domain.Authorizations(
                             classic=util.compute_capabilities(db_user), )))
                    session.commit()
                    # We'll use these data to run tests.
                    cls.users.append((
                        email,
                        username,
                        password,
                        name,
                        (archive, subject_class, net_points),
                        (approved, deleted, banned),
                    ))