Skip to content

Commit

Permalink
Merge branch 'master' into stable
Browse files Browse the repository at this point in the history
  • Loading branch information
rkevin-arch committed May 29, 2020
2 parents 78ebab7 + 99abe05 commit 74a4c88
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,24 @@ def get_username():


def ngshare_url():
if 'PROXY_PUBLIC_SERVICE_HOST' in os.environ:
return 'http://proxy-public/services/ngshare'
else:
# replace this with correct URL if you are not using a kubernetes set up
return 'http://127.0.0.1:12121/api'
global _ngshare_url
try:
return _ngshare_url
except NameError:
try:
from nbgrader.apps import NbGrader

nbgrader = NbGrader()
nbgrader.load_config_file()
exchange = nbgrader.config.ExchangeFactory.exchange()
_ngshare_url = exchange.ngshare_url
return _ngshare_url
except Exception as e:
prRed(
"Cannot determine ngshare URL. Please check your nbgrader_config.py!",
False,
)
prRed(e)


def get_header():
Expand Down
48 changes: 25 additions & 23 deletions ngshare_exchange/tests/test_course_management.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from requests_mock import Mocker
import urllib
import tempfile
from .. import ngshare_management as nm
from .. import course_management as cm
from io import StringIO


Expand All @@ -31,6 +31,8 @@ def parse_body(body: str):


NGSHARE_URL = 'http://127.0.0.1:12121/api'
global _ngshare_url
cm._ngshare_url = NGSHARE_URL


class TestCourseManagement:
Expand Down Expand Up @@ -184,23 +186,23 @@ def test_crete_course(self, capsys):
course_id=self.course_id,
instructors=self.instructors,
)
nm.execute_command(cmd)
cm.execute_command(cmd)
out, err = capsys.readouterr()
out = remove_color(out)
assert ' Successfully created {}\n'.format(self.course_id) in out

# test missing course id
with pytest.raises(SystemExit) as se:
cmd = self.form_command('create_course')
nm.execute_command(cmd)
cm.execute_command(cmd)
assert se.type == SystemExit
assert se.value.code == -1

# try to create course again
self._mock_create_course()
with pytest.raises(SystemExit) as se:
cmd = self.form_command('create_course', course_id=self.course_id)
nm.execute_command(cmd)
cm.execute_command(cmd)
out, err = capsys.readouterr()
assert ' Course already exists' in out
assert se.type == SystemExit
Expand All @@ -210,14 +212,14 @@ def test_add_student(self, capsys):
# test missing course id
with pytest.raises(SystemExit) as se:
cmd = self.form_command('add_student')
nm.execute_command(cmd)
cm.execute_command(cmd)
assert se.type == SystemExit
assert se.value.code == -1

# test missing student id
with pytest.raises(SystemExit) as se:
cmd = self.form_command('add_student', course_id=self.course_id)
nm.execute_command(cmd)
cm.execute_command(cmd)
assert se.type == SystemExit
assert se.value.code == -1

Expand All @@ -230,7 +232,7 @@ def test_add_student(self, capsys):
last_name='doe',
email='[email protected]',
)
nm.execute_command(cmd)
cm.execute_command(cmd)
out, err = capsys.readouterr()
assert 'Successfully added/updated {}'.format(self.student_id) in out

Expand All @@ -239,14 +241,14 @@ def test_add_students(self, capsys, tmp_path):
# test no course id
with pytest.raises(SystemExit) as se:
cmd = self.form_command('add_students')
nm.execute_command(cmd)
cm.execute_command(cmd)
assert se.type == SystemExit
assert se.value.code == -1

# test no file
with pytest.raises(SystemExit) as se:
cmd = self.form_command('add_students', course_id=self.course_id)
nm.execute_command(cmd)
cm.execute_command(cmd)
assert se.type == SystemExit
assert se.value.code == -1

Expand All @@ -255,7 +257,7 @@ def test_add_students(self, capsys, tmp_path):
cmd = self.form_command(
'add_students', course_id=self.course_id, students_csv='dne'
)
nm.execute_command(cmd)
cm.execute_command(cmd)

assert se.type == SystemExit
assert se.value.code == -1
Expand All @@ -274,7 +276,7 @@ def test_add_students(self, capsys, tmp_path):
cmd = self.form_command(
'add_students', course_id=self.course_id, students_csv=f.name,
)
nm.execute_command(cmd)
cm.execute_command(cmd)
out, err = capsys.readouterr()
assert 'sid1 was sucessfuly added to math101' in out
assert 'sid2 was sucessfuly added to math101' in out
Expand All @@ -285,14 +287,14 @@ def test_add_instructor(self, capsys):
# test no course id
with pytest.raises(SystemExit) as se:
cmd = self.form_command('add_instructor')
nm.execute_command(cmd)
cm.execute_command(cmd)
assert se.type == SystemExit
assert se.value.code == -1

# test no instructor id
with pytest.raises(SystemExit) as se:
cmd = self.form_command('add_instructor', course_id=self.course_id)
nm.execute_command(cmd)
cm.execute_command(cmd)
assert se.type == SystemExit
assert se.value.code == -1

Expand All @@ -305,7 +307,7 @@ def test_add_instructor(self, capsys):
last_name='doe',
email='[email protected]',
)
nm.execute_command(cmd)
cm.execute_command(cmd)
out, err = capsys.readouterr()
assert (
'Successfully added {} as an instructor to {}'.format(
Expand All @@ -320,14 +322,14 @@ def test_remove_student(self, capsys):
# test missing course id
with pytest.raises(SystemExit) as se:
cmd = self.form_command('remove_student')
nm.execute_command(cmd)
cm.execute_command(cmd)
assert se.type == SystemExit
assert se.value.code == -1

# test missing student id
with pytest.raises(SystemExit) as se:
cmd = self.form_command('remove_student', course_id=self.course_id)
nm.execute_command(cmd)
cm.execute_command(cmd)
assert se.type == SystemExit
assert se.value.code == -1

Expand All @@ -337,7 +339,7 @@ def test_remove_student(self, capsys):
course_id=self.course_id,
student_id=self.student_id,
)
nm.execute_command(cmd)
cm.execute_command(cmd)
out, err = capsys.readouterr()
assert (
'Successfully deleted {} from {}'.format(
Expand All @@ -352,7 +354,7 @@ def test_remove_instructor(self, capsys):
# test missing course id
with pytest.raises(SystemExit) as se:
cmd = self.form_command('remove_instructor')
nm.execute_command(cmd)
cm.execute_command(cmd)
assert se.type == SystemExit
assert se.value.code == -1

Expand All @@ -361,7 +363,7 @@ def test_remove_instructor(self, capsys):
cmd = self.form_command(
'remove_instructor', course_id=self.course_id
)
nm.execute_command(cmd)
cm.execute_command(cmd)
assert se.type == SystemExit
assert se.value.code == -1

Expand All @@ -371,7 +373,7 @@ def test_remove_instructor(self, capsys):
course_id=self.course_id,
instructor_id=self.instructor_id,
)
nm.execute_command(cmd)
cm.execute_command(cmd)
out, err = capsys.readouterr()
assert (
'Successfully deleted instructor {} from {}'.format(
Expand All @@ -384,7 +386,7 @@ def test_add_students_parsing(self, capsys):
# test empty file
with tempfile.NamedTemporaryFile() as f:
with pytest.raises(SystemExit) as se:
nm.add_students(self.course_id, f.name, False)
cm.add_students(self.course_id, f.name, False)
assert se.type == SystemExit
assert se.value.code == -1
out, err = capsys.readouterr()
Expand All @@ -396,7 +398,7 @@ def test_add_students_parsing(self, capsys):
f.flush()

with pytest.raises(SystemExit) as se:
nm.add_students(self.course_id, f.name, False)
cm.add_students(self.course_id, f.name, False)
assert se.type == SystemExit
assert se.value.code == -1
out, err = capsys.readouterr()
Expand All @@ -410,7 +412,7 @@ def test_add_students_parsing(self, capsys):
f.flush()

with pytest.raises(SystemExit) as se:
nm.add_students(self.course_id, f.name, False)
cm.add_students(self.course_id, f.name, False)
assert se.type == SystemExit
assert se.value.code == -1
out, err = capsys.readouterr()
Expand Down
2 changes: 1 addition & 1 deletion ngshare_exchange/version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = '0.1.0'
__version__ = '0.3.0'
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def get_version(rel_path):
],
entry_points={
'console_scripts': [
'ngshare-course-management = ngshare_exchange.ngshare_management:main'
'ngshare-course-management = ngshare_exchange.course_management:main'
]
},
)

0 comments on commit 74a4c88

Please sign in to comment.