Ejemplo n.º 1
0
    def test_setup_with_wrong_case_on_student(self, tmpdir):
        """User names are case insensitive on GitLab, and so setup should work
        fine even if the case of some character in a student's username is
        "incorrect".

        See https://github.com/repobee/repobee/issues/900
        """
        student = STUDENT_TEAMS[0].members[0]
        student_wrong_case = student.upper()
        assert (student !=
                student_wrong_case), "cases match, test is pointless :("

        command = " ".join([
            *repobee_plug.cli.CoreCommand.repos.setup.as_name_tuple(),
            *BASE_ARGS,
            *TEMPLATE_ORG_ARG,
            *MASTER_REPOS_ARG,
            "--students",
            student_wrong_case,
        ])

        run_repobee(command, workdir=tmpdir, plugins=[_repobee.ext.gitlab])

        assert_repos_exist([plug.StudentTeam(members=[student])],
                           assignment_names)
Ejemplo n.º 2
0
    def test_clean_setup_in_subgroup(self, tmpdir):
        """It should be possible to use a subgroup as the target org."""
        gl, template_group, target_group = gitlab_and_groups()
        subgroup_name = "bestgroup"
        subgroup_full_path = f"{target_group.path}/{subgroup_name}"
        gl.groups.create(
            dict(
                name=subgroup_name,
                path=subgroup_name,
                parent_id=target_group.id,
            ))

        base_args = [
            arg if arg != ORG_NAME else subgroup_full_path for arg in BASE_ARGS
        ]

        command = " ".join([
            *repobee_plug.cli.CoreCommand.repos.setup.as_name_tuple(),
            *base_args,
            *TEMPLATE_ORG_ARG,
            *MASTER_REPOS_ARG,
            *STUDENTS_ARG,
        ])

        run_repobee(command, workdir=tmpdir, plugins=[_repobee.ext.gitlab])
        assert_repos_exist(STUDENT_TEAMS,
                           assignment_names,
                           org_name=subgroup_full_path)
Ejemplo n.º 3
0
    def test_clean_setup_in_subgroup(self, extra_args):
        """It should be possible to use a subgroup as the target org."""
        gl, template_group, target_group = gitlab_and_groups()
        subgroup_name = "bestgroup"
        subgroup_full_path = f"{target_group.path}/{subgroup_name}"
        gl.groups.create(
            dict(
                name=subgroup_name,
                path=subgroup_name,
                parent_id=target_group.id,
            ))

        base_args = [
            arg if arg != ORG_NAME else subgroup_full_path for arg in BASE_ARGS
        ]

        command = " ".join([
            REPOBEE_GITLAB,
            *repobee_plug.cli.CoreCommand.repos.setup.as_name_tuple(),
            *base_args,
            *TEMPLATE_ORG_ARG,
            *MASTER_REPOS_ARG,
            *STUDENTS_ARG,
        ])

        result = run_in_docker_with_coverage(command, extra_args=extra_args)
        assert result.returncode == 0
        assert_repos_exist(STUDENT_TEAMS,
                           assignment_names,
                           org_name=subgroup_full_path)
Ejemplo n.º 4
0
    def test_clean_setup(self, tmpdir):
        """Test a first-time setup with master repos in the master org."""
        command = " ".join([
            *repobee_plug.cli.CoreCommand.repos.setup.as_name_tuple(),
            *BASE_ARGS,
            *TEMPLATE_ORG_ARG,
            *MASTER_REPOS_ARG,
            *STUDENTS_ARG,
        ])

        run_repobee(command, workdir=tmpdir, plugins=[_repobee.ext.gitlab])
        assert_repos_exist(STUDENT_TEAMS, assignment_names)
        assert_on_groups(STUDENT_TEAMS)
Ejemplo n.º 5
0
    def test_setup_twice(self, tmpdir):
        """Setting up twice should have the same effect as setting up once."""
        command = " ".join([
            *repobee_plug.cli.CoreCommand.repos.setup.as_name_tuple(),
            *BASE_ARGS,
            *TEMPLATE_ORG_ARG,
            *MASTER_REPOS_ARG,
            *STUDENTS_ARG,
        ])

        run_repobee(command, workdir=tmpdir, plugins=[_repobee.ext.gitlab])
        run_repobee(command, workdir=tmpdir, plugins=[_repobee.ext.gitlab])
        assert_repos_exist(STUDENT_TEAMS, assignment_names)
        assert_on_groups(STUDENT_TEAMS)
Ejemplo n.º 6
0
    def test_clean_setup(self, extra_args):
        """Test a first-time setup with master repos in the master org."""
        command = " ".join([
            REPOBEE_GITLAB,
            *repobee_plug.cli.CoreCommand.repos.setup.as_name_tuple(),
            *BASE_ARGS,
            *TEMPLATE_ORG_ARG,
            *MASTER_REPOS_ARG,
            *STUDENTS_ARG,
        ])

        result = run_in_docker_with_coverage(command, extra_args=extra_args)
        assert result.returncode == 0
        assert_repos_exist(STUDENT_TEAMS, assignment_names)
        assert_on_groups(STUDENT_TEAMS)
Ejemplo n.º 7
0
    def test_setup_with_token_owner_as_student(self, tmpdir):
        """Setting up with the token owner as a student should not cause
        a crash (see #812)
        """
        command = " ".join([
            *repobee_plug.cli.CoreCommand.repos.setup.as_name_tuple(),
            *BASE_ARGS,
            *TEMPLATE_ORG_ARG,
            *MASTER_REPOS_ARG,
            "--students",
            TEACHER,
        ])

        run_repobee(command, workdir=tmpdir, plugins=[_repobee.ext.gitlab])
        assert_repos_exist([plug.StudentTeam(members=[TEACHER])],
                           assignment_names)
Ejemplo n.º 8
0
    def test_setup_twice(self, extra_args):
        """Setting up twice should have the same effect as setting up once."""
        command = " ".join([
            REPOBEE_GITLAB,
            *repobee_plug.cli.CoreCommand.repos.setup.as_name_tuple(),
            *BASE_ARGS,
            *TEMPLATE_ORG_ARG,
            *MASTER_REPOS_ARG,
            *STUDENTS_ARG,
        ])

        result = run_in_docker_with_coverage(command, extra_args=extra_args)
        result = run_in_docker_with_coverage(command, extra_args=extra_args)
        assert result.returncode == 0
        assert_repos_exist(STUDENT_TEAMS, assignment_names)
        assert_on_groups(STUDENT_TEAMS)
Ejemplo n.º 9
0
    def test_setup_with_token_owner_as_student(self, extra_args):
        """Setting up with the token owner as a student should not cause
        a crash (see #812)
        """
        command = " ".join([
            REPOBEE_GITLAB,
            *repobee_plug.cli.CoreCommand.repos.setup.as_name_tuple(),
            *BASE_ARGS,
            *TEMPLATE_ORG_ARG,
            *MASTER_REPOS_ARG,
            "--students",
            TEACHER,
        ])

        result = run_in_docker_with_coverage(command, extra_args=extra_args)
        assert result.returncode == 0
        assert_repos_exist([plug.StudentTeam(members=[TEACHER])],
                           assignment_names)
Ejemplo n.º 10
0
def with_student_repos(restore):
    """Set up student repos before starting tests.

    Note that explicitly including restore here is necessary to ensure that
    it runs before this fixture.
    """
    command = " ".join([
        REPOBEE_GITLAB,
        *str(repobee_plug.cli.CoreCommand.repos.setup).split(),
        *BASE_ARGS,
        *TEMPLATE_ORG_ARG,
        *MASTER_REPOS_ARG,
        *STUDENTS_ARG,
    ])

    result = run_in_docker(command)

    # pre-test asserts
    assert result.returncode == 0
    assert_repos_exist(STUDENT_TEAMS, assignment_names)
    assert_on_groups(STUDENT_TEAMS)
Ejemplo n.º 11
0
def with_student_repos(restore, tmpdir):
    """Set up student repos before starting tests.

    Note that explicitly including restore here is necessary to ensure that
    it runs before this fixture.
    """
    command = " ".join([
        *str(repobee_plug.cli.CoreCommand.repos.setup).split(),
        *BASE_ARGS,
        *TEMPLATE_ORG_ARG,
        *MASTER_REPOS_ARG,
        *STUDENTS_ARG,
    ])

    repobee_testhelpers.funcs.run_repobee(command,
                                          workdir=tmpdir,
                                          plugins=[_repobee.ext.gitlab])

    # pre-test asserts
    assert_repos_exist(STUDENT_TEAMS, assignment_names)
    assert_on_groups(STUDENT_TEAMS)
Ejemplo n.º 12
0
    def test_setup_with_twice_with_wrong_case_on_second_setup(self, tmpdir):
        """User names on GitLab are case insensitive, and so setting up repos
        for the same student with two different cases of characters should work
        the same as setting up just once

        See
        https://github.com/repobee/repobee/issues/900#issuecomment-830075510
        for a bug where this was not the case.
        """
        student = STUDENT_TEAMS[0].members[0]
        student_lowercase = STUDENT_TEAMS[0].members[0].lower()
        # the original should be lowercase
        assert (student == student_lowercase
                ), "expected real student username to be lowercase"

        student_uppercase = student_lowercase.upper()
        base_command = [
            *repobee_plug.cli.CoreCommand.repos.setup.as_name_tuple(),
            *BASE_ARGS,
            *TEMPLATE_ORG_ARG,
            *MASTER_REPOS_ARG,
            "--students",
        ]

        def _cmd(student):
            return " ".join(base_command + [student])

        run_repobee(
            _cmd(student_lowercase),
            workdir=tmpdir,
            plugins=[_repobee.ext.gitlab],
        )
        run_repobee(
            _cmd(student_uppercase),
            workdir=tmpdir,
            plugins=[_repobee.ext.gitlab],
        )

        assert_repos_exist([plug.StudentTeam(members=[student])],
                           assignment_names)