def build_test_schools(num_elements=2):

    # DEV: This is quite redundant with tests.test_views.setUp().
    #  If I keep this, that redundancy should be removed somehow.

    # Build an organization, down to the performance indicator level.
    num_elements = num_elements

    user = User.objects.filter(username=os.environ['RU_USERNAME'])[0]
    su_user = User.objects.filter(username=os.environ['SU_USERNAME'])[0]

    # Build num_elements test organizations that user 0 is associated with,
    #  num_elements the user 1 is associated with.
    test_organizations, test_sas = [], []
    for organization_num in range(6):
        name = li.get_words(2)
        if organization_num < num_elements/2:
            new_organization = Organization.objects.create(name=name, owner=user)
            new_organization.editors.add(user)
        else:
            new_organization = Organization.objects.create(name=name, owner=su_user)
            new_organization.editors.add(su_user)
        test_organizations.append(new_organization)

        # Create num_elements subject areas for each organization.
        for sa_num in range(num_elements):
            sa_name = li.get_words(2)
            new_sa = SubjectArea.objects.create(subject_area=sa_name,
                                                organization=new_organization)
            test_sas.append(new_sa)

            # Create num_elements grad standards for each subject area.
            for gs_num in range(num_elements):
                gs_body = li.get_words(randint(3,7))
                new_gs = CompetencyArea.objects.create(subject_area=new_sa,
                                                           competency_area=gs_body)

                # Create num_elements perf indicators for each grad std.
                for pi_num in range(num_elements):
                    pi_body = li.get_paragraph(randint(2,5))
                    new_pi = EssentialUnderstanding.objects.create(essential_understanding=pi_body,
                                                                 competency_area=new_gs)

            # Create num_elements sdas for each sa.
            for sda_num in range(num_elements):
                sda_name = li.get_words(randint(2,3))
                new_sda = SubdisciplineArea.objects.create(subject_area=new_sa,
                                                           subdiscipline_area=sda_name)

                # Create num_elements grad standards for each sda.
                for gs_num in range(num_elements):
                    gs_body = li.get_words(randint(3,7))
                    new_gs = CompetencyArea.objects.create(subject_area=new_sa,
                                                               subdiscipline_area=new_sda,
                                                               competency_area=gs_body)

                    # Create num_elements perf indicators for each grad std.
                    for pi_num in range(num_elements):
                        pi_body = li.get_paragraph(randint(2,5))
                        new_pi = EssentialUnderstanding.objects.create(essential_understanding=pi_body,
                                                                     competency_area=new_gs)
Build a set of test schools for dev work.
dataset/ETHPy150Open openlearningtools/opencompetencies/competencies/my_admin.py/build_test_schools