GitHub PullRequestReviewCommentEvent at 2014-12-19 12:11:06
Repository: empirical
Actor: alibotean
Payload: {"action":"created","comment":{"url":"https://api.github.com/repos/chevah/empirical/pulls/comments/22101585","id":22101585,"diff_hunk":"@@ -187,78 +196,93 @@ def do_QUIT(self):\n         self.server.stop = True\n \n     def do_GET(self):\n-        response = self._getResponse()\n+        self._handleRequest()\n+\n+    def do_POST(self):\n+        self._handleRequest()\n+\n+    def _handleRequest(self):\n+        \"\"\"\n+        Check if we can handle the request and send response.\n+        \"\"\"\n+        response = self._matchResponse()\n         if response:\n-            self.send_response(response.response_code)\n-            self.send_header(\"Content-type\", response.content_type)\n-            self.end_headers()\n-            self.wfile.write(response.test_response_content)\n-        else:\n-            self.send_error(404)\n+            self._sendReponse(response)\n+            return\n+\n+        self.send_error(404)\n \n-    def _getResponse(self):\n-        '''Return the MockHTTPResponse for the current request.'''\n+    def _matchResponse(self):\n+        \"\"\"\n+        Return the ResponseDefinition for the current request.\n+        \"\"\"\n         for response in self.__class__.valid_responses:\n-            if self.path == response.url:\n-                return response\n-        # If no response was found, return None.\n-        return None\n+            if self.path != response.url or self.command != response.method:\n+                self._debug()\n+                continue\n+\n+            # For POST request we read content.\n+            if self.command == 'POST':\n+                length = int(self.headers.getheader('content-length'))\n+                content = self.rfile.read(length)\n+                if content != response.request:\n+                    self._debug(content)\n+                    continue\n \n-    def do_POST(self):\n-        if self._haveValidURL():\n-            length = int(self.headers.getheader('content-length'))\n-            request = self.rfile.read(length)\n-            response = self._postResponse(request)\n-            if response:\n-                self.send_response(response.response_code)\n-                self.send_header(\"Content-type\", response.content_type)\n-                self.end_headers()\n-                self.wfile.write(response.test_response_content)\n-            else:\n-                if self.debug:\n-                    print '\\nserver got data - %s\\nserver exp data - %s\\n' % (\n-                        request, unicode(self._getAcceptedRequests()))\n-                self.send_error(400)\n-        else:\n-            if self.debug:\n-                print '\\nserver got url - %s\\nserver exp url - %s\\n' % (\n-                    self.path, unicode(self._getAcceptedURLs()))\n-            self.send_error(404)\n+            # We have a match.\n+            return response\n \n-    def _postResponse(self, request):\n-        '''Return a tuple containing the'''\n-        for response in self.__class__.valid_responses:\n-            if response.url == self.path and response.request == request:\n-                return response\n         return None\n \n-    def _getAcceptedURLs(self):\n-        '''Return the list of URLs accepted by the server.'''\n-        result = []\n-        for response in self.__class__.valid_responses:\n-            result.append(response.url)\n-        return result\n-\n-    def _getAcceptedRequests(self):\n-        '''Return the list of request contents accepted by this server.'''\n-        result = []\n-        for response in self.__class__.valid_responses:\n-            if response.url == self.path:\n-                result.append(response.request)\n-        return result\n+    def _debug(self, message=''):\n+        \"\"\"\n+        Print to stdout a debug message.\n+        \"\"\"\n+        if not self.debug:\n+            return\n+        print '\\nGot %s:%s - %s\\n' % (\n+            self.command, self.path, message)\n \n-    def _haveValidURL(self):\n-        '''Return True if the current request is in the list of URLs\n-        accepted by the server.'''\n-        for response in self.__class__.valid_responses:\n-            if self.path == response.url:\n-                return True\n-        return False\n+    def _sendReponse(self, response):\n+        \"\"\"\n+        Send response to client.\n+        \"\"\"\n+        connection_header = self.headers.getheader('connection')\n+        if connection_header:\n+            connection_header = connection_header.lower()\n+\n+        if self.server_version == 'HTTP/1.1':\n+            # For HTTP/1.1 connections are persistent by default.\n+            if not connection_header:\n+                connection_header = 'keep-alive'\n+        else:\n+            # For HTTP/1.0 connections are not persistent by default.\n+            if not connection_header:\n+                connection_header = 'close'\n+\n+        if response.persistent is None:\n+            # Ignore persistent flag.\n+            pass\n+        elif response.persistent:\n+            if connection_header == 'close':\n+                self.send_error(400, 'Connection it not persistent')","path":"chevah/empirical/mockup.py","position":254,"original_position":254,"commit_id":"fff10e622969831ef031ff1aa0f3931372b785ed","original_commit_id":"fff10e622969831ef031ff1aa0f3931372b785ed","user":{"login":"alibotean","id":465539,"avatar_url":"https://avatars.githubusercontent.com/u/465539?v=3","gravatar_id":"","url":"https://api.github.com/users/alibotean","html_url":"https://github.com/alibotean","followers_url":"https://api.github.com/users/alibotean/followers","following_url":"https://api.github.com/users/alibotean/following{/other_user}","gists_url":"https://api.github.com/users/alibotean/gists{/gist_id}","starred_url":"https://api.github.com/users/alibotean/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/alibotean/subscriptions","organizations_url":"https://api.github.com/users/alibotean/orgs","repos_url":"https://api.github.com/users/alibotean/repos","events_url":"https://api.github.com/users/alibotean/events{/privacy}","received_events_url":"https://api.github.com/users/alibotean/received_events","type":"User","site_admin":false},"body":"it -> is","created_at":"2014-12-19T12:11:06Z","updated_at":"2014-12-19T12:11:06Z","html_url":"https://github.com/chevah/empirical/pull/43#discussion_r22101585","pull_request_url":"https://api.github.com/repos/chevah/empirical/pulls/43","_links":{"self":{"href":"https://api.github.com/repos/chevah/empirical/pulls/comments/22101585"},"html":{"href":"https://github.com/chevah/empirical/pull/43#discussion_r22101585"},"pull_request":{"href":"https://api.github.com/repos/chevah/empirical/pulls/43"}}},"pull_request":{"url":"https://api.github.com/repos/chevah/empirical/pulls/43","id":26322369,"html_url":"https://github.com/chevah/empirical/pull/43","diff_url":"https://github.com/chevah/empirical/pull/43.diff","patch_url":"https://github.com/chevah/empirical/pull/43.patch","issue_url":"https://api.github.com/repos/chevah/empirical/issues/43","number":43,"state":"open","locked":false,"title":"[#2590] Update http mock to match on method and persistence and allow custom response message.","user":{"login":"adiroiban","id":204609,"avatar_url":"https://avatars.githubusercontent.com/u/204609?v=3","gravatar_id":"","url":"https://api.github.com/users/adiroiban","html_url":"https://github.com/adiroiban","followers_url":"https://api.github.com/users/adiroiban/followers","following_url":"https://api.github.com/users/adiroiban/following{/other_user}","gists_url":"https://api.github.com/users/adiroiban/gists{/gist_id}","starred_url":"https://api.github.com/users/adiroiban/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/adiroiban/subscriptions","organizations_url":"https://api.github.com/users/adiroiban/orgs","repos_url":"https://api.github.com/users/adiroiban/repos","events_url":"https://api.github.com/users/adiroiban/events{/privacy}","received_events_url":"https://api.github.com/users/adiroiban/received_events","type":"User","site_admin":false},"body":"Problem\r\n=======\r\n\r\nWe need to extend the HTTPMockServer and its handler to help with testing or our server.\r\n\r\nChanges\r\n=======\r\nHTTPMockServer was created as a quick and dirty hack to test simple web requests.\r\nAt the start I did not believed that it is of much use and that it should be replaced with something better...\r\nit turned that that with a bit of helpers it can be useful ... so here I have extended it and added tests.\r\n\r\nThis is not really a mock, but a real server, as it listed on TCP and handles real requests.\r\nI have renamed the class names to better reflect what they are... the Mock name is too generic.\r\n\r\nThe current implementation is based on \"Backend Definitions\"  as the order in which requests are made is not\r\nenforces.\r\n\r\nFor Request Expectations vs Backend Definitions see https://docs.angularjs.org/api/ngMock/service/$httpBackend\r\n\r\nThis changes will break the API, but I will create a new branch on server to integrate the changes.\r\nThis changes also check persistence connection by default.\r\n\r\n\r\nHow to test\r\n=========\r\n\r\n\r\nreviewers: @alibotean \r\n\r\n\r\ncheck that changes make sense.\r\n\r\nThanks!","created_at":"2014-12-18T18:46:58Z","updated_at":"2014-12-19T12:11:06Z","closed_at":null,"merged_at":null,"merge_commit_sha":"35bb3798f3b7addfd99da1aacd2df95d375ef4bd","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/chevah/empirical/pulls/43/commits","review_comments_url":"https://api.github.com/repos/chevah/empirical/pulls/43/comments","review_comment_url":"https://api.github.com/repos/chevah/empirical/pulls/comments/{number}","comments_url":"https://api.github.com/repos/chevah/empirical/issues/43/comments","statuses_url":"https://api.github.com/repos/chevah/empirical/statuses/fff10e622969831ef031ff1aa0f3931372b785ed","head":{"label":"chevah:2590-mock-http-server","ref":"2590-mock-http-server","sha":"fff10e622969831ef031ff1aa0f3931372b785ed","user":{"login":"chevah","id":1153635,"avatar_url":"https://avatars.githubusercontent.com/u/1153635?v=3","gravatar_id":"","url":"https://api.github.com/users/chevah","html_url":"https://github.com/chevah","followers_url":"https://api.github.com/users/chevah/followers","following_url":"https://api.github.com/users/chevah/following{/other_user}","gists_url":"https://api.github.com/users/chevah/gists{/gist_id}","starred_url":"https://api.github.com/users/chevah/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/chevah/subscriptions","organizations_url":"https://api.github.com/users/chevah/orgs","repos_url":"https://api.github.com/users/chevah/repos","events_url":"https://api.github.com/users/chevah/events{/privacy}","received_events_url":"https://api.github.com/users/chevah/received_events","type":"Organization","site_admin":false},"repo":{"id":7752170,"name":"empirical","full_name":"chevah/empirical","owner":{"login":"chevah","id":1153635,"avatar_url":"https://avatars.githubusercontent.com/u/1153635?v=3","gravatar_id":"","url":"https://api.github.com/users/chevah","html_url":"https://github.com/chevah","followers_url":"https://api.github.com/users/chevah/followers","following_url":"https://api.github.com/users/chevah/following{/other_user}","gists_url":"https://api.github.com/users/chevah/gists{/gist_id}","starred_url":"https://api.github.com/users/chevah/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/chevah/subscriptions","organizations_url":"https://api.github.com/users/chevah/orgs","repos_url":"https://api.github.com/users/chevah/repos","events_url":"https://api.github.com/users/chevah/events{/privacy}","received_events_url":"https://api.github.com/users/chevah/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/chevah/empirical","description":"Testing helpers for Chevah project","fork":false,"url":"https://api.github.com/repos/chevah/empirical","forks_url":"https://api.github.com/repos/chevah/empirical/forks","keys_url":"https://api.github.com/repos/chevah/empirical/keys{/key_id}","collaborators_url":"https://api.github.com/repos/chevah/empirical/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/chevah/empirical/teams","hooks_url":"https://api.github.com/repos/chevah/empirical/hooks","issue_events_url":"https://api.github.com/repos/chevah/empirical/issues/events{/number}","events_url":"https://api.github.com/repos/chevah/empirical/events","assignees_url":"https://api.github.com/repos/chevah/empirical/assignees{/user}","branches_url":"https://api.github.com/repos/chevah/empirical/branches{/branch}","tags_url":"https://api.github.com/repos/chevah/empirical/tags","blobs_url":"https://api.github.com/repos/chevah/empirical/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/chevah/empirical/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/chevah/empirical/git/refs{/sha}","trees_url":"https://api.github.com/repos/chevah/empirical/git/trees{/sha}","statuses_url":"https://api.github.com/repos/chevah/empirical/statuses/{sha}","languages_url":"https://api.github.com/repos/chevah/empirical/languages","stargazers_url":"https://api.github.com/repos/chevah/empirical/stargazers","contributors_url":"https://api.github.com/repos/chevah/empirical/contributors","subscribers_url":"https://api.github.com/repos/chevah/empirical/subscribers","subscription_url":"https://api.github.com/repos/chevah/empirical/subscription","commits_url":"https://api.github.com/repos/chevah/empirical/commits{/sha}","git_commits_url":"https://api.github.com/repos/chevah/empirical/git/commits{/sha}","comments_url":"https://api.github.com/repos/chevah/empirical/comments{/number}","issue_comment_url":"https://api.github.com/repos/chevah/empirical/issues/comments/{number}","contents_url":"https://api.github.com/repos/chevah/empirical/contents/{+path}","compare_url":"https://api.github.com/repos/chevah/empirical/compare/{base}...{head}","merges_url":"https://api.github.com/repos/chevah/empirical/merges","archive_url":"https://api.github.com/repos/chevah/empirical/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/chevah/empirical/downloads","issues_url":"https://api.github.com/repos/chevah/empirical/issues{/number}","pulls_url":"https://api.github.com/repos/chevah/empirical/pulls{/number}","milestones_url":"https://api.github.com/repos/chevah/empirical/milestones{/number}","notifications_url":"https://api.github.com/repos/chevah/empirical/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/chevah/empirical/labels{/name}","releases_url":"https://api.github.com/repos/chevah/empirical/releases{/id}","created_at":"2013-01-22T12:42:40Z","updated_at":"2014-10-07T06:42:56Z","pushed_at":"2014-12-18T18:43:10Z","git_url":"git://github.com/chevah/empirical.git","ssh_url":"git@github.com:chevah/empirical.git","clone_url":"https://github.com/chevah/empirical.git","svn_url":"https://github.com/chevah/empirical","homepage":null,"size":1868,"stargazers_count":1,"watchers_count":1,"language":"Python","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":1,"forks":0,"open_issues":1,"watchers":1,"default_branch":"master"}},"base":{"label":"chevah:master","ref":"master","sha":"8540fcf22f5303ec835c4324948fdad987d1e381","user":{"login":"chevah","id":1153635,"avatar_url":"https://avatars.githubusercontent.com/u/1153635?v=3","gravatar_id":"","url":"https://api.github.com/users/chevah","html_url":"https://github.com/chevah","followers_url":"https://api.github.com/users/chevah/followers","following_url":"https://api.github.com/users/chevah/following{/other_user}","gists_url":"https://api.github.com/users/chevah/gists{/gist_id}","starred_url":"https://api.github.com/users/chevah/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/chevah/subscriptions","organizations_url":"https://api.github.com/users/chevah/orgs","repos_url":"https://api.github.com/users/chevah/repos","events_url":"https://api.github.com/users/chevah/events{/privacy}","received_events_url":"https://api.github.com/users/chevah/received_events","type":"Organization","site_admin":false},"repo":{"id":7752170,"name":"empirical","full_name":"chevah/empirical","owner":{"login":"chevah","id":1153635,"avatar_url":"https://avatars.githubusercontent.com/u/1153635?v=3","gravatar_id":"","url":"https://api.github.com/users/chevah","html_url":"https://github.com/chevah","followers_url":"https://api.github.com/users/chevah/followers","following_url":"https://api.github.com/users/chevah/following{/other_user}","gists_url":"https://api.github.com/users/chevah/gists{/gist_id}","starred_url":"https://api.github.com/users/chevah/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/chevah/subscriptions","organizations_url":"https://api.github.com/users/chevah/orgs","repos_url":"https://api.github.com/users/chevah/repos","events_url":"https://api.github.com/users/chevah/events{/privacy}","received_events_url":"https://api.github.com/users/chevah/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/chevah/empirical","description":"Testing helpers for Chevah project","fork":false,"url":"https://api.github.com/repos/chevah/empirical","forks_url":"https://api.github.com/repos/chevah/empirical/forks","keys_url":"https://api.github.com/repos/chevah/empirical/keys{/key_id}","collaborators_url":"https://api.github.com/repos/chevah/empirical/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/chevah/empirical/teams","hooks_url":"https://api.github.com/repos/chevah/empirical/hooks","issue_events_url":"https://api.github.com/repos/chevah/empirical/issues/events{/number}","events_url":"https://api.github.com/repos/chevah/empirical/events","assignees_url":"https://api.github.com/repos/chevah/empirical/assignees{/user}","branches_url":"https://api.github.com/repos/chevah/empirical/branches{/branch}","tags_url":"https://api.github.com/repos/chevah/empirical/tags","blobs_url":"https://api.github.com/repos/chevah/empirical/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/chevah/empirical/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/chevah/empirical/git/refs{/sha}","trees_url":"https://api.github.com/repos/chevah/empirical/git/trees{/sha}","statuses_url":"https://api.github.com/repos/chevah/empirical/statuses/{sha}","languages_url":"https://api.github.com/repos/chevah/empirical/languages","stargazers_url":"https://api.github.com/repos/chevah/empirical/stargazers","contributors_url":"https://api.github.com/repos/chevah/empirical/contributors","subscribers_url":"https://api.github.com/repos/chevah/empirical/subscribers","subscription_url":"https://api.github.com/repos/chevah/empirical/subscription","commits_url":"https://api.github.com/repos/chevah/empirical/commits{/sha}","git_commits_url":"https://api.github.com/repos/chevah/empirical/git/commits{/sha}","comments_url":"https://api.github.com/repos/chevah/empirical/comments{/number}","issue_comment_url":"https://api.github.com/repos/chevah/empirical/issues/comments/{number}","contents_url":"https://api.github.com/repos/chevah/empirical/contents/{+path}","compare_url":"https://api.github.com/repos/chevah/empirical/compare/{base}...{head}","merges_url":"https://api.github.com/repos/chevah/empirical/merges","archive_url":"https://api.github.com/repos/chevah/empirical/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/chevah/empirical/downloads","issues_url":"https://api.github.com/repos/chevah/empirical/issues{/number}","pulls_url":"https://api.github.com/repos/chevah/empirical/pulls{/number}","milestones_url":"https://api.github.com/repos/chevah/empirical/milestones{/number}","notifications_url":"https://api.github.com/repos/chevah/empirical/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/chevah/empirical/labels{/name}","releases_url":"https://api.github.com/repos/chevah/empirical/releases{/id}","created_at":"2013-01-22T12:42:40Z","updated_at":"2014-10-07T06:42:56Z","pushed_at":"2014-12-18T18:43:10Z","git_url":"git://github.com/chevah/empirical.git","ssh_url":"git@github.com:chevah/empirical.git","clone_url":"https://github.com/chevah/empirical.git","svn_url":"https://github.com/chevah/empirical","homepage":null,"size":1868,"stargazers_count":1,"watchers_count":1,"language":"Python","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":1,"forks":0,"open_issues":1,"watchers":1,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/chevah/empirical/pulls/43"},"html":{"href":"https://github.com/chevah/empirical/pull/43"},"issue":{"href":"https://api.github.com/repos/chevah/empirical/issues/43"},"comments":{"href":"https://api.github.com/repos/chevah/empirical/issues/43/comments"},"review_comments":{"href":"https://api.github.com/repos/chevah/empirical/pulls/43/comments"},"review_comment":{"href":"https://api.github.com/repos/chevah/empirical/pulls/comments/{number}"},"commits":{"href":"https://api.github.com/repos/chevah/empirical/pulls/43/commits"},"statuses":{"href":"https://api.github.com/repos/chevah/empirical/statuses/fff10e622969831ef031ff1aa0f3931372b785ed"}}}}