Repository: ucfopen/canvasapi

Issue:
Canvas.get_user() no longer accepts 'self' argument
_(Note: this issue only affects the current version of `develop`)_

Previously, it was possible to pass `'self'` as an argument to `Canvas.get_user()` (`canvas.get_user('self')`) instead of an ID.

Somewhere along the line (likely in the wider adoption of `obj_or_id`, #96), this functionality was broken.

Restore this functionality and add a test explicitly testing `'self'` to prevent future regressions.

When #108 is finished, we may ultimately remove this behavior but at that time there will be an adequate replacement for the functionality.

Discussion:

Patch:
diff --git a/canvasapi/canvas.py b/canvasapi/canvas.py
index 0e3f030..687649c 100644
--- a/canvasapi/canvas.py
+++ b/canvasapi/canvas.py
@@ -164,8 +164,9 @@ class Canvas(object):
         :rtype: :class:`canvasapi.user.User`
         """
         if id_type:
-            user_id = user
-            uri = 'users/{}:{}'.format(id_type, user_id)
+            uri = 'users/{}:{}'.format(id_type, user)
+        elif user == 'self':
+            uri = 'users/self'
         else:
             user_id = obj_or_id(user, "user", (User,))
             uri = 'users/{}'.format(user_id)


Test patch:
diff --git a/tests/fixtures/user.json b/tests/fixtures/user.json
index bc71d63..2aa9773 100644
--- a/tests/fixtures/user.json
+++ b/tests/fixtures/user.json
@@ -226,6 +226,14 @@
 			"name": "John Doe"
 		}
 	},
+	"get_by_id_self": {
+		"method": "GET",
+		"endpoint": "users/self",
+		"data": {
+			"id": 1,
+			"name": "John Doe"
+		}
+	},
 	"get_file": {
 		"method": "GET",
 		"endpoint": "users/1/files/1",
diff --git a/tests/test_canvas.py b/tests/test_canvas.py
index e8331ab..dc5ec34 100644
--- a/tests/test_canvas.py
+++ b/tests/test_canvas.py
@@ -149,6 +149,14 @@ class TestCanvas(unittest.TestCase):
         self.assertIsInstance(user, User)
         self.assertTrue(hasattr(user, 'name'))
 
+    def test_get_user_self(self, m):
+        register_uris({'user': ['get_by_id_self']}, m)
+
+        user = self.canvas.get_user('self')
+
+        self.assertIsInstance(user, User)
+        self.assertTrue(hasattr(user, 'name'))
+
     def test_get_user_fail(self, m):
         register_uris({'generic': ['not_found']}, m)