コード例 #1
0
def test_generate_service_connections(profiles):
    """Service connection is generated for all profiles,"""
    generate_services()
    generate_profiles(k=profiles, faker=Faker())

    generate_service_connections()

    assert ServiceConnection.objects.count() == profiles
    assert (Profile.objects.annotate(Count("service_connections")).filter(
        service_connections__count=1).count() == profiles)
コード例 #2
0
def test_generate_service_connections(profiles, youth_percentage):
    """Service connection is generated for all profiles,"""
    generate_services()
    generate_profiles(k=profiles, faker=Faker())

    generate_service_connections(youth_percentage)

    assert ServiceConnection.objects.count() == profiles
    assert ServiceConnection.objects.filter(
        service__service_type=ServiceType.YOUTH_MEMBERSHIP).count() == int(
            profiles * youth_percentage)
    assert YouthProfile.objects.count() == 0
コード例 #3
0
def test_generates_youth_profiles(profiles, youth_percentage):
    """Youth profiles are generated for all profiles which have youth membership ServiceConnection."""
    generate_services()
    generate_profiles(k=profiles, faker=Faker())
    generate_service_connections(youth_percentage)

    generate_youth_profiles(faker=Faker())

    assert YouthProfile.objects.count() == int(profiles * youth_percentage)
    # Assert that youth membership service connections have youth membership profile
    assert Profile.objects.filter(
        service_connections__service__service_type=ServiceType.YOUTH_MEMBERSHIP
    ).count() == int(profiles * youth_percentage)
コード例 #4
0
    def handle(self, *args, **kwargs):
        clear = kwargs["clear"]
        no_clear = kwargs["no_clear"]
        development = kwargs["development"]
        superuser = kwargs["superuser"]
        locale = kwargs["locale"]
        faker = Faker(locale)
        profile_count = kwargs["profilecount"]

        if not no_clear and (development or clear):
            self.stdout.write("Clearing data...")
            management.call_command("flush", verbosity=0, interactive=False)
            self.stdout.write(self.style.SUCCESS("Done - Data cleared"))

        self.stdout.write("Creating/updating initial data")

        if superuser:
            self.stdout.write("Adding admin user...")
            management.call_command("add_admin_user")
            self.stdout.write(self.style.SUCCESS("Done - Admin user"))

        # Initial profile data
        self.stdout.write("Generating data fields...")
        generate_data_fields()
        self.stdout.write("Generating services...")
        services = generate_services()
        self.stdout.write("Generating groups...")
        groups = generate_groups_for_services(services=services)

        self.stdout.write(self.style.SUCCESS("Done - Profile data"))

        # Development
        if development:
            self.stdout.write("Assigning group permissions for services...")
            assign_permissions(groups=groups)

            with factory.Faker.override_default_locale(locale):
                self.stdout.write("Generating group admins...")
                generate_group_admins(groups=groups, faker=faker)
                self.stdout.write(f"Generating profiles ({profile_count})...")
                generate_profiles(profile_count, faker=faker)
                self.stdout.write("Generating service connections...")
                generate_service_connections()

            self.stdout.write(self.style.SUCCESS("Done - Development fake data"))
コード例 #5
0
def test_generates_profiles():
    assert Profile.objects.count() == 0
    generate_profiles(k=10, faker=Faker())
    assert Profile.objects.count() == 10
コード例 #6
0
def test_generates_default_amount_of_profiles():
    assert Profile.objects.count() == 0
    generate_profiles(faker=Faker())
    assert Profile.objects.count() == 50
コード例 #7
0
    def handle(self, *args, **kwargs):
        clear = kwargs["clear"]
        no_clear = kwargs["no_clear"]
        development = kwargs["development"]
        superuser = kwargs["superuser"]
        divisions = kwargs["divisions"]
        locale = kwargs["locale"]
        faker = Faker(locale)
        profile_count = kwargs["profilecount"]
        youth_profile_percentage = kwargs["youthprofilepercentage"]

        if not no_clear and (development or clear):
            self.stdout.write("Clearing data...")
            management.call_command("flush", verbosity=0, interactive=False)
            self.stdout.write(self.style.SUCCESS("Done - Data cleared"))

        self.stdout.write("Creating/updating initial data")

        if superuser:
            self.stdout.write("Adding admin user...")
            management.call_command("add_admin_user")
            self.stdout.write(self.style.SUCCESS("Done - Admin user"))

        if divisions:
            self.stdout.write("Importing Helsinki divisions of interest...")
            management.call_command("geo_import", "finland",
                                    "--municipalities")
            management.call_command("geo_import", "helsinki", "--divisions")
            management.call_command("mark_divisions_of_interest")
            self.stdout.write(
                self.style.SUCCESS("Done - Helsinki divisions of interest"))

        # Initial profile data
        self.stdout.write("Generating data fields...")
        generate_data_fields()
        self.stdout.write("Generating services...")
        services = generate_services()
        self.stdout.write("Generating groups...")
        groups = generate_groups_for_services(services=services)
        self.stdout.write("Generating subscription types...")
        generate_subscription_types()

        self.stdout.write(self.style.SUCCESS("Done - Profile data"))

        # Initial youth profile data
        self.stdout.write("Generating youth membership notifications...")
        generate_notifications()

        self.stdout.write(self.style.SUCCESS("Done - Youth Profile data"))

        # Development
        if development:
            self.stdout.write("Assigning group permissions for services...")
            assign_permissions(groups=groups)

            with factory.Faker.override_default_locale(locale):
                self.stdout.write("Generating group admins...")
                generate_group_admins(groups=groups, faker=faker)
                self.stdout.write(f"Generating profiles ({profile_count})...")
                generate_profiles(profile_count, faker=faker)
                self.stdout.write("Generating service connections...")
                generate_service_connections(youth_profile_percentage)
                self.stdout.write("Generating youth profiles...")
                generate_youth_profiles(faker=faker)

            self.stdout.write(
                self.style.SUCCESS("Done - Development fake data"))