{"action":"created","comment":{"url":"https://api.github.com/repos/edx/xblock-lti-consumer/pulls/comments/45077253","id":45077253,"diff_hunk":"@@ -0,0 +1,287 @@\n+# -*- coding: utf-8 -*-\n+\"\"\"\n+Unit tests for lti_consumer.lti module\n+\"\"\"\n+\n+import unittest\n+\n+from mock import Mock, PropertyMock, patch\n+\n+from lti_consumer.tests.unit.test_utils import make_request\n+from lti_consumer.tests.unit.test_lti_consumer import TestLtiConsumerXBlock\n+\n+from lti_consumer.lti import parse_result_json, Lti1Consumer, Lti2Consumer\n+from lti_consumer.exceptions import LtiError\n+\n+\n+INVALID_JSON_INPUTS = [\n+    ([\n+        u\"kk\",   # ValueError\n+        u\"{{}\",  # ValueError\n+        u\"{}}\",  # ValueError\n+        3,       # TypeError\n+        {},      # TypeError\n+    ], u\"Supplied JSON string in request body could not be decoded\"),\n+    ([\n+        u\"3\",        # valid json, not array or object\n+        u\"[]\",       # valid json, array too small\n+        u\"[3, {}]\",  # valid json, 1st element not an object\n+    ], u\"Supplied JSON string is a list that does not contain an object as the first element\"),\n+    ([\n+        u'{\"@type\": \"NOTResult\"}',  # @type key must have value 'Result'\n+    ], u\"JSON object does not contain correct @type attribute\"),\n+    ([\n+        # @context missing\n+        u'{\"@type\": \"Result\", \"resultScore\": 0.1}',\n+    ], u\"JSON object does not contain required key\"),\n+    ([\n+        u'''\n+        {\"@type\": \"Result\",\n+         \"@context\": \"http://purl.imsglobal.org/ctx/lis/v2/Result\",\n+         \"resultScore\": 100}'''  # score out of range\n+    ], u\"score value outside the permitted range of 0-1.\"),\n+    ([\n+        u'''\n+        {\"@type\": \"Result\",\n+         \"@context\": \"http://purl.imsglobal.org/ctx/lis/v2/Result\",\n+         \"resultScore\": \"1b\"}''',   # score ValueError\n+        u'''\n+        {\"@type\": \"Result\",\n+         \"@context\": \"http://purl.imsglobal.org/ctx/lis/v2/Result\",\n+         \"resultScore\": {}}''',   # score TypeError\n+    ], u\"Could not convert resultScore to float\"),\n+]\n+\n+VALID_JSON_INPUTS = [\n+    (u'''\n+    {\"@type\": \"Result\",\n+     \"@context\": \"http://purl.imsglobal.org/ctx/lis/v2/Result\",\n+     \"resultScore\": 0.1}''', 0.1, u\"\"),  # no comment means we expect \"\"\n+    (u'''\n+    [{\"@type\": \"Result\",\n+     \"@context\": \"http://purl.imsglobal.org/ctx/lis/v2/Result\",\n+     \"@id\": \"anon_id:abcdef0123456789\",\n+     \"resultScore\": 0.1}]''', 0.1, u\"\"),  # OK to have array of objects -- just take the first.  @id is okay too\n+    (u'''\n+    {\"@type\": \"Result\",\n+     \"@context\": \"http://purl.imsglobal.org/ctx/lis/v2/Result\",\n+     \"resultScore\": 0.1,\n+     \"comment\": \"ಠ益ಠ\"}''', 0.1, u\"ಠ益ಠ\"),  # unicode comment\n+    (u'''\n+    {\"@type\": \"Result\",\n+     \"@context\": \"http://purl.imsglobal.org/ctx/lis/v2/Result\"}''', None, u\"\"),  # no score means we expect None\n+]\n+\n+GET_RESULT_RESPONSE = {\n+    \"@context\": \"http://purl.imsglobal.org/ctx/lis/v2/Result\",\n+    \"@type\": \"Result\",\n+}\n+\n+\n+class TestParseResultJson(unittest.TestCase):\n+    \"\"\"\n+    Unit tests for `lti_consumer.lti.parse_result_json`\n+    \"\"\"\n+\n+    def test_invalid_json(self):\n+        \"\"\"\n+        Test invalid json raises exception\n+        \"\"\"\n+        for error_inputs, error_message in INVALID_JSON_INPUTS:\n+            for error_input in error_inputs:\n+                with self.assertRaisesRegexp(LtiError, error_message):\n+                    parse_result_json(error_input)\n+\n+    def test_valid_json(self):\n+        \"\"\"\n+        Test valid json returns expected values\n+        \"\"\"\n+        for json_str, expected_score, expected_comment in VALID_JSON_INPUTS:\n+            score, comment = parse_result_json(json_str)\n+            self.assertEqual(score, expected_score)\n+            self.assertEqual(comment, expected_comment)\n+\n+\n+class TestLti1Consumer(TestLtiConsumerXBlock):\n+    \"\"\"\n+    Unit tests for Lti1Consumer\n+    \"\"\"\n+\n+    def setUp(self):\n+        super(TestLti1Consumer, self).setUp()\n+        self.lti_consumer = Lti1Consumer(self.xblock)\n+\n+    @patch('lti_consumer.lti.get_oauth_request_signature', Mock(\n+        return_value=(\n+            'OAuth oauth_nonce=\"80966668944732164491378916897\", '\n+            'oauth_timestamp=\"1378916897\", oauth_version=\"1.0\", oauth_signature_method=\"HMAC-SHA1\", '\n+            'oauth_consumer_key=\"t\", oauth_signature=\"frVp4JuvT1mVXlxktiAUjQ7%2F1cw%3D\"'\n+        )\n+    ))\n+    @patch(\n+        'lti_consumer.lti_consumer.LtiConsumerXBlock.prefixed_custom_parameters',\n+        PropertyMock(return_value={u'custom_param_1': 'custom1', u'custom_param_2': 'custom2'})\n+    )\n+    @patch('lti_consumer.lti_consumer.LtiConsumerXBlock.lti_provider_key_secret', PropertyMock(return_value=('t', 's')))\n+    @patch('lti_consumer.lti_consumer.LtiConsumerXBlock.user_id', PropertyMock(return_value='4knx2j'))\n+    def test_get_signed_lti_parameters(self):\n+        \"\"\"\n+        Test `get_signed_lti_parameters` returns the correct dict\n+        \"\"\"\n+        expected_lti_parameters = {","path":"lti_consumer/tests/unit/test_lti.py","position":131,"original_position":131,"commit_id":"0af4bfdb4b26ef0c834b912d124768d35818a5ca","original_commit_id":"ae1053025b4d07e15576648dcf75097c0d9aca16","user":{"login":"douglashall","id":224634,"avatar_url":"https://avatars.githubusercontent.com/u/224634?v=3","gravatar_id":"","url":"https://api.github.com/users/douglashall","html_url":"https://github.com/douglashall","followers_url":"https://api.github.com/users/douglashall/followers","following_url":"https://api.github.com/users/douglashall/following{/other_user}","gists_url":"https://api.github.com/users/douglashall/gists{/gist_id}","starred_url":"https://api.github.com/users/douglashall/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/douglashall/subscriptions","organizations_url":"https://api.github.com/users/douglashall/orgs","repos_url":"https://api.github.com/users/douglashall/repos","events_url":"https://api.github.com/users/douglashall/events{/privacy}","received_events_url":"https://api.github.com/users/douglashall/received_events","type":"User","site_admin":false},"body":"I just want to make sure that `get_signed_lti_parameters` is returning the dictionary that I would expect.","created_at":"2015-11-17T15:56:45Z","updated_at":"2015-11-17T15:56:45Z","html_url":"https://github.com/edx/xblock-lti-consumer/pull/1#discussion_r45077253","pull_request_url":"https://api.github.com/repos/edx/xblock-lti-consumer/pulls/1","_links":{"self":{"href":"https://api.github.com/repos/edx/xblock-lti-consumer/pulls/comments/45077253"},"html":{"href":"https://github.com/edx/xblock-lti-consumer/pull/1#discussion_r45077253"},"pull_request":{"href":"https://api.github.com/repos/edx/xblock-lti-consumer/pulls/1"}}},"pull_request":{"url":"https://api.github.com/repos/edx/xblock-lti-consumer/pulls/1","id":50290964,"html_url":"https://github.com/edx/xblock-lti-consumer/pull/1","diff_url":"https://github.com/edx/xblock-lti-consumer/pull/1.diff","patch_url":"https://github.com/edx/xblock-lti-consumer/pull/1.patch","issue_url":"https://api.github.com/repos/edx/xblock-lti-consumer/issues/1","number":1,"state":"open","locked":false,"title":"Sprint Solutions:Zug PHX-200 PHX-201 XBlock LTI Consumer","user":{"login":"douglashall","id":224634,"avatar_url":"https://avatars.githubusercontent.com/u/224634?v=3","gravatar_id":"","url":"https://api.github.com/users/douglashall","html_url":"https://github.com/douglashall","followers_url":"https://api.github.com/users/douglashall/followers","following_url":"https://api.github.com/users/douglashall/following{/other_user}","gists_url":"https://api.github.com/users/douglashall/gists{/gist_id}","starred_url":"https://api.github.com/users/douglashall/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/douglashall/subscriptions","organizations_url":"https://api.github.com/users/douglashall/orgs","repos_url":"https://api.github.com/users/douglashall/repos","events_url":"https://api.github.com/users/douglashall/events{/privacy}","received_events_url":"https://api.github.com/users/douglashall/received_events","type":"User","site_admin":false},"body":"This PR migrates the LTI XModule component which lives in edx-platform (https://github.com/edx/edx-platform/blob/master/common/lib/xmodule/xmodule/lti_module.py) to this new repository and converts the component to the XBlock API.\r\n\r\nThere is additional refactoring of the LTI XModule code to increase code quality and improve extensibility for when/if we want to add additional LTI spec functionality.\r\n\r\nThe modal window feature described in PHX-200 is also implemented as a part of this PR.\r\n\r\nRelated PRs:\r\nhttps://github.com/edx/xblock-utils/pull/32\r\nhttps://github.com/edx/edx-platform/pull/10600\r\n\r\nSandbox: https://studio-douglashall.sandbox.edx.org/container/block-v1:edX+Test101+course+type@vertical+block@18fab131d1f54ea58ea534333444c6c8","created_at":"2015-11-10T18:22:05Z","updated_at":"2015-11-17T15:56:45Z","closed_at":null,"merged_at":null,"merge_commit_sha":"9da6b6f6bd9ad6c377ecf118f30ddeaed82b489d","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/edx/xblock-lti-consumer/pulls/1/commits","review_comments_url":"https://api.github.com/repos/edx/xblock-lti-consumer/pulls/1/comments","review_comment_url":"https://api.github.com/repos/edx/xblock-lti-consumer/pulls/comments{/number}","comments_url":"https://api.github.com/repos/edx/xblock-lti-consumer/issues/1/comments","statuses_url":"https://api.github.com/repos/edx/xblock-lti-consumer/statuses/0af4bfdb4b26ef0c834b912d124768d35818a5ca","head":{"label":"edx:task/douglashall/PHX-201/xblock_lti_consumer","ref":"task/douglashall/PHX-201/xblock_lti_consumer","sha":"0af4bfdb4b26ef0c834b912d124768d35818a5ca","user":{"login":"edx","id":3179841,"avatar_url":"https://avatars.githubusercontent.com/u/3179841?v=3","gravatar_id":"","url":"https://api.github.com/users/edx","html_url":"https://github.com/edx","followers_url":"https://api.github.com/users/edx/followers","following_url":"https://api.github.com/users/edx/following{/other_user}","gists_url":"https://api.github.com/users/edx/gists{/gist_id}","starred_url":"https://api.github.com/users/edx/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/edx/subscriptions","organizations_url":"https://api.github.com/users/edx/orgs","repos_url":"https://api.github.com/users/edx/repos","events_url":"https://api.github.com/users/edx/events{/privacy}","received_events_url":"https://api.github.com/users/edx/received_events","type":"Organization","site_admin":false},"repo":{"id":45846602,"name":"xblock-lti-consumer","full_name":"edx/xblock-lti-consumer","owner":{"login":"edx","id":3179841,"avatar_url":"https://avatars.githubusercontent.com/u/3179841?v=3","gravatar_id":"","url":"https://api.github.com/users/edx","html_url":"https://github.com/edx","followers_url":"https://api.github.com/users/edx/followers","following_url":"https://api.github.com/users/edx/following{/other_user}","gists_url":"https://api.github.com/users/edx/gists{/gist_id}","starred_url":"https://api.github.com/users/edx/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/edx/subscriptions","organizations_url":"https://api.github.com/users/edx/orgs","repos_url":"https://api.github.com/users/edx/repos","events_url":"https://api.github.com/users/edx/events{/privacy}","received_events_url":"https://api.github.com/users/edx/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/edx/xblock-lti-consumer","description":"","fork":false,"url":"https://api.github.com/repos/edx/xblock-lti-consumer","forks_url":"https://api.github.com/repos/edx/xblock-lti-consumer/forks","keys_url":"https://api.github.com/repos/edx/xblock-lti-consumer/keys{/key_id}","collaborators_url":"https://api.github.com/repos/edx/xblock-lti-consumer/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/edx/xblock-lti-consumer/teams","hooks_url":"https://api.github.com/repos/edx/xblock-lti-consumer/hooks","issue_events_url":"https://api.github.com/repos/edx/xblock-lti-consumer/issues/events{/number}","events_url":"https://api.github.com/repos/edx/xblock-lti-consumer/events","assignees_url":"https://api.github.com/repos/edx/xblock-lti-consumer/assignees{/user}","branches_url":"https://api.github.com/repos/edx/xblock-lti-consumer/branches{/branch}","tags_url":"https://api.github.com/repos/edx/xblock-lti-consumer/tags","blobs_url":"https://api.github.com/repos/edx/xblock-lti-consumer/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/edx/xblock-lti-consumer/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/edx/xblock-lti-consumer/git/refs{/sha}","trees_url":"https://api.github.com/repos/edx/xblock-lti-consumer/git/trees{/sha}","statuses_url":"https://api.github.com/repos/edx/xblock-lti-consumer/statuses/{sha}","languages_url":"https://api.github.com/repos/edx/xblock-lti-consumer/languages","stargazers_url":"https://api.github.com/repos/edx/xblock-lti-consumer/stargazers","contributors_url":"https://api.github.com/repos/edx/xblock-lti-consumer/contributors","subscribers_url":"https://api.github.com/repos/edx/xblock-lti-consumer/subscribers","subscription_url":"https://api.github.com/repos/edx/xblock-lti-consumer/subscription","commits_url":"https://api.github.com/repos/edx/xblock-lti-consumer/commits{/sha}","git_commits_url":"https://api.github.com/repos/edx/xblock-lti-consumer/git/commits{/sha}","comments_url":"https://api.github.com/repos/edx/xblock-lti-consumer/comments{/number}","issue_comment_url":"https://api.github.com/repos/edx/xblock-lti-consumer/issues/comments{/number}","contents_url":"https://api.github.com/repos/edx/xblock-lti-consumer/contents/{+path}","compare_url":"https://api.github.com/repos/edx/xblock-lti-consumer/compare/{base}...{head}","merges_url":"https://api.github.com/repos/edx/xblock-lti-consumer/merges","archive_url":"https://api.github.com/repos/edx/xblock-lti-consumer/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/edx/xblock-lti-consumer/downloads","issues_url":"https://api.github.com/repos/edx/xblock-lti-consumer/issues{/number}","pulls_url":"https://api.github.com/repos/edx/xblock-lti-consumer/pulls{/number}","milestones_url":"https://api.github.com/repos/edx/xblock-lti-consumer/milestones{/number}","notifications_url":"https://api.github.com/repos/edx/xblock-lti-consumer/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/edx/xblock-lti-consumer/labels{/name}","releases_url":"https://api.github.com/repos/edx/xblock-lti-consumer/releases{/id}","created_at":"2015-11-09T15:21:44Z","updated_at":"2015-11-09T15:21:44Z","pushed_at":"2015-11-16T20:44:19Z","git_url":"git://github.com/edx/xblock-lti-consumer.git","ssh_url":"git@github.com:edx/xblock-lti-consumer.git","clone_url":"https://github.com/edx/xblock-lti-consumer.git","svn_url":"https://github.com/edx/xblock-lti-consumer","homepage":null,"size":84,"stargazers_count":0,"watchers_count":0,"language":null,"has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":1,"forks":0,"open_issues":1,"watchers":0,"default_branch":"master"}},"base":{"label":"edx:master","ref":"master","sha":"3ee67dcc3218c10d78a98374dc901ad6380e58d5","user":{"login":"edx","id":3179841,"avatar_url":"https://avatars.githubusercontent.com/u/3179841?v=3","gravatar_id":"","url":"https://api.github.com/users/edx","html_url":"https://github.com/edx","followers_url":"https://api.github.com/users/edx/followers","following_url":"https://api.github.com/users/edx/following{/other_user}","gists_url":"https://api.github.com/users/edx/gists{/gist_id}","starred_url":"https://api.github.com/users/edx/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/edx/subscriptions","organizations_url":"https://api.github.com/users/edx/orgs","repos_url":"https://api.github.com/users/edx/repos","events_url":"https://api.github.com/users/edx/events{/privacy}","received_events_url":"https://api.github.com/users/edx/received_events","type":"Organization","site_admin":false},"repo":{"id":45846602,"name":"xblock-lti-consumer","full_name":"edx/xblock-lti-consumer","owner":{"login":"edx","id":3179841,"avatar_url":"https://avatars.githubusercontent.com/u/3179841?v=3","gravatar_id":"","url":"https://api.github.com/users/edx","html_url":"https://github.com/edx","followers_url":"https://api.github.com/users/edx/followers","following_url":"https://api.github.com/users/edx/following{/other_user}","gists_url":"https://api.github.com/users/edx/gists{/gist_id}","starred_url":"https://api.github.com/users/edx/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/edx/subscriptions","organizations_url":"https://api.github.com/users/edx/orgs","repos_url":"https://api.github.com/users/edx/repos","events_url":"https://api.github.com/users/edx/events{/privacy}","received_events_url":"https://api.github.com/users/edx/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/edx/xblock-lti-consumer","description":"","fork":false,"url":"https://api.github.com/repos/edx/xblock-lti-consumer","forks_url":"https://api.github.com/repos/edx/xblock-lti-consumer/forks","keys_url":"https://api.github.com/repos/edx/xblock-lti-consumer/keys{/key_id}","collaborators_url":"https://api.github.com/repos/edx/xblock-lti-consumer/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/edx/xblock-lti-consumer/teams","hooks_url":"https://api.github.com/repos/edx/xblock-lti-consumer/hooks","issue_events_url":"https://api.github.com/repos/edx/xblock-lti-consumer/issues/events{/number}","events_url":"https://api.github.com/repos/edx/xblock-lti-consumer/events","assignees_url":"https://api.github.com/repos/edx/xblock-lti-consumer/assignees{/user}","branches_url":"https://api.github.com/repos/edx/xblock-lti-consumer/branches{/branch}","tags_url":"https://api.github.com/repos/edx/xblock-lti-consumer/tags","blobs_url":"https://api.github.com/repos/edx/xblock-lti-consumer/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/edx/xblock-lti-consumer/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/edx/xblock-lti-consumer/git/refs{/sha}","trees_url":"https://api.github.com/repos/edx/xblock-lti-consumer/git/trees{/sha}","statuses_url":"https://api.github.com/repos/edx/xblock-lti-consumer/statuses/{sha}","languages_url":"https://api.github.com/repos/edx/xblock-lti-consumer/languages","stargazers_url":"https://api.github.com/repos/edx/xblock-lti-consumer/stargazers","contributors_url":"https://api.github.com/repos/edx/xblock-lti-consumer/contributors","subscribers_url":"https://api.github.com/repos/edx/xblock-lti-consumer/subscribers","subscription_url":"https://api.github.com/repos/edx/xblock-lti-consumer/subscription","commits_url":"https://api.github.com/repos/edx/xblock-lti-consumer/commits{/sha}","git_commits_url":"https://api.github.com/repos/edx/xblock-lti-consumer/git/commits{/sha}","comments_url":"https://api.github.com/repos/edx/xblock-lti-consumer/comments{/number}","issue_comment_url":"https://api.github.com/repos/edx/xblock-lti-consumer/issues/comments{/number}","contents_url":"https://api.github.com/repos/edx/xblock-lti-consumer/contents/{+path}","compare_url":"https://api.github.com/repos/edx/xblock-lti-consumer/compare/{base}...{head}","merges_url":"https://api.github.com/repos/edx/xblock-lti-consumer/merges","archive_url":"https://api.github.com/repos/edx/xblock-lti-consumer/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/edx/xblock-lti-consumer/downloads","issues_url":"https://api.github.com/repos/edx/xblock-lti-consumer/issues{/number}","pulls_url":"https://api.github.com/repos/edx/xblock-lti-consumer/pulls{/number}","milestones_url":"https://api.github.com/repos/edx/xblock-lti-consumer/milestones{/number}","notifications_url":"https://api.github.com/repos/edx/xblock-lti-consumer/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/edx/xblock-lti-consumer/labels{/name}","releases_url":"https://api.github.com/repos/edx/xblock-lti-consumer/releases{/id}","created_at":"2015-11-09T15:21:44Z","updated_at":"2015-11-09T15:21:44Z","pushed_at":"2015-11-16T20:44:19Z","git_url":"git://github.com/edx/xblock-lti-consumer.git","ssh_url":"git@github.com:edx/xblock-lti-consumer.git","clone_url":"https://github.com/edx/xblock-lti-consumer.git","svn_url":"https://github.com/edx/xblock-lti-consumer","homepage":null,"size":84,"stargazers_count":0,"watchers_count":0,"language":null,"has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":1,"forks":0,"open_issues":1,"watchers":0,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/edx/xblock-lti-consumer/pulls/1"},"html":{"href":"https://github.com/edx/xblock-lti-consumer/pull/1"},"issue":{"href":"https://api.github.com/repos/edx/xblock-lti-consumer/issues/1"},"comments":{"href":"https://api.github.com/repos/edx/xblock-lti-consumer/issues/1/comments"},"review_comments":{"href":"https://api.github.com/repos/edx/xblock-lti-consumer/pulls/1/comments"},"review_comment":{"href":"https://api.github.com/repos/edx/xblock-lti-consumer/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/edx/xblock-lti-consumer/pulls/1/commits"},"statuses":{"href":"https://api.github.com/repos/edx/xblock-lti-consumer/statuses/0af4bfdb4b26ef0c834b912d124768d35818a5ca"}}}}