Commit 945abe72 by Will Daly

Respond to code review feedback

parent 47b81c92
...@@ -7,7 +7,6 @@ import json ...@@ -7,7 +7,6 @@ import json
import urllib import urllib
from datetime import timedelta, datetime from datetime import timedelta, datetime
from uuid import uuid4 from uuid import uuid4
import contextlib
import ddt import ddt
import httpretty import httpretty
...@@ -1345,24 +1344,26 @@ class TestSubmitPhotosForVerification(TestCase): ...@@ -1345,24 +1344,26 @@ class TestSubmitPhotosForVerification(TestCase):
"S3_BUCKET": "test.example.com", "S3_BUCKET": "test.example.com",
} }
}) })
@httpretty.activate
@moto.mock_s3 @moto.mock_s3
def test_submit_photos_for_reverification(self): def test_submit_photos_for_reverification(self):
# Create the S3 bucket for photo upload # Create the S3 bucket for photo upload
conn = boto.connect_s3() conn = boto.connect_s3()
conn.create_bucket("test.example.com") conn.create_bucket("test.example.com")
# Mock the POST to Software Secure
httpretty.register_uri(httpretty.POST, "https://verify.example.com/submit/")
# Submit an initial verification attempt # Submit an initial verification attempt
with self._intercept_post() as mock_post: self._submit_photos(
self._submit_photos( face_image=self.IMAGE_DATA + "4567",
face_image=self.IMAGE_DATA + "4567", photo_id_image=self.IMAGE_DATA + "8910",
photo_id_image=self.IMAGE_DATA + "8910", )
) initial_data = self._get_post_data()
initial_data = self._get_post_data(mock_post)
# Submit a face photo for re-verification # Submit a face photo for re-verification
with self._intercept_post() as mock_post: self._submit_photos(face_image=self.IMAGE_DATA + "1112")
self._submit_photos(face_image=self.IMAGE_DATA + "1112") reverification_data = self._get_post_data()
reverification_data = self._get_post_data(mock_post)
# Verify that the initial attempt sent the same ID photo as the reverification attempt # Verify that the initial attempt sent the same ID photo as the reverification attempt
self.assertEqual(initial_data["PhotoIDKey"], reverification_data["PhotoIDKey"]) self.assertEqual(initial_data["PhotoIDKey"], reverification_data["PhotoIDKey"])
...@@ -1484,35 +1485,10 @@ class TestSubmitPhotosForVerification(TestCase): ...@@ -1484,35 +1485,10 @@ class TestSubmitPhotosForVerification(TestCase):
account_settings = get_account_settings(self.user) account_settings = get_account_settings(self.user)
self.assertEqual(account_settings['name'], full_name) self.assertEqual(account_settings['name'], full_name)
@contextlib.contextmanager def _get_post_data(self):
def _intercept_post(self): """Retrieve POST data from the last request. """
""" last_request = httpretty.last_request()
Mock `requests.post()` to always return a 200 status code. return json.loads(last_request.body)
Yields:
mock.Mock
"""
with patch("verify_student.models.requests.post") as mock_post:
mock_post.return_value = mock.Mock(
status_code=200,
text="Fake response",
)
yield mock_post
def _get_post_data(self, mock_post):
"""
Retrieve data sent with a mock POST request.
Arguments:
mock_post (mock.Mock): The mock for `requests.post()`.
Returns:
dict
"""
__, kwargs = mock_post.call_args
return json.loads(kwargs["data"])
class TestPhotoVerificationResultsCallback(ModuleStoreTestCase): class TestPhotoVerificationResultsCallback(ModuleStoreTestCase):
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment