Skip to content

Commit

Permalink
Rename 'team' -> 'org' in test_github
Browse files Browse the repository at this point in the history
Reduce confusion as team and org are used interchangeably
when describing orgs
  • Loading branch information
j0nnyr0berts committed Aug 5, 2021
1 parent 34fb60c commit cb8a884
Showing 1 changed file with 20 additions and 20 deletions.
40 changes: 20 additions & 20 deletions oauthenticator/tests/test_github.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,40 +71,40 @@ async def test_allowed_org_membership(github_client):

## Mock Github API

teams = {
orgs = {
'red': ['grif', 'simmons', 'donut', 'sarge', 'lopez'],
'blue': ['tucker', 'caboose', 'burns', 'sheila', 'texas'],
}

member_regex = re.compile(r'/orgs/(.*)/members')

def team_members(paginate, request):
def org_members(paginate, request):
urlinfo = urlparse(request.url)
team = member_regex.match(urlinfo.path).group(1)
org = member_regex.match(urlinfo.path).group(1)

if team not in teams:
if org not in orgs:
return HTTPResponse(request, 404)

if not paginate:
return [user_model(m) for m in teams[team]]
return [user_model(m) for m in orgs[org]]
else:
page = parse_qs(urlinfo.query).get('page', ['1'])
page = int(page[0])
return team_members_paginated(
team, page, urlinfo, functools.partial(HTTPResponse, request)
return org_members_paginated(
org, page, urlinfo, functools.partial(HTTPResponse, request)
)

def team_members_paginated(team, page, urlinfo, response):
if page < len(teams[team]):
def org_members_paginated(org, page, urlinfo, response):
if page < len(orgs[org]):
headers = make_link_header(urlinfo, page + 1)
elif page == len(teams[team]):
elif page == len(orgs[org]):
headers = {}
else:
return response(400)

headers.update({'Content-Type': 'application/json'})

ret = [user_model(teams[team][page - 1])]
ret = [user_model(orgs[org][page - 1])]

return response(
200,
Expand All @@ -114,26 +114,26 @@ def team_members_paginated(team, page, urlinfo, response):

membership_regex = re.compile(r'/orgs/(.*)/members/(.*)')

def team_membership(request):
def org_membership(request):
urlinfo = urlparse(request.url)
urlmatch = membership_regex.match(urlinfo.path)
team = urlmatch.group(1)
org = urlmatch.group(1)
username = urlmatch.group(2)
print('Request team = %s, username = %s' % (team, username))
if team not in teams:
print('Team not found: team = %s' % (team))
print('Request org = %s, username = %s' % (org, username))
if org not in orgs:
print('Team not found: org = %s' % (org))
return HTTPResponse(request, 404)
if username not in teams[team]:
print('Member not found: team = %s, username = %s' % (team, username))
if username not in orgs[org]:
print('Member not found: org = %s, username = %s' % (org, username))
return HTTPResponse(request, 404)
return HTTPResponse(request, 204)

## Perform tests

for paginate in (False, True):
client_hosts = client.hosts['api.github.com']
client_hosts.append((membership_regex, team_membership))
client_hosts.append((member_regex, functools.partial(team_members, paginate)))
client_hosts.append((membership_regex, org_membership))
client_hosts.append((member_regex, functools.partial(org_members, paginate)))

authenticator.allowed_organizations = ['blue']

Expand Down

0 comments on commit cb8a884

Please sign in to comment.