Skip to content

Commit

Permalink
Merge pull request #33 from mitodl/itsbenweeks/optional_group
Browse files Browse the repository at this point in the history
Making the -g flag optional for `create_xml_repo`
  • Loading branch information
carsongee committed May 26, 2015
2 parents c25daf0 + 46b7524 commit f4a9a5d
Show file tree
Hide file tree
Showing 6 changed files with 110 additions and 7 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,4 @@ docs/_build/
target/

# For loading up local environment
.env
.env
13 changes: 11 additions & 2 deletions orcoursetrion/actions/github.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,14 +125,18 @@ def release_studio(course, term):
)


def create_xml_repo(course, term, team, members=None, description=None):
def create_xml_repo(course, term, team=None, members=None, description=None):
"""Creates a course repo at
:py:const:`~orcoursetrion.config.ORC_GH_API_URL` with key
:py:const:`~orcoursetrion.config.ORC_GH_OAUTH2_TOKEN` and at
organization :py:const:`~orcoursetrion.config.ORC_XML_ORG`, and
with ``team`` as a collaborator (Along with
:py:const:`~orcoursetrion.config.ORC_XML_DEPLOY_TEAM`).
If ``team`` is not provided, then it will be generated with
:py:const:`~orcoursetrion.config.ORC_COURSE_PREFIX`, ``course``,
and ``term``
If ``members`` is provided, the ``team`` membership will be
*replaced* with the members listed. It will also create the team if
it doesn't already exist regardless of the value of ``members``.
Expand Down Expand Up @@ -171,7 +175,12 @@ def create_xml_repo(course, term, team, members=None, description=None):
github.add_team_repo(
config.ORC_XML_ORG, repo_name, config.ORC_XML_DEPLOY_TEAM
)
# Setup the passed in team

# Team matches repo_name if no team is passed.
if team is None:
team = repo_name

# Setup the team
github.put_team(config.ORC_XML_ORG, team, False, members)
github.add_team_repo(config.ORC_XML_ORG, repo_name, team)

Expand Down
7 changes: 4 additions & 3 deletions orcoursetrion/cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,12 +153,13 @@ def execute():
help='Term of the course (i.e. Spring_2015)'
)
create_xml_repo.add_argument(
'-g', '--team', type=str, required=True,
help='Name of team in organization that should have access'
'-g', '--team', type=str, default=None,
help='Name of team in organization that should have access, creates' +
' new team with the same name as the repository if empty.'
)
create_xml_repo.add_argument(
'-m', '--member', nargs='*', type=str,
help='One or more usernames to replace the membership of the team'
help='One or more usernames to replace/add to team membership.'
)
create_xml_repo.add_argument(
'-d', '--description', type=str,
Expand Down
5 changes: 5 additions & 0 deletions orcoursetrion/tests/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,11 @@ def callback_team_list(
'id': 1,
'name': self.TEST_TEAM
},

{
'id': 1,
'name': self.TEST_REPO
}
]
page2 = [
{
Expand Down
18 changes: 18 additions & 0 deletions orcoursetrion/tests/test_cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,24 @@ def test_cmd_create_xml_repo(self):
['archlight', 'dreadnought'],
self.TEST_DESCRIPTION
)
args = [
'orcoursetrion', 'create_xml_repo',
'-c', self.TEST_COURSE,
'-t', self.TEST_TERM,
'-d', self.TEST_DESCRIPTION,
'-m', 'archlight', 'dreadnought',
]
with mock.patch('sys.argv', args):
with mock.patch('orcoursetrion.cmd.actions') as mocked_actions:
execute()
self.assertTrue(mocked_actions.create_xml_repo.called)
mocked_actions.create_xml_repo.assert_called_with(
self.TEST_COURSE,
self.TEST_TERM,
None,
['archlight', 'dreadnought'],
self.TEST_DESCRIPTION
)

def test_cmd_rerun_xml(self):
"""
Expand Down
72 changes: 71 additions & 1 deletion orcoursetrion/tests/test_github.py
Original file line number Diff line number Diff line change
Expand Up @@ -551,7 +551,7 @@ def test_actions_release_studio_success(self, config):

@mock.patch('orcoursetrion.actions.github.config')
@httpretty.activate
def test_actions_create_xml_repo_success(self, config):
def test_actions_create_xml_repo_success_old_team(self, config):
"""Test the API call comes through as expected.
"""
config.ORC_GH_OAUTH2_TOKEN = self.OAUTH2_TOKEN
Expand All @@ -572,13 +572,37 @@ def test_actions_create_xml_repo_success(self, config):
status=201
)

# Create a repo with an old team.
create_xml_repo(
course=self.TEST_COURSE,
term=self.TEST_TERM,
team=self.TEST_TEAM,
description=self.TEST_DESCRIPTION,
)

@mock.patch('orcoursetrion.actions.github.config')
@httpretty.activate
def test_actions_create_xml_repo_success_new_team(self, config):
"""Test the API call comes through as expected.
"""
config.ORC_GH_OAUTH2_TOKEN = self.OAUTH2_TOKEN
config.ORC_GH_API_URL = self.URL
config.ORC_COURSE_PREFIX = self.TEST_PREFIX
config.ORC_XML_ORG = self.ORG
config.ORC_XML_DEPLOY_TEAM = self.TEST_TEAM
config.ORC_STAGING_GITRELOAD = self.TEST_STAGING_GR

self.register_repo_check(self.callback_repo_check)
self.register_repo_create(self.callback_repo_create)
self.register_team_list(
partial(self.callback_team_list, more=True)
)
self.register_team_repo_add(self.callback_team_repo)
self.register_hook_create(
body=json.dumps({'id': 1}),
status=201
)

# Now create repo with a new team
member_changes = []
member_list = ['fenris']
Expand All @@ -603,6 +627,52 @@ def test_actions_create_xml_repo_success(self, config):
member_changes
)

@mock.patch('orcoursetrion.actions.github.config')
@httpretty.activate
def test_actions_create_xml_repo_success_no_team(self, config):
"""Test the API call comes through as expected.
"""
config.ORC_GH_OAUTH2_TOKEN = self.OAUTH2_TOKEN
config.ORC_GH_API_URL = self.URL
config.ORC_COURSE_PREFIX = self.TEST_PREFIX
config.ORC_XML_ORG = self.ORG
config.ORC_XML_DEPLOY_TEAM = self.TEST_TEAM
config.ORC_STAGING_GITRELOAD = self.TEST_STAGING_GR

self.register_repo_check(self.callback_repo_check)
self.register_repo_create(self.callback_repo_create)
self.register_team_list(
partial(self.callback_team_list, more=True)
)
self.register_team_repo_add(self.callback_team_repo)
self.register_hook_create(
body=json.dumps({'id': 1}),
status=201
)

# Now create repo without a team
member_changes = []
member_list = ['andrea', 'andreas']
self.register_team_members(
partial(self.callback_team_members, members=[])
)
self.register_team_create(
partial(self.callback_team_create, read_only=False)
)
self.register_team_membership(
partial(self.callback_team_membership, action_list=member_changes)
)
create_xml_repo(
course=self.TEST_COURSE,
term=self.TEST_TERM,
members=member_list,
description=self.TEST_DESCRIPTION
)
self.assertItemsEqual(
[(unicode(x), True) for x in member_list],
member_changes
)

@mock.patch('orcoursetrion.actions.github.config')
@httpretty.activate
def test_actions_rerun_xml_success(self, config):
Expand Down

0 comments on commit f4a9a5d

Please sign in to comment.