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())
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 setUp(self): """Generate some fake data.""" self.app = Flask('test') util.init_app(self.app) self.app.config['CLASSIC_DATABASE_URI'] = 'sqlite:///test.db' self.app.config['CLASSIC_SESSION_HASH'] = 'foohash' with self.app.app_context(): util.create_all() with util.transaction() as session: person = Person('en') net = Internet('en') ip_addr = net.ip_v4() email = person.email() approved = 1 deleted = 0 banned = 0 first_name = person.name() last_name = person.surname() suffix_name = person.title() joined_date = util.epoch( Datetime('en').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) self.user = domain.User(user_id=str(db_user.user_id), username='******', email=db_user.email, name=domain.UserFullName( forename=db_user.first_name, surname=db_user.last_name, suffix=db_user.suffix_name))
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()
def generate(): inserts = [] counter = 330 person = Person('en') business = Business('en') address = Address('en') internet = Internet('en') for index in range(counter, 15000, 1): inserts.append(template.substitute(id=index, name=person.name().replace("'", "''"), surname=person.surname().replace("'", "''"), email=person.email().replace("'", "''"), phone=person.telephone(), customer_id=random.randint(330, 14999) )) inserts_file = open('result_scripts/contacts.sql', 'w', encoding='utf-8') inserts_file.writelines('\n'.join(inserts)) inserts_file.close()
def users(count: int = 500) -> List[models.User]: """Generate a bunch of random users.""" _users = [] for i in range(count): locale = _get_locale() person = Person(locale) net = Internet(locale) ip_addr = net.ip_v4() _users.append( models.User( first_name=person.name(), last_name=person.surname(), suffix_name=person.title(), share_first_name=1, share_last_name=1, email=person.email(), share_email=8, email_bouncing=0, policy_class=2, # Public user. joined_date=_epoch(Datetime(locale).datetime()), joined_ip_num=ip_addr, joined_remote_host=ip_addr)) return _users
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()
def setUp(self): """Generate some fake data.""" self.app = Flask('test') util.init_app(self.app) self.app.config['CLASSIC_DATABASE_URI'] = 'sqlite:///test.db' self.app.config['CLASSIC_SESSION_HASH'] = 'foohash' with self.app.app_context(): util.create_all() with util.transaction() as session: person = Person('en') net = Internet('en') ip_addr = net.ip_v4() email = "*****@*****.**" approved = 1 deleted = 0 banned = 0 first_name = person.name() last_name = person.surname() suffix_name = person.title() joined_date = util.epoch( Datetime('en').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) self.user = domain.User(user_id=str(db_user.user_id), username='******', email=db_user.email, name=domain.UserFullName( forename=db_user.first_name, surname=db_user.last_name, suffix=db_user.suffix_name)) ok_patterns = ['%w3.org', '%aaas.org', '%agu.org', '%ams.org'] bad_patterns = ['%.com', '%.net', '%.biz.%'] with util.transaction() as session: for pattern in ok_patterns: session.add(models.DBEmailWhitelist(pattern=str(pattern))) for pattern in bad_patterns: session.add(models.DBEmailBlacklist(pattern=str(pattern))) session.add( models.DBEndorsementDomain( endorsement_domain='test_domain', endorse_all='n', mods_endorse_all='n', endorse_email='y', papers_to_endorse=3)) for category, definition in taxonomy.CATEGORIES_ACTIVE.items(): if '.' in category: archive, subject_class = category.split('.', 1) else: archive, subject_class = category, '' session.add( models.DBCategory(archive=archive, subject_class=subject_class, definitive=1, active=1, endorsement_domain='test_domain'))
from datetime import datetime as py_datetime from datetime import timedelta from mimesis import Address, Business, Datetime, Internet, Numbers, Person, Text, random person = Person() addr = Address() number = Numbers() business = Business() datetime = Datetime() internet = Internet() random = random.Random() text = Text() date_format = "%Y-%m-%d" def generate_car_data(): return dict(registration_number=generate_car_registration_code(), color=generate_car_color()) def generate_car_registration_code(): return random.custom_code(mask="@@-####") def generate_car_color(): return text.color() def generate_rent_data(car_id=None):
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), ))
def test_authenticate_and_use_session(self): """Attempt to authenticate users and create/load auth sessions.""" with self.app.app_context(): for datum in self.users: email, username, password, name, endorsement, status = datum approved, deleted, banned = status # Approved users may log in. if approved and not deleted and not banned: user, auths = authenticate.authenticate(email, password) self.assertIsInstance(user, domain.User, "User data is returned") self.assertEqual(user.email, email, "Email is set correctly") self.assertEqual(user.username, username, "Username is set correctly") first_name, last_name, suffix_name = name self.assertEqual(user.name.forename, first_name, "Forename is set correctly") self.assertEqual(user.name.surname, last_name, "Surname is set correctly") self.assertEqual(user.name.suffix, suffix_name, "Suffix is set correctly") self.assertIsInstance(auths, domain.Authorizations, "Authorizations data are returned") if endorsement[2] > 0: self.assertIn( domain.Category(archive=endorsement[0], subject=endorsement[1]), auths.endorsements, "Endorsements are included in authorizations") # Banned or deleted users may not log in. elif deleted or banned: with self.assertRaises(exceptions.AuthenticationFailed): authenticate.authenticate(email, password) continue # Users who are not approved may not log in. elif not approved: with self.assertRaises(exceptions.AuthenticationFailed): authenticate.authenticate(email, password) continue locale = _get_locale() net = Internet(locale) ip = net.ip_v4() session = sessions.create(auths, ip, ip, user=user) cookie = sessions.generate_cookie(session) session_loaded = sessions.load(cookie) self.assertEqual(session.user, session_loaded.user, "Loaded the correct user") self.assertEqual(session.session_id, session_loaded.session_id, "Loaded the correct session") # Invalidate 10% of the sessions, and try again. if _prob(10): sessions.invalidate(cookie) with self.assertRaises(exceptions.SessionExpired): sessions.load(cookie)
def _internets(self, seed): return Internet(seed=seed), Internet(seed=seed)
def pi_push_all_records(self, n_record_limit: int) -> bool: """ Called when a tool has no incoming data connection. :param n_record_limit: Set it to <0 for no limit, 0 for no records, and >0 to specify the number of records. :return: True for success, False for failure. """ if not self.is_initialized: return False # Save a reference to the RecordInfo passed into this function in the global namespace, so we can access it later. record_info_out = Sdk.RecordInfo(self.alteryx_engine) # Adds the new field to the record. for field in self.column_name: self.output_field = record_info_out.add_field(field, self.output_type, size=self.field_size) # Lets the downstream tools know what the outgoing record metadata will look like, based on record_info_out. self.output_anchor.init(record_info_out) # Creating a new, empty record creator based on record_info_out's record layout. record_creator = record_info_out.construct_record_creator() #import pdb; pdb.set_trace() #sophs code: for record in range(self.record_limit): for field in enumerate(record_info_out): if field[1].name == 'number_float': mimesis_object = Numbers() record_value = str( mimesis_object.float_number(end=10000, precision=6)) if field[1].name == 'number_float_positive': mimesis_object = Numbers() record_value = str( mimesis_object.float_number(start=0, end=10000, precision=6)) if field[1].name == 'number_int': mimesis_object = Numbers() record_value = str( mimesis_object.integer_number(start=-32767, end=32767)) if field[1].name == 'number_int_positive': mimesis_object = Numbers() record_value = str( mimesis_object.integer_number(start=0, end=32767)) if field[1].name == 'address_street_address': mimesis_object = Address(self.Locale) record_value = mimesis_object.address() if field[1].name == 'address_coordinates': mimesis_object = Address(self.Locale) record_value = str(mimesis_object.coordinates()) if field[1].name == 'address_country': mimesis_object = Address(self.Locale) record_value = mimesis_object.country(allow_random=True) if field[1].name == 'address_postal_code': mimesis_object = Address(self.Locale) record_value = mimesis_object.postal_code() if field[1].name == 'code_imei': mimesis_object = Code() record_value = mimesis_object.imei() if field[1].name == 'code_isbn': mimesis_object = Code() record_value = mimesis_object.isbn() if field[1].name == 'code_pin': mimesis_object = Code() record_value = mimesis_object.pin() if field[1].name == 'food_dish': mimesis_object = Food(self.Locale) record_value = mimesis_object.dish() if field[1].name == 'food_fruit': mimesis_object = Food(self.Locale) record_value = mimesis_object.fruit() if field[1].name == 'food_vegetables': mimesis_object = Food(self.Locale) record_value = mimesis_object.vegetable() if field[1].name == 'internet_url': mimesis_object = Internet() record_value = mimesis_object.home_page() if field[1].name == 'internet_ipv4': mimesis_object = Internet() record_value = mimesis_object.ip_v4() if field[1].name == 'internet_mac': mimesis_object = Internet() record_value = mimesis_object.mac_address() if field[1].name == 'person_blood_type': mimesis_object = Person(self.Locale) record_value = mimesis_object.blood_type() if field[1].name == 'person_email': mimesis_object = Person(self.Locale) record_value = mimesis_object.email() if field[1].name == 'person_full_name': mimesis_object = Person(self.Locale) record_value = mimesis_object.full_name() if field[1].name == 'person_nationality': mimesis_object = Person(self.Locale) record_value = mimesis_object.nationality() if field[1].name == 'person_occupation': mimesis_object = Person(self.Locale) record_value = mimesis_object.occupation() if field[1].name == 'person_telephone': mimesis_object = Person(self.Locale) record_value = mimesis_object.telephone() if field[1].name == 'science_atomic_number': mimesis_object = Science(self.Locale) record_value = str(mimesis_object.atomic_number()) if field[1].name == 'science_chemical_element': mimesis_object = Science(self.Locale) record_value = mimesis_object.chemical_element() if field[1].name == 'transport_airplane': mimesis_object = Transport() record_value = mimesis_object.airplane() if field[1].name == 'transport_car': mimesis_object = Transport() record_value = mimesis_object.car() if field[1].name == 'transport_truck': mimesis_object = Transport() record_value = mimesis_object.truck() if field[1].name == 'transport_vehicle_reg_code': mimesis_object = Transport() record_value = mimesis_object.vehicle_registration_code() if field[1].name == 'business_company_name': mimesis_object = Business() record_value = mimesis_object.company() if field[1].name == 'business_company_type': mimesis_object = Business() record_value = mimesis_object.company_type() if field[1].name == 'file_filename': mimesis_object = File() record_value = mimesis_object.file_name() if field[1].name == 'file_file_extension': mimesis_object = File() record_value = mimesis_object.extension() if field[1].name == 'file_mime_type': mimesis_object = File() record_value = mimesis_object.mime_type() if field[1].name == 'file_size': mimesis_object = File() record_value = mimesis_object.size() record_info_out[field[0]].set_from_string( record_creator, record_value) out_record = record_creator.finalize_record() self.output_anchor.push_record(out_record, False) record_creator.reset() # Make sure that the output anchor is closed. self.output_anchor.close() return True
def ii_push_record(self, in_record: object) -> bool: """ Responsible for pushing records out. Called when an input record is being sent to the plugin. :param in_record: The data for the incoming record. :return: False if there's a downstream error, or if there's an error with the field name, otherwise True. """ if not self.parent.is_initialized: return False #create the new fields record_value = None for field in enumerate(self.record_info_out): if field[1].name == 'number_float': mimesis_object = Numbers() record_value = str( mimesis_object.float_number(end=10000, precision=6)) if field[1].name == 'number_float_positive': mimesis_object = Numbers() record_value = str( mimesis_object.float_number(start=0, end=10000, precision=6)) if field[1].name == 'number_int': mimesis_object = Numbers() record_value = str( mimesis_object.integer_number(start=-32767, end=32767)) if field[1].name == 'number_int_positive': mimesis_object = Numbers() record_value = str( mimesis_object.integer_number(start=0, end=32767)) if field[1].name == 'address_street_address': mimesis_object = Address(self.Locale) record_value = mimesis_object.address() if field[1].name == 'address_coordinates': mimesis_object = Address(self.Locale) record_value = str(mimesis_object.coordinates()) if field[1].name == 'address_country': mimesis_object = Address(self.Locale) record_value = mimesis_object.country(allow_random=True) if field[1].name == 'address_postal_code': mimesis_object = Address(self.Locale) record_value = mimesis_object.postal_code() if field[1].name == 'code_imei': mimesis_object = Code() record_value = mimesis_object.imei() if field[1].name == 'code_isbn': mimesis_object = Code() record_value = mimesis_object.isbn() if field[1].name == 'code_pin': mimesis_object = Code() record_value = mimesis_object.pin() if field[1].name == 'food_dish': mimesis_object = Food(self.Locale) record_value = mimesis_object.dish() if field[1].name == 'food_fruit': mimesis_object = Food(self.Locale) record_value = mimesis_object.fruit() if field[1].name == 'food_vegetables': mimesis_object = Food(self.Locale) record_value = mimesis_object.vegetable() if field[1].name == 'internet_url': mimesis_object = Internet() record_value = mimesis_object.home_page() if field[1].name == 'internet_ipv4': mimesis_object = Internet() record_value = mimesis_object.ip_v4() if field[1].name == 'internet_mac': mimesis_object = Internet() record_value = mimesis_object.mac_address() if field[1].name == 'person_blood_type': mimesis_object = Person(self.Locale) record_value = mimesis_object.blood_type() if field[1].name == 'person_email': mimesis_object = Person(self.Locale) record_value = mimesis_object.email() if field[1].name == 'person_full_name': mimesis_object = Person(self.Locale) record_value = mimesis_object.full_name() if field[1].name == 'person_nationality': mimesis_object = Person(self.Locale) record_value = mimesis_object.nationality() if field[1].name == 'person_occupation': mimesis_object = Person(self.Locale) record_value = mimesis_object.occupation() if field[1].name == 'person_telephone': mimesis_object = Person(self.Locale) record_value = mimesis_object.telephone() if field[1].name == 'science_atomic_number': mimesis_object = Science(self.Locale) record_value = str(mimesis_object.atomic_number()) if field[1].name == 'science_chemical_element': mimesis_object = Science(self.Locale) record_value = mimesis_object.chemical_element() if field[1].name == 'transport_airplane': mimesis_object = Transport() record_value = mimesis_object.airplane() if field[1].name == 'transport_car': mimesis_object = Transport() record_value = mimesis_object.car() if field[1].name == 'transport_truck': mimesis_object = Transport() record_value = mimesis_object.truck() if field[1].name == 'transport_vehicle_reg_code': mimesis_object = Transport() record_value = mimesis_object.vehicle_registration_code() if field[1].name == 'business_company_name': mimesis_object = Business() record_value = mimesis_object.company() if field[1].name == 'business_company_type': mimesis_object = Business() record_value = mimesis_object.company_type() if field[1].name == 'file_filename': mimesis_object = File() record_value = mimesis_object.file_name() if field[1].name == 'file_file_extension': mimesis_object = File() record_value = mimesis_object.extension() if field[1].name == 'file_mime_type': mimesis_object = File() record_value = mimesis_object.mime_type() if field[1].name == 'file_size': mimesis_object = File() record_value = mimesis_object.size() self.record_info_out[field[0]].set_from_string( self.record_creator, record_value) out_record = self.record_creator.finalize_record() #self.parent.output_anchor.push_record(out_record, False) self.record_creator.reset() # Copy the data from the incoming record into the outgoing record. self.record_creator.reset() self.record_copier.done_adding() self.record_copier.copy(self.record_creator, in_record) # Push the record downstream and quit if there's a downstream error. if not self.parent.output_anchor.push_record(out_record): return False return True
def net(self): return Internet()
def net(): return Internet()
def i2(self, seed): return Internet(seed=seed)
def internet(): """ :return: """ return Internet()