Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- vagrant@(none):/srv/nemesis/test/api-tests (ticket2162)$ git diff HEAD^ ../../nemesis/app.py apache_tests.sh test_users_post.py
- diff --git a/nemesis/app.py b/nemesis/app.py
- index 49ecca7..78eeb04 100644
- --- a/nemesis/app.py
- +++ b/nemesis/app.py
- @@ -152,6 +152,8 @@ def set_user_details(userid):
- user_to_update.make_student()
- elif request.form["new_type"] == 'team-leader':
- user_to_update.make_teacher()
- + if request.form.has_key("withdrawn") and request.form['withdrawn'] == 'true' and ah.user.can_withdraw(user_to_update):
- + user_to_update.withdraw()
- user_to_update.save()
- @@ -160,6 +162,7 @@ def set_user_details(userid):
- if request.form.has_key("new_password"):
- user_to_update.set_password(request.form["new_password"])
- + print(ah.user.can_withdraw(user_to_update))
- return '{}', 200
- else:
- return ah.auth_error_json, 403
- diff --git a/test/api-tests/apache_tests.sh b/test/api-tests/apache_tests.sh
- index 4992f3a..a5508ad 100755
- --- a/test/api-tests/apache_tests.sh
- +++ b/test/api-tests/apache_tests.sh
- @@ -1,3 +1,4 @@
- +python ../../nemesis/libnemesis/tests/reset_ldap.py
- service httpd restart
- sleep 1
- touch .apachetest
- diff --git a/test/api-tests/test_users_post.py b/test/api-tests/test_users_post.py
- index 97243b4..6f364f0 100644
- --- a/test/api-tests/test_users_post.py
- +++ b/test/api-tests/test_users_post.py
- @@ -1,8 +1,9 @@
- +from nose.tools import with_setup
- import test_helpers
- import sys
- sys.path.append("../../nemesis/libnemesis")
- -from libnemesis import User
- +from libnemesis import User, srusers
- def test_post_no_user():
- r,data = test_helpers.server_post("/user/student_coll1_1")
- @@ -240,6 +241,8 @@ def test_post_blueshirt_cant_set_team():
- }
- r,data = test_helpers.server_post("/user/student_coll1_1", params)
- + print(r.status)
- + print(r)
- assert r.status == 200
- u = User("student_coll1_1")
- @@ -296,3 +299,48 @@ def test_post_teacher_cant_set_other_team():
- u = User("student_coll1_1")
- teams = [t.name for t in u.teams]
- assert [old_team] == teams
- +
- +current_user_groups = None
- +
- +def replace_group_with(username, groupName, replacements):
- + group = srusers.group(groupName)
- + group.user_rm("student_coll1_1")
- + group.save()
- + for gname in replacements:
- + grp = srusers.group(gname)
- + grp.user_add("student_coll1_1")
- + grp.save()
- +
- +@with_setup(None, replace_group_with('student_coll1_1', 'withdrawn', srusers.user("student_coll1_1").groups()))
- +def test_post_teacher_can_withdraw_student():
- + params = {"username":"teacher_coll1",
- + "password":"facebees",
- + "withdraw":'true',
- + }
- +
- + r, data = test_helpers.server_post("/user/student_coll1_1", params)
- + assert r.status == 200
- +
- + assert User("student_coll1_1").has_withdrawn
- +
- +def test_post_student_cant_withdraw_other_student():
- + params = {"username":"student_coll1_1",
- + "password":"cows",
- + "withdraw":'true',
- + }
- +
- + r, data = test_helpers.server_post("/user/student_coll1_2", params)
- + assert r.status == 403
- +
- + assert not User("student_coll1_2").has_withdrawn
- +
- +def test_post_teacher_cant_withdraw_self():
- + params = {"username":"teacher_coll1",
- + "password":"facebees",
- + "withdraw":'true',
- + }
- +
- + r, data = test_helpers.server_post("/user/teacher_coll1", params)
- + assert r.status == 200
- +
- + assert not User("teacher_coll1").has_withdrawn
- vagrant@(none):/srv/nemesis/test/api-tests (ticket2162)$ sudo ./apache_tests.sh
- adding new entry "uid=teacher_coll1,ou=users,o=sr"
- adding new entry "uid=teacher_coll2,ou=users,o=sr"
- adding new entry "uid=student_coll1_1,ou=users,o=sr"
- adding new entry "uid=student_coll1_2,ou=users,o=sr"
- adding new entry "uid=student_coll2_1,ou=users,o=sr"
- adding new entry "uid=student_coll2_2,ou=users,o=sr"
- adding new entry "uid=blueshirt,ou=users,o=sr"
- adding new entry "uid=withdrawn_student,ou=users,o=sr"
- adding new entry "cn=college-1,ou=groups,o=sr"
- adding new entry "cn=college-2,ou=groups,o=sr"
- adding new entry "cn=teachers,ou=groups,o=sr"
- adding new entry "cn=students,ou=groups,o=sr"
- adding new entry "cn=team-ABC,ou=groups,o=sr"
- adding new entry "cn=team-DFE,ou=groups,o=sr"
- adding new entry "cn=team-QWZ,ou=groups,o=sr"
- adding new entry "cn=mentors,ou=groups,o=sr"
- adding new entry "cn=withdrawn,ou=groups,o=sr"
- Redirecting to /bin/systemctl restart httpd.service
- .....................................................FFF..F....F...F..
- ======================================================================
- FAIL: test_users_post.test_post_sets_own_password
- ----------------------------------------------------------------------
- Traceback (most recent call last):
- File "/usr/lib/python2.7/site-packages/nose/case.py", line 197, in runTest
- self.test(*self.arg)
- AssertionError
- ======================================================================
- FAIL: test_users_post.test_post_sets_own_password_and_name
- ----------------------------------------------------------------------
- Traceback (most recent call last):
- File "/usr/lib/python2.7/site-packages/nose/case.py", line 197, in runTest
- self.test(*self.arg)
- File "/srv/nemesis/test/api-tests/test_users_post.py", line 96, in test_post_sets_own_password_and_name
- assert r.status == 200
- AssertionError
- ======================================================================
- FAIL: test_users_post.test_post_sets_first_last_name
- ----------------------------------------------------------------------
- Traceback (most recent call last):
- File "/usr/lib/python2.7/site-packages/nose/case.py", line 197, in runTest
- self.test(*self.arg)
- File "/srv/nemesis/test/api-tests/test_users_post.py", line 121, in test_post_sets_first_last_name
- assert r.status == 200
- AssertionError
- ======================================================================
- FAIL: test_users_post.test_student_post_doesnt_set_first_last_name
- ----------------------------------------------------------------------
- Traceback (most recent call last):
- File "/usr/lib/python2.7/site-packages/nose/case.py", line 197, in runTest
- self.test(*self.arg)
- File "/srv/nemesis/test/api-tests/test_users_post.py", line 174, in test_student_post_doesnt_set_first_last_name
- assert details_dict["first_name"] == old_first
- AssertionError
- ======================================================================
- FAIL: test_users_post.test_post_blueshirt_cant_set_team
- ----------------------------------------------------------------------
- Traceback (most recent call last):
- File "/usr/lib/python2.7/site-packages/nose/case.py", line 197, in runTest
- self.test(*self.arg)
- File "/srv/nemesis/test/api-tests/test_users_post.py", line 246, in test_post_blueshirt_cant_set_team
- assert r.status == 200
- AssertionError:
- -------------------- >> begin captured stdout << ---------------------
- 403
- <httplib.HTTPResponse instance at 0xb6e2ceac>
- --------------------- >> end captured stdout << ----------------------
- ======================================================================
- FAIL: test_users_post.test_post_teacher_can_withdraw_student
- ----------------------------------------------------------------------
- Traceback (most recent call last):
- File "/usr/lib/python2.7/site-packages/nose/case.py", line 197, in runTest
- self.test(*self.arg)
- File "/srv/nemesis/test/api-tests/test_users_post.py", line 324, in test_post_teacher_can_withdraw_student
- assert User("student_coll1_1").has_withdrawn
- AssertionError
- ----------------------------------------------------------------------
- Ran 70 tests in 24.819s
- FAILED (failures=6)
Advertisement
Add Comment
Please, Sign In to add comment