Beispiel #1
0
    def populate_data(self):
        people = AutoFixture(
            Person,
            field_values={
                "anonymised": False,
                "name": generators.FirstNameGenerator()
            },
        ).create(5)

        for person in people:
            AutoFixture(HealthRecord,
                        field_values={
                            "anonymised": False,
                            "person": person
                        }).create(random.randint(1, 3))

            AutoFixture(
                PersonProfile,
                field_values={
                    "anonymised": False,
                    "person": person,
                    "age": generators.IntegerGenerator(5, 55),
                    "address": generators.LoremGenerator(max_length=100),
                },
            ).create(random.randint(1, 3))

            AutoFixture(
                MailingListLog,
                field_values={
                    "anonymised": False,
                    "email": person.email,
                    "sent_at": generators.DateTimeGenerator(),
                },
            ).create(random.randint(1, 3))
Beispiel #2
0
def create_many_leads(num, created_by, project):
    leads = []
    for i in range(num):
        lead = Lead()
        lead.title = generators.LoremGenerator(max_length=20).generate()
        lead.project = project
        lead.created_by = created_by
        lead.modified_by = created_by
        lead.status = random.choice(['pending', 'processed'])
        lead.condidentiality = random.choice([
            'unprotected',
            'protected',
            'restricted',
            'confidential',
        ])
        lead.published_on = generators.DateGenerator().generate()
        leads.append(lead)

    Lead.objects.bulk_create(leads)

    LeadAssigneeThrough = Lead.assignee.through
    assignee_throughs = []

    all_users = list(User.objects.all())
    count = len(all_users)
    for lead in leads:
        assignee_throughs.append(
            LeadAssigneeThrough(
                lead_id=lead.id,
                user_id=all_users[random.randint(0, count - 1)].id,
            )
        )

    LeadAssigneeThrough.objects.bulk_create(assignee_throughs)
Beispiel #3
0
 def post_process_instance(self, instance, commit):
     choice = random.randint(1, 2)
     if choice == 1:
         instance.text = generators.LoremGenerator().generate()
     else:
         instance.url = generators.URLGenerator().generate()
         instance.website = urlparse(instance.url).netloc
     instance.save()
class FairsharingRecordAutoFixture(AutoFixture):
    field_values = {
        'name': generators.StringGenerator(max_length=10, min_length=8),
        'abbreviation': generators.StringGenerator(max_length=3, min_length=2),
        'homepage': generators.URLGenerator(),
        'description': generators.LoremGenerator(),
        'doi': generators.StaticGenerator(generate_doi(DATACITE_PREFIX))
    }
    def test_pre_process_has_effect(self):
        expected_string = generators.LoremGenerator(max_length=50)()

        class TestAutoFixture(AutoFixture):
            def pre_process_instance(self, instance):
                instance.name = expected_string
                return instance

        instance = TestAutoFixture(SimpleModel).create_one()
        self.assertEqual(instance.name, expected_string)
Beispiel #6
0
 class RoleAutoFixture(AutoFixture):
     field_values = {
         'name': RoleNameGenerator(),
         'github_user': generators.FirstNameGenerator(),
         'github_repo': generators.StringGenerator(min_length=6, max_length=10),
         'description': generators.LoremGenerator(max_length=250),
         'readme': generators.LoremHTMLGenerator(),
         'min_ansible_version': generators.StaticGenerator('1.3'),
         'issue_tracker_url': generators.URLGenerator(),
         'license': generators.StaticGenerator(''),
         'company': generators.StaticGenerator(''),
         'is_valid': generators.StaticGenerator(True),
     }
Beispiel #7
0
class CategoriesFixture(AutoFixture):
    field_values = {
        'name': generators.FirstNameGenerator(),
        'description': generators.LoremGenerator(),
        #'picture' : generators.ImageGenerator()
    }