class RepoFactory(BaseFactory): id = FuzzyInteger(999999) name = FuzzyText(length=8) owner = factory.SubFactory(UserFactory) owner_login = factory.LazyAttribute(lambda repo: repo.owner.login) organization = factory.LazyAttribute(lambda repo: repo.owner) organization_login = factory.LazyAttribute( lambda repo: repo.organization.login) private = False description = FuzzyText(prefix="autogenerated: ", length=50) fork = False created_at = FuzzyNaiveDateTime(start_dt=week_ago, end_dt=yesterday) updated_at = FuzzyNaiveDateTime(start_dt=yesterday, end_dt=now) pushed_at = FuzzyNaiveDateTime(start_dt=yesterday, end_dt=now) size = FuzzyInteger(100, 1000000) stargazers_count = FuzzyInteger(50) watchers_count = FuzzyInteger(50) language = FuzzyChoice(["Python", "JavaScript", "Ruby", "Markdown"]) has_issues = True has_downloads = True has_wiki = True has_pages = True forks_count = FuzzyInteger(50) open_issues_count = FuzzyInteger(100) default_branch = "master" class Meta(object): model = Repository
class PullRequestFactory(BaseFactory): id = FuzzyInteger(999999) number = factory.Sequence(int) state = "open" locked = False user = factory.SubFactory(UserFactory) user_login = factory.LazyAttribute(lambda pr: pr.user.login) title = factory.Sequence(lambda n: "PR #{}".format(n)) body = FuzzyText(prefix="autogenerated: ", length=50) created_at = FuzzyNaiveDateTime(start_dt=week_ago, end_dt=yesterday) updated_at = FuzzyNaiveDateTime(start_dt=yesterday, end_dt=now) base_repo = factory.SubFactory(RepoFactory) base_ref = "master" head_repo = factory.SubFactory(RepoFactory) head_ref = FuzzyText(length=10) merged = False comments_count = FuzzyInteger(10) review_comments_count = FuzzyInteger(15) commits_count = FuzzyInteger(5) additions = FuzzyInteger(50) deletions = FuzzyInteger(50) changed_files = FuzzyInteger(20) class Meta(object): model = PullRequest
class PopSnapFactory(factory.alchemy.SQLAlchemyModelFactory): class Meta: model = models.PopulationSnapshot sqlalchemy_session = db.session id = factory.Sequence(int) popcount = FuzzyInteger(0, 150) time = FuzzyNaiveDateTime(datetime.datetime.now())
class VotingFactory(DjangoModelFactory): key = factory.Sequence(lambda n: '%dv' % n) value = { 'documents': [ { 'id': '393905d', 'type': 'pateikimas', 'number': 'XIP-2992', 'name': ('Valstybės saugumo departamento įstatymo 10 straipsnio ' 'pakeitimo ĮSTATYMO PROJEKTAS (Nr. XIP-2992)') }, ], } name = 'priėmimas po pateikimo' timestamp = FuzzyNaiveDateTime(datetime.datetime(2012, 11, 16)) source = factory.Sequence( lambda n: 'http://www3.lrs.lt/pls/inter/w5_sale.bals?p_bals_id=%d' % n) class Meta: model = Voting django_get_or_create = ('name', )
class ReleaseFactory(WarehouseFactory): FACTORY_FOR = table_shim(releases) version = FuzzyVersion() summary = FuzzyText(length=75) created = FuzzyNaiveDateTime( datetime.datetime.now() - datetime.timedelta(days=5), )
def FuzzyEndTime(): return ( FuzzyNaiveDateTime( datetime.datetime.now() - datetime.timedelta(days=19), datetime.datetime.now() ) )
def handle(self, *args, **options): upper_bound = options['upper_bound'] substance_type = options['substance_type'] substance_unit = options['substance_unit'] username = options['username'] try: user = User.objects.get(name=username.lower()) except ObjectDoesNotExist: user = User.objects.create(name=username.lower()) try: category = Category.objects.get(name=substance_type.lower()) except ObjectDoesNotExist: category = Category.objects.create(name=substance_type.lower()) try: unit = Unit.objects.get(name=substance_unit.lower()) except ObjectDoesNotExist: unit = Unit.objects.create(name=substance_unit.lower(), category=category) end_date = date.today() start_date = end_date - timedelta(days=7) for i in self.get_date_list(start_date, end_date): for _ in range(3): SubstanceFactory( user=user, unit=unit, category=category, record_date=i, record_time=FuzzyNaiveDateTime(datetime.datetime.now() - timedelta(hours=24)), value=FuzzyInteger(0, int(upper_bound)))
def FuzzyStartTime(): return ( FuzzyNaiveDateTime( datetime.datetime.now() - datetime.timedelta(days=40), datetime.datetime.now() - datetime.timedelta(days=20), ) )
class ColorFactory(DjangoModelFactory): FACTORY_FOR = Color user = SubFactory(UserFactory) value = FuzzyInteger(0, 8) category = SubFactory(CategoryFactory) record_date = date.today() record_time = FuzzyNaiveDateTime(datetime.now() - timedelta(hours=24)) notes = 'This is a randomly generated dummy urine color data'
class MeetupFactory(factory.DjangoModelFactory): class Meta: model = models.Meetup number = factory.Sequence(lambda n: n) date = FuzzyNaiveDateTime( start_dt=datetime.utcnow() - timedelta(days=30 * 6), end_dt=datetime.utcnow() + timedelta(days=30 * 6))
class TalkProposalFactory(factory.DjangoModelFactory): class Meta: model = models.TalkProposal message = factory.Faker('sentence') date_submitted = FuzzyNaiveDateTime( start_dt=datetime.utcnow() - timedelta(days=30 * 6), end_dt=datetime.utcnow() + timedelta(days=30 * 6))
class MilestoneFactory(BaseFactory): repo = factory.SubFactory(RepoFactory) number = factory.Sequence(int) state = "open" title = factory.Sequence(lambda n: "v{}.0".format(n)) description = FuzzyText(prefix="autogenerated: ", length=50) creator = factory.LazyAttribute(lambda m: m.repo.owner) creator_login = factory.LazyAttribute(lambda m: m.repo.owner_login) open_issues_count = FuzzyInteger(20) closed_issues_count = FuzzyInteger(20) created_at = FuzzyNaiveDateTime(start_dt=week_ago, end_dt=yesterday) updated_at = FuzzyNaiveDateTime(start_dt=yesterday, end_dt=now) closed_at = None due_at = None class Meta(object): model = Milestone
class UserFactory(BaseFactory): id = FuzzyInteger(999999) login = FuzzyText(length=8) site_admin = False name = FuzzyText(length=16) company = "GitHub" email = "*****@*****.**" hireable = False bio = FuzzyText(prefix="autogenerated: ", length=50) public_repos_count = FuzzyInteger(50) public_gists_count = FuzzyInteger(50) followers_count = FuzzyInteger(50) following_count = FuzzyInteger(50) created_at = FuzzyNaiveDateTime(start_dt=week_ago, end_dt=yesterday) updated_at = FuzzyNaiveDateTime(start_dt=yesterday, end_dt=now) class Meta(object): model = User
class GlucoseFactory(DjangoModelFactory): FACTORY_FOR = Glucose user = SubFactory(UserFactory) value = FuzzyInteger(50, 240) category = SubFactory(CategoryFactory) record_date = date.today() record_time = FuzzyNaiveDateTime(datetime.now() - timedelta(hours=24)) notes = 'Hello! Please feel free to mess around.'
class TreesFactory(BaseFactoryWithID): class Meta: model = Trees name = FuzzyText() buildname = FuzzyText() date = FuzzyNaiveDateTime(datetime.datetime.now()) arch = FuzzyText() imported = 1 compatlayer = False
class GiftCardFactory(Factory): class Meta: model = GiftCard id = LazyFunction(uuid.uuid4) redeem_code = FuzzyText(length=14, chars=string.ascii_uppercase + string.digits) date_of_issue = FuzzyDate(start_date=date.today()) pin = FuzzyInteger(low=1_000_000_000_000_000, high=9_999_999_999_999_999) timestamp = FuzzyNaiveDateTime(start_dt=datetime.now()) is_used = False source = FuzzyChoice(["AMAZON", "WOOHOO", "MAGICPIN", "HDFC SMARTBUY"]) denomination = FuzzyChoice([50, 100, 200, 500, 1_000, 2_000, 10_000])
class UserFactory(SQLAlchemyModelFactory): # pylint: disable=no-init,too-few-public-methods class Meta: # pylint: disable=old-style-class,no-init,too-few-public-methods model = User sqlalchemy_session = db.session first_name = LazyAttribute(lambda o: fake.first_name()) last_name = LazyAttribute(lambda o: fake.last_name()) # Can't log in to user unless SECURITY_PASSWORD_HASH='plaintext' in the config password = u'foobar' email = LazyAttribute( lambda o: u'{}.{}@fakeemail.net'.format(o.first_name, o.last_name)) active = True confirmed_at = FuzzyNaiveDateTime(datetime(2015, 1, 1)) joined = RelatedFactory(UserJoinedEventFactory, 'user') position = LazyAttribute(lambda o: fake.job()) organization = LazyAttribute(lambda o: fake.company()) organization_type = FuzzyChoice(ORG_TYPES.keys()) country = LazyAttribute(lambda o: fake.country_code()) city = LazyAttribute(lambda o: fake.city()) projects = LazyAttribute(lambda o: fake.paragraph()) tutorial_step = 3 @post_generation def expertise_domains(self, create, extracted, **kwargs): #pylint: disable=unused-argument if not create: return if extracted is not None: for expertise_domain in extracted: expertise_domain.user = self return else: domains = current_app.config.get('DOMAINS', []) for expertise_domain in sample(domains, randint(0, len(domains))): self.expertise_domains.append( UserExpertiseDomainFactory.create(user_id=self.id, name=expertise_domain)) @post_generation def languages(self, create, extracted, **kwargs): #pylint: disable=unused-argument if not create: return if extracted is not None: for language in extracted: language.user = self return else: for locale in sample(LOCALES, randint(0, len(LOCALES))): self.languages.append( UserLanguageFactory.create(user_id=self.id, locale=locale)) @post_generation def skills(self, create, extracted, **kwargs): #pylint: disable=unused-argument if not create: return if extracted is not None: for skill in extracted: skill.user = self return else: question_ids = QUESTIONS_BY_ID.keys() for question_id in sample(question_ids, randint(0, len(question_ids))): self.skills.append( UserSkillFactory.create(user_id=self.id, name=question_id)) @post_generation def connections(self, create, extracted, **kwargs): #pylint: disable=unused-argument if not create: return if extracted is not None: for connection in extracted: connection.user = self return else: max_connection_events = 5 max_emails_per_connection = 5 users = User.query_in_deployment().all() for _ in xrange(0, randint(0, max_connection_events)): users_to_connect = set() for _ in xrange(0, randint(1, max_emails_per_connection)): users_to_connect.add(choice(users)) connection = ConnectionEventFactory.create() for u in users_to_connect: EmailFactory.create(from_user_id=self.id, to_user_id=u.id, connection_event=connection) connection.set_total_connections() @post_generation def messages(self, create, extracted, **kwargs): #pylint: disable=unused-argument if not create: return if extracted is not None: for message in extracted: message.user = self return else: max_messages = 3 for _ in xrange(0, randint(0, max_messages)): SharedMessageEventFactory.create(user_id=self.id)
class UseOfForceIncidentFactory(BaseFactory): opaque_id = FuzzyText(length=12) occured_date = FuzzyNaiveDateTime(start_dt=datetime(2012, 1, 1)) service_type = FuzzyChoice(["Arresting", "Call for Service", "Code Inforcement", "Interviewing", "Restraining", "Transporting", None]) use_of_force_reason = FuzzyChoice(["Assaulting Citizen(s)", "Assaulting Officer", "Combative Subject", "Damage to City Prop.", "Damage to Private Prop.", "Non-compliance", "Resisting Arrest", None]) resident_weapon_used = FuzzyChoice(["Gun", "Knife", "Verbal threats", None]) census_tract = FuzzyChoice( ["3101.03", "3101.04", "3101.05", "3101.06", "3101.08", "3101.10", "3101.11", "3102.01", "3102.03", "3102.04", "3103.05", "3103.06", "3103.08", "3103.09", "3103.10", "3103.12", "3201.05", "3201.06", "3201.07", "3201.08", "3201.09", "3202.02", "3202.03", "3202.04", "3203.01", "3203.03", "3203.04", "3204", "3205", "3207", "3208", "3209.01", "3209.02", "3209.03", "3210.01", "3210.02", "3211", "3212", "3213", "3214", "3216", "3217", "3218", "3219", "3220", "3221", "3222", "3224", "3225", "3226", "3227", "3301.03", "3301.05", "3301.06", "3301.08", "3302.02", "3302.08", "3304.01", "3305", "3306", "3307", "3308.03", "3308.04", "3308.05", "3308.06", "3309", "3310", "3401.01", "3401.02", "3401.08", "3401.09", "3401.10", "3401.11", "3401.12", "3402.01", "3402.02", "3403", "3404", "3405", "3406", "3407", "3409.02", "3410", "3417", "3419.02", "3419.03", "3419.04", "3421.01", "3422", "3423", "3501", "3503", "3505", "3506", "3508", "3510", "3512", "3516", "3524", "3527", "3528", "3533", "3535", "3536", "3542", "3547", "3554", "3562", "3573", "3574", "3579", "3581", "3601.01", "3601.02", "3602.01", "3603.01", "3603.02", "3604.01", "3604.02", "3604.04", "3604.05", "3605.01", "3605.02", "3606.01", "3606.02", "3608", "3609", "3611", "3614", "3702.01", "3702.02", "3703.01", "3801", "3802", "3803", "3804.02", "3804.03", "3804.04", "3805.01", "3805.02", "3806", "3807", "3809.02", "3810.01", "3810.02", "3811.01", "3811.02", "3812.01", "3812.03", "3812.04", "3812.05", "3901.02", "3902", "3904.02", "3904.03", "3904.04", "3904.05", "3905", "3906", "3909", "3910", None, None, None, None, None, None, None, None, None, None] ) division = FuzzyChoice([ ["Chiefs Staff Division", "Court Liaison", "", ""], ["Investigative Division", "Crime Prevention", "C Shift", ""], ["Investigative Division", "Detective Bureau", "Auto Theft Unit", "Evenings"], ["Investigative Division", "Detective Bureau", "Auto Theft Unit", "Off Duty"], ["Investigative Division", "Detective Bureau", "Auto Theft Unit", "Rotating"], ["Investigative Division", "Detective Bureau", "Homicide Unit", "Evenings"], ["Investigative Division", "Detective Bureau", "Homicide Unit", "Rotating"], ["Investigative Division", "First Precinct", "A Shift", "X21 Zone"], ["Investigative Division", "First Precinct", "A Shift", "X22 Zone"], ["Investigative Division", "First Precinct", "B Shift", "X26 Zone"], ["Investigative Division", "Second Precinct", "Day Beats", "Beat 19"], ["Investigative Division", "Special Investigations", "Computer Crimes", "Days"], ["Investigative Division", "Special Investigations", "Computer Crimes", "Evenings"], ["Investigative Division", "Special Investigations", "Criminal Intelligence", "Days"], ["Investigative Division", "Special Investigations", "Day Beats", "Beat 19"], ["Investigative Division", "Special Investigations", "K 9 Unit", "Days"], ["Investigative Division", "Special Investigations", "Narcotics", "Days"], ["Investigative Division", "Special Investigations", "Vice", "Evenings"], ["Operational Bureau", "First Precinct", "C Shift", "X25 Zone"], ["Operational Bureau", "Fourth Precinct", "C.O.P. Program", "Days"], ["Operational Bureau", "Fourth Precinct", "Unknown", "Unknown"], ["Operational Bureau", "Second Precinct", "B Shift", "X20 Zone"], ["Operational Bureau", "Second Precinct", "Day Beats", "Beat 18"], ["Operational Bureau", "Second Precinct", "Day Beats", "Beat 19"], ["Operational Bureau", "Third Precinct", "C Shift", "X26 Zone"], ["Operational Division", "Crime Prevention", "B Shift", "X27 Zone"], ["Operational Division", "Detective Bureau", "Auto Theft Unit", "Days"], ["Operational Division", "First Precinct", "A Shift", "X20 Zone"], ["Operational Division", "First Precinct", "A Shift", "X22 Zone"], ["Operational Division", "First Precinct", "A Shift", "X23 Zone"], ["Operational Division", "First Precinct", "A Shift", "X24 Zone"], ["Operational Division", "First Precinct", "A Shift", "X25 Zone"], ["Operational Division", "First Precinct", "A Shift", "X26 Zone"], ["Operational Division", "First Precinct", "A Shift", "X27 Zone"], ["Operational Division", "First Precinct", "B Shift", "Beat 20"], ["Operational Division", "First Precinct", "B Shift", "X20 Zone"], ["Operational Division", "First Precinct", "B Shift", "X21 Zone"], ["Operational Division", "First Precinct", "B Shift", "X22 Zone"], ["Operational Division", "First Precinct", "B Shift", "X23 Zone"], ["Operational Division", "First Precinct", "B Shift", "X24 Zone"], ["Operational Division", "First Precinct", "B Shift", "X26 Zone"], ["Operational Division", "First Precinct", "B Shift", "X27 Zone"], ["Operational Division", "First Precinct", "B Shift", "X28 Zone"], ["Operational Division", "First Precinct", "C Shift", "X20 Zone"], ["Operational Division", "First Precinct", "C Shift", "X21 Zone"], ["Operational Division", "First Precinct", "C Shift", "X23 Zone"], ["Operational Division", "First Precinct", "C Shift", "X24 Zone"], ["Operational Division", "First Precinct", "C Shift", "X25 Zone"], ["Operational Division", "Fourth Precinct", "A Shift", "X20 Zone"], ["Operational Division", "Fourth Precinct", "A Shift", "X22 Zone"], ["Operational Division", "Fourth Precinct", "A Shift", "X24 Zone"], ["Operational Division", "Fourth Precinct", "B Shift", "Beat 23"], ["Operational Division", "Fourth Precinct", "B Shift", "X25 Zone"], ["Operational Division", "Fourth Precinct", "B Shift", "X27 Zone"], ["Operational Division", "Fourth Precinct", "C Shift", "Beat 20"], ["Operational Division", "Fourth Precinct", "C Shift", "Beat 23"], ["Operational Division", "Fourth Precinct", "C Shift", "X20 Zone"], ["Operational Division", "Fourth Precinct", "C Shift", "X21 Zone"], ["Operational Division", "Fourth Precinct", "C Shift", "X22 Zone"], ["Operational Division", "Fourth Precinct", "C Shift", "X25 Zone"], ["Operational Division", "Fourth Precinct", "C Shift", "X27 Zone"], ["Operational Division", "Fourth Precinct", "Commanding Officer", "Days"], ["Operational Division", "Second Precinct", "A Shift", "Beat 14"], ["Operational Division", "Second Precinct", "A Shift", "Beat 17"], ["Operational Division", "Second Precinct", "A Shift", "Beat 19"], ["Operational Division", "Second Precinct", "A Shift", "X20 Zone"], ["Operational Division", "Second Precinct", "B Shift", "X20 Zone"], ["Operational Division", "Second Precinct", "B Shift", "X23 Zone"], ["Operational Division", "Second Precinct", "B Shift", "X25 Zone"], ["Operational Division", "Second Precinct", "C Shift", "X22 Zone"], ["Operational Division", "Second Precinct", "Day Beats", ""], ["Operational Division", "Second Precinct", "Day Beats", "Beat 15"], ["Operational Division", "Second Precinct", "Day Beats", "Beat 19"], ["Operational Division", "Second Precinct", "Day Beats", "Beat 20"], ["Operational Division", "Second Precinct", "Days Bikes", "Beat 19"], ["Operational Division", "Second Precinct", "Days Bikes", "Evenings"], ["Operational Division", "Second Precinct", "Night Beats", "Beat 19"], ["Operational Division", "Second Precinct", "Night Beats", "Evenings"], ["Operational Division", "Second Precinct", "Oceanfront", "Day Bikes"], ["Operational Division", "Second Precinct", "Off Duty / LE", "Evenings"], ["Operational Division", "Special Investigations", "B Shift", "X20 Zone"], ["Operational Division", "Special Investigations", "Bomb Squad", "Beat 20"], ["Operational Division", "Special Operations", "Bomb Squad", "Rotating"], ["Operational Division", "Special Operations", "SWAT Team", " "], ["Operational Division", "Special Operations", "SWAT Team", "MidNights"], ["Operational Division", "Special Operations", "SWAT Team", "Rotating"], ["Operational Division", "Third Precinct", "A Shift", "C.O.P."], ["Operational Division", "Third Precinct", "B Shift", "X22 Zone"], ["Operational Division", "Third Precinct", "B Shift", "X24 Zone"], ["Operational Division", "Third Precinct", "C Shift", "X26 Zone"], ["Operational Division", "Third Precinct", "C Shift", "X29 Zone"], ["Prof. Dev and Training", "VBLETA", "Instructor", "Days"], ["Support Division", "Logistical Support", "A Shift", ""], [None, None, None, None], [None, None, None, None], [None, None, None, None], [None, None, None, None] ]) precinct = None shift = None beat = None disposition = FuzzyChoice([ "Inactivated", "Informational Purpose On", "No Violation", "Not Sustained", "Not within Policy", "Partially Sustained", "Sustained", "Unfounded/Exonerated", "Unfounded/False", "Unfounded/Not Involved", "Unfounded/Unwarranted", "Withdrawn", "Within policy", None ]) officer_force_type = FuzzyChoice([ "Capstun", "Distraction Techniques", "Expandable Baton", "Hand Cuffed", "Hands On", "K-9 Utilized", "Kicked", "Pain Compliance", "Pinched", "Pressure Points", "Punched", "Restraints", "Sage Impact", "Side Handle Baton", "Taser", "Verbal", None ]) resident_resist_type = FuzzyChoice([ "Active Aggression", "Bite", "Deadly Force Assualt", "Defensive Resistance", "Flash Light to the Head", "Fled", "Kicked", "Passive Resistance", "Pinched", "Psycholog Intimidation", "Punched", "Spit", "Stricking", "Used Knife", "Used other object", "Verbal Resistance", None ]) officer_weapon_used = FuzzyChoice(["Gun", "Handcuffs", "Physical", None]) resident_weapon_used = FuzzyChoice(["Gun", "Knife", "Verbal threats", None]) arrest_made = FuzzyChoice([True, False, None]) arrest_charges = LazyAttribute(lambda i: random.choice(["18.2.63 FALE", "18.2.64 FALE", "18.2.64 Felony Assualt LEO", "18.2-60", "18.2-60 ASLE", "18.2-60 FALE", "18.2-64 FALE", "18.2-64 FAOLE", "18.2-64 Felony assualt LE", "Assault of LE Officer", "Assault on LE", "Assult on L/E (felony)", "Felonious assault on LE", "Felony assault on LE", "Felony Assualt on LE", "Resisting Arrest"]) if i.arrest_made is True else None) resident_injured = FuzzyChoice([True, False, None]) resident_hospitalized = FuzzyChoice([True, False, None]) officer_injured = FuzzyChoice([True, False, None]) officer_hospitalized = FuzzyChoice([True, False, None]) resident_race = FuzzyChoice(["Asian", "Black", "Hispanic", "Native Ameri", "Polynesian", "Unknown", "White", None]) officer_race = FuzzyChoice(["Asian", "Black", "Hispanic", "Native Ameri", "Polynesian", "Unknown", "White", None]) officer_identifier = FuzzyChoice([factory_random_string(12) for x in range(30)]) officer_years_of_service = FuzzyInteger(30) @classmethod def _after_postgeneration(cls, obj, create, results=None): tmp = obj.division obj.division = tmp[0] obj.precinct = tmp[1] obj.shift = tmp[2] obj.beat = tmp[3] class Meta: model = UseOfForceIncident
FuzzyChoice, FuzzyNaiveDateTime, FuzzyInteger, FuzzyText, FuzzyDateTime, ) from server.models import (db, Command, Credential, Host, Hostname, License, PolicyViolation, Reference, Service, SourceCode, Tag, User, Vulnerability, VulnerabilityCode, VulnerabilityTemplate, VulnerabilityWeb, Workspace, ReferenceTemplate, CommandObject, Comment, CustomFieldsSchema) # Make partials for start and end date. End date must be after start date FuzzyStartTime = lambda: (FuzzyNaiveDateTime( datetime.datetime.now() - datetime.timedelta(days=40), datetime.datetime.now() - datetime.timedelta(days=20), )) FuzzyEndTime = lambda: (FuzzyNaiveDateTime( datetime.datetime.now() - datetime.timedelta(days=19), datetime.datetime.now())) all_unicode = ''.join(unichr(i) for i in xrange(65536)) UNICODE_LETTERS = ''.join( c for c in all_unicode if unicodedata.category(c) == 'Lu' or unicodedata.category(c) == 'Ll') class FaradayFactory(factory.alchemy.SQLAlchemyModelFactory): @classmethod def build_dict(cls, **kwargs): ret = factory.build(dict, FACTORY_CLASS=cls)
Reference, Service, SourceCode, Tag, User, Vulnerability, VulnerabilityCode, VulnerabilityTemplate, VulnerabilityWeb, Workspace, ReferenceTemplate, CommandObject, Comment) # Make partials for start and end date. End date must be after start date FuzzyStartTime = lambda: ( FuzzyNaiveDateTime( datetime.datetime.now() - datetime.timedelta(days=40), datetime.datetime.now() - datetime.timedelta(days=20), ) ) FuzzyEndTime = lambda: ( FuzzyNaiveDateTime( datetime.datetime.now() - datetime.timedelta(days=19), datetime.datetime.now() ) ) all_unicode = ''.join(unichr(i) for i in xrange(65536)) UNICODE_LETTERS = ''.join(c for c in all_unicode if unicodedata.category(c) == 'Lu' or unicodedata.category(c) == 'Ll') class FaradayFactory(factory.alchemy.SQLAlchemyModelFactory):
class CitizenComplaintFactory(BaseFactory): opaque_id = FuzzyText(length=12) occured_date = FuzzyNaiveDateTime(start_dt=datetime(2012, 1, 1)) census_tract = FuzzyChoice( ["3101.03", "3101.04", "3101.05", "3101.06", "3101.08", "3101.10", "3101.11", "3102.01", "3102.03", "3102.04", "3103.05", "3103.06", "3103.08", "3103.09", "3103.10", "3103.12", "3201.05", "3201.06", "3201.07", "3201.08", "3201.09", "3202.02", "3202.03", "3202.04", "3203.01", "3203.03", "3203.04", "3204", "3205", "3207", "3208", "3209.01", "3209.02", "3209.03", "3210.01", "3210.02", "3211", "3212", "3213", "3214", "3216", "3217", "3218", "3219", "3220", "3221", "3222", "3224", "3225", "3226", "3227", "3301.03", "3301.05", "3301.06", "3301.08", "3302.02", "3302.08", "3304.01", "3305", "3306", "3307", "3308.03", "3308.04", "3308.05", "3308.06", "3309", "3310", "3401.01", "3401.02", "3401.08", "3401.09", "3401.10", "3401.11", "3401.12", "3402.01", "3402.02", "3403", "3404", "3405", "3406", "3407", "3409.02", "3410", "3417", "3419.02", "3419.03", "3419.04", "3421.01", "3422", "3423", "3501", "3503", "3505", "3506", "3508", "3510", "3512", "3516", "3524", "3527", "3528", "3533", "3535", "3536", "3542", "3547", "3554", "3562", "3573", "3574", "3579", "3581", "3601.01", "3601.02", "3602.01", "3603.01", "3603.02", "3604.01", "3604.02", "3604.04", "3604.05", "3605.01", "3605.02", "3606.01", "3606.02", "3608", "3609", "3611", "3614", "3702.01", "3702.02", "3703.01", "3801", "3802", "3803", "3804.02", "3804.03", "3804.04", "3805.01", "3805.02", "3806", "3807", "3809.02", "3810.01", "3810.02", "3811.01", "3811.02", "3812.01", "3812.03", "3812.04", "3812.05", "3901.02", "3902", "3904.02", "3904.03", "3904.04", "3904.05", "3905", "3906", "3909", "3910", None, None, None, None, None, None, None, None, None, None] ) division = FuzzyChoice([ ["Chiefs Staff Division", "Court Liaison", "", ""], ["Investigative Division", "Crime Prevention", "C Shift", ""], ["Investigative Division", "Detective Bureau", "Auto Theft Unit", "Evenings"], ["Investigative Division", "Detective Bureau", "Auto Theft Unit", "Off Duty"], ["Investigative Division", "Detective Bureau", "Auto Theft Unit", "Rotating"], ["Investigative Division", "Detective Bureau", "Homicide Unit", "Evenings"], ["Investigative Division", "Detective Bureau", "Homicide Unit", "Rotating"], ["Investigative Division", "First Precinct", "A Shift", "X21 Zone"], ["Investigative Division", "First Precinct", "A Shift", "X22 Zone"], ["Investigative Division", "First Precinct", "B Shift", "X26 Zone"], ["Investigative Division", "Second Precinct", "Day Beats", "Beat 19"], ["Investigative Division", "Special Investigations", "Computer Crimes", "Days"], ["Investigative Division", "Special Investigations", "Computer Crimes", "Evenings"], ["Investigative Division", "Special Investigations", "Criminal Intelligence", "Days"], ["Investigative Division", "Special Investigations", "Day Beats", "Beat 19"], ["Investigative Division", "Special Investigations", "K 9 Unit", "Days"], ["Investigative Division", "Special Investigations", "Narcotics", "Days"], ["Investigative Division", "Special Investigations", "Vice", "Evenings"], ["Operational Bureau", "First Precinct", "C Shift", "X25 Zone"], ["Operational Bureau", "Fourth Precinct", "C.O.P. Program", "Days"], ["Operational Bureau", "Fourth Precinct", "Unknown", "Unknown"], ["Operational Bureau", "Second Precinct", "B Shift", "X20 Zone"], ["Operational Bureau", "Second Precinct", "Day Beats", "Beat 18"], ["Operational Bureau", "Second Precinct", "Day Beats", "Beat 19"], ["Operational Bureau", "Third Precinct", "C Shift", "X26 Zone"], ["Operational Division", "Crime Prevention", "B Shift", "X27 Zone"], ["Operational Division", "Detective Bureau", "Auto Theft Unit", "Days"], ["Operational Division", "First Precinct", "A Shift", "X20 Zone"], ["Operational Division", "First Precinct", "A Shift", "X22 Zone"], ["Operational Division", "First Precinct", "A Shift", "X23 Zone"], ["Operational Division", "First Precinct", "A Shift", "X24 Zone"], ["Operational Division", "First Precinct", "A Shift", "X25 Zone"], ["Operational Division", "First Precinct", "A Shift", "X26 Zone"], ["Operational Division", "First Precinct", "A Shift", "X27 Zone"], ["Operational Division", "First Precinct", "B Shift", "Beat 20"], ["Operational Division", "First Precinct", "B Shift", "X20 Zone"], ["Operational Division", "First Precinct", "B Shift", "X21 Zone"], ["Operational Division", "First Precinct", "B Shift", "X22 Zone"], ["Operational Division", "First Precinct", "B Shift", "X23 Zone"], ["Operational Division", "First Precinct", "B Shift", "X24 Zone"], ["Operational Division", "First Precinct", "B Shift", "X26 Zone"], ["Operational Division", "First Precinct", "B Shift", "X27 Zone"], ["Operational Division", "First Precinct", "B Shift", "X28 Zone"], ["Operational Division", "First Precinct", "C Shift", "X20 Zone"], ["Operational Division", "First Precinct", "C Shift", "X21 Zone"], ["Operational Division", "First Precinct", "C Shift", "X23 Zone"], ["Operational Division", "First Precinct", "C Shift", "X24 Zone"], ["Operational Division", "First Precinct", "C Shift", "X25 Zone"], ["Operational Division", "Fourth Precinct", "A Shift", "X20 Zone"], ["Operational Division", "Fourth Precinct", "A Shift", "X22 Zone"], ["Operational Division", "Fourth Precinct", "A Shift", "X24 Zone"], ["Operational Division", "Fourth Precinct", "B Shift", "Beat 23"], ["Operational Division", "Fourth Precinct", "B Shift", "X25 Zone"], ["Operational Division", "Fourth Precinct", "B Shift", "X27 Zone"], ["Operational Division", "Fourth Precinct", "C Shift", "Beat 20"], ["Operational Division", "Fourth Precinct", "C Shift", "Beat 23"], ["Operational Division", "Fourth Precinct", "C Shift", "X20 Zone"], ["Operational Division", "Fourth Precinct", "C Shift", "X21 Zone"], ["Operational Division", "Fourth Precinct", "C Shift", "X22 Zone"], ["Operational Division", "Fourth Precinct", "C Shift", "X25 Zone"], ["Operational Division", "Fourth Precinct", "C Shift", "X27 Zone"], ["Operational Division", "Fourth Precinct", "Commanding Officer", "Days"], ["Operational Division", "Second Precinct", "A Shift", "Beat 14"], ["Operational Division", "Second Precinct", "A Shift", "Beat 17"], ["Operational Division", "Second Precinct", "A Shift", "Beat 19"], ["Operational Division", "Second Precinct", "A Shift", "X20 Zone"], ["Operational Division", "Second Precinct", "B Shift", "X20 Zone"], ["Operational Division", "Second Precinct", "B Shift", "X23 Zone"], ["Operational Division", "Second Precinct", "B Shift", "X25 Zone"], ["Operational Division", "Second Precinct", "C Shift", "X22 Zone"], ["Operational Division", "Second Precinct", "Day Beats", ""], ["Operational Division", "Second Precinct", "Day Beats", "Beat 15"], ["Operational Division", "Second Precinct", "Day Beats", "Beat 19"], ["Operational Division", "Second Precinct", "Day Beats", "Beat 20"], ["Operational Division", "Second Precinct", "Days Bikes", "Beat 19"], ["Operational Division", "Second Precinct", "Days Bikes", "Evenings"], ["Operational Division", "Second Precinct", "Night Beats", "Beat 19"], ["Operational Division", "Second Precinct", "Night Beats", "Evenings"], ["Operational Division", "Second Precinct", "Oceanfront", "Day Bikes"], ["Operational Division", "Second Precinct", "Off Duty / LE", "Evenings"], ["Operational Division", "Special Investigations", "B Shift", "X20 Zone"], ["Operational Division", "Special Investigations", "Bomb Squad", "Beat 20"], ["Operational Division", "Special Operations", "Bomb Squad", "Rotating"], ["Operational Division", "Special Operations", "SWAT Team", " "], ["Operational Division", "Special Operations", "SWAT Team", "MidNights"], ["Operational Division", "Special Operations", "SWAT Team", "Rotating"], ["Operational Division", "Third Precinct", "A Shift", "C.O.P."], ["Operational Division", "Third Precinct", "B Shift", "X22 Zone"], ["Operational Division", "Third Precinct", "B Shift", "X24 Zone"], ["Operational Division", "Third Precinct", "C Shift", "X26 Zone"], ["Operational Division", "Third Precinct", "C Shift", "X29 Zone"], ["Prof. Dev and Training", "VBLETA", "Instructor", "Days"], ["Support Division", "Logistical Support", "A Shift", ""], [None, None, None, None], [None, None, None, None], [None, None, None, None], [None, None, None, None]] ) precinct = None shift = None beat = None disposition = FuzzyChoice([ "Inactivated", "Informational Purpose On", "No Violation", "Not Sustained", "Not within Policy", "Partially Sustained", "Sustained", "Unfounded/Exonerated", "Unfounded/False", "Unfounded/Not Involved", "Unfounded/Unwarranted", "Withdrawn", "Within policy", None ]) allegation = FuzzyChoice(["Inappropriate use of force", "Substandard officer performance", "Officer used inappropriate language", "Officer didn't file incident report", "K-9 Incidents", "Profiling", "Rudeness", "Mistreatment", None]) resident_race = FuzzyChoice(["Asian", "Black", "Hispanic", "Native Ameri", "Polynesian", "Unknown", "White", None]) resident_sex = FuzzyChoice(["Anonymou", "Female", "Male", None]) officer_race = FuzzyChoice(["Asian", "Black", "Hispanic", "Native Ameri", "Polynesian", "Unknown", "White", None]) officer_sex = FuzzyChoice(["Anonymou", "Female", "Male", None]) officer_identifier = FuzzyChoice([factory_random_string(12) for x in range(30)]) officer_years_of_service = FuzzyInteger(30) @classmethod def _after_postgeneration(cls, obj, create, results=None): tmp = obj.division obj.division = tmp[0] obj.precinct = tmp[1] obj.shift = tmp[2] obj.beat = tmp[3] class Meta: model = CitizenComplaint