repobee_testhelpers Module Reference

Module reference for the RepoBee testhelpers.

This package is not yet entirely stable, so expect that there may be (minor) breaking changes across releases.

fixtures

Fixtures for use with pytest.

repobee_testhelpers.fixtures.platform_dir()[source]

Setup the platform emulation with a template organization with git repositories, the students and teacher as users, and return the the workdirectory for the platform.

repobee_testhelpers.fixtures.platform_url(platform_dir)[source]

Base url to the platform.

funcs

Helper functions for tests.

repobee_testhelpers.funcs.get_api(platform_url, org_name='fall2020', user='ric', token='123token456')[source]

Return an instance of the fakeapi.FakeAPI, configured for the tests.

Return type:

LocalAPI

repobee_testhelpers.funcs.get_repos(platform_url, org_name='fall2020')[source]

Get all repos from the given platform and organization.

Parameters:
  • platform_url (str) – URL to the directory used by the fakeapi.FakeAPI.

  • org_name (str) – The organization to get repos from.

Return type:

List[Repo]

Returns:

A list of fake repos.

repobee_testhelpers.funcs.get_student_teams(platform_url, org_name='fall2020')[source]

Like get_platform_teams(), but converts each team to a StudentTeam. for easier comparison.

Parameters:
  • platform_url (str) – URL to the directory used by the fakeapi.FakeAPI.

  • org_name (str) – The organization to get repos from.

Return type:

List[StudentTeam]

Returns:

A list of student teams.

repobee_testhelpers.funcs.get_teams(platform_url, org_name='fall2020')[source]

Get all of the teams from the given platform and organization. Note that this returns the actual platform implementation of Team.

Parameters:
  • platform_url (str) – URL to the directory used by the fakeapi.FakeAPI.

  • org_name (str) – The organization to get repos from.

Return type:

List[Team]

Returns:

A list of platform teams.

repobee_testhelpers.funcs.hash_directory(dirpath)[source]

Compute the directory hash using Git.

Parameters:

dirpath (Union[str, Path]) – Path to a directory.

Return type:

str

Returns:

The hash of the root tree of the directory.

repobee_testhelpers.funcs.initialize_repo(path, default_branch='master')[source]

Initialize the directory to a Git repo and commit all files in it.

Parameters:
  • path (Path) – Path to the directory to turn into a Git repository.

  • default_branch (str) – Name of the default branch to use.

Return type:

Repo

Returns:

A repo.

repobee_testhelpers.funcs.run_repobee(cmd, **kwargs)[source]

Helper function to call repobee.run when using the fakeapi.FakeAPI platform API.

This function will by default use a config file that sets appropriate values for students_file, user, org_name and template_org_name for use with the FakeAPI platform API. If you wish to use a different config, simply pass config_file="/path/to/your/config" to the function, or config_file="" to not use a config file at all.

The FakeAPI plugin is always loaded last, so it is the not possible to use another platform API with this function. If you wish to do so, you should use :py:class`repobee.run` directly instead.

Parameters:
Return type:

Mapping[str, List[Result]]

Returns:

The results mapping returned by repobee.run()

repobee_testhelpers.funcs.template_repo_hashes()[source]

Get hashes for the template repos.

Return type:

Mapping[str, str]

Returns:

A mapping (template_repo_name -> hash)

repobee_testhelpers.funcs.tree_hash(repo_root)[source]

Get the hash of the HEAD tree object of this repository.

Parameters:

repo_root (Path) – Path to the root of a Git repository.

Return type:

str

Returns:

The hash of the root tree object.

repobee_testhelpers.funcs.update_repository(repo_url)[source]

Context manager for updating a Git repository. Clones the repository from the given url, yields the path to the cloned directory, and then commits and pushes any changes after the context has been exited.

Parameters:

repo_url (str) – URL to a Git repository.

Return type:

Iterator[Path]

Returns:

A context manager that yields a path to the local repository.

const

Constants for use in tests.

localapi

A local implementation of the repobee_plug.PlatformAPI specification that can be used to test RepoBee and plugins.

Danger

This module is in alpha version, and its behavior may change without notice.

class repobee_testhelpers.localapi.FakeAPIHooks(plugin_name)[source]
class repobee_testhelpers.localapi.Issue(title, body, number, created_at, author, state, assignees)[source]
class repobee_testhelpers.localapi.LocalAPI(base_url, org_name, user, token)[source]

A local implementation of the repobee_plug.PlatformAPI specification, which emulates a GitHub-like platform without accessing any network resources.

assign_members(team, members, permission=TeamPermission.PUSH)[source]

See repobee_plug.PlatformAPI.assign_members().

Return type:

None

assign_repo(team, repo, permission)[source]

See repobee_plug.PlatformAPI.assign_repo().

Return type:

None

close_issue(issue)[source]

See repobee_plug.PlatformAPI.close_issue().

Return type:

None

create_issue(title, body, repo, assignees=None)[source]

See repobee_plug.PlatformAPI.create_issue().

Return type:

Issue

create_repo(name, description, private, team=None)[source]

See repobee_plug.PlatformAPI.create_repo().

Return type:

Repo

create_team(name, members=None, permission=TeamPermission.PUSH)[source]

See repobee_plug.PlatformAPI.create_team().

Return type:

Team

delete_repo(repo)[source]

See repobee_plug.PlatformAPI.delete_repo().

Return type:

None

delete_team(team)[source]

See repobee_plug.PlatformAPI.delete_team().

Return type:

None

extract_repo_name(repo_url)[source]

Extract a repo name from the provided url.

Parameters:

repo_url (str) – A URL to a repository.

Return type:

str

Returns:

The name of the repository corresponding to the url.

for_organization(org_name)[source]

See repobee_plug.PlatformAPI.for_organization().

Return type:

LocalAPI

get_repo(repo_name, team_name)[source]

See repobee_plug.PlatformAPI.get_repo().

Return type:

Repo

get_repo_issues(repo)[source]

See repobee_plug.PlatformAPI.get_repo_issues().

Return type:

Iterable[Issue]

get_repo_urls(assignment_names, org_name=None, team_names=None, insert_auth=False)[source]

Get repo urls for all specified repo names in the organization. As checking if every single repo actually exists takes a long time with a typical REST API, this function does not in general guarantee that the urls returned actually correspond to existing repos.

If the org_name argument is supplied, urls are computed relative to that organization. If it is not supplied, the target organization is used.

If the teams argument is supplied, student repo urls are computed instead of master repo urls.

Parameters:
  • assignment_names (Iterable[str]) – A list of master repository names.

  • org_name (Optional[str]) – Organization in which repos are expected. Defaults to the target organization of the API instance.

  • team_names (Optional[List[str]]) – A list of team names specifying student groups.

Return type:

List[str]

Returns:

a list of urls corresponding to the repo names.

get_repos(repo_urls=None)[source]

See repobee_plug.PlatformAPI.get_repos().

Return type:

Iterable[Repo]

get_team_repos(team)[source]

See repobee_plug.PlatformAPI.get_team_repos().

Return type:

Iterable[Repo]

get_teams(team_names=None)[source]

See repobee_plug.PlatformAPI.get_teams().

Return type:

Iterable[Team]

insert_auth(url)[source]

See repobee_plug.PlatformAPI.insert_auth().

Return type:

str

static verify_settings(user, org_name, base_url, token, template_org_name=None)[source]

Verify the following (to the extent that is possible and makes sense for the specific platform):

  1. An internet connection is available

  2. Base url is correct

  3. The token has sufficient access privileges

  4. Target organization (specifiend by org_name) exists
    • If template_org_name is supplied, this is also checked to exist.

  5. User is owner in organization (verify by getting
    • If template_org_name is supplied, user is also checked to be an owner of it.

organization member list and checking roles)

Should raise an appropriate subclass of PlatformError when a problem is encountered.

Parameters:
  • user (str) – The username to try to fetch.

  • org_name (str) – Name of the target organization.

  • base_url (str) – A base url to a github API.

  • token (str) – A secure OAUTH2 token.

  • org_name – Name of the master organization.

Return type:

None

Returns:

True if the connection is well formed.

Raises:

PlatformError

class repobee_testhelpers.localapi.PlatformState(teams, repos, users)[source]
class repobee_testhelpers.localapi.Repo(name, description, url, private, path, issues=<factory>)[source]
class repobee_testhelpers.localapi.Team(name, members, permission, id, repos=<factory>)[source]
class repobee_testhelpers.localapi.User(username)[source]