def test_change_pin_clear_was_locked(self, slumber): buyer = self.setup_buyer(slumber) client.change_pin(self.uuid, '1234', clear_was_locked=True) buyer.patch.assert_called_with({'pin': '1234', 'pin_confirmed': False, 'pin_was_locked_out': False}, headers={'If-Match': ''})
def test_change_pin_without_existing_pin(self): uuid = "change_pin_without_existing_pin" new_pin = "1234" buyer = client.create_buyer(uuid) assert not buyer.get("pin") client.change_pin(uuid, new_pin) buyer = client.get_buyer(uuid) assert buyer.get("pin") assert client.verify_pin(uuid, new_pin)
def test_change_pin_with_existing_pin(self): uuid = "change_pin_with_existing_pin" pin = "5432" new_pin = pin[::-1] client.create_buyer(uuid, pin) client.change_pin(uuid, new_pin) buyer = client.get_buyer(uuid) assert buyer.get("pin") assert client.verify_pin(uuid, new_pin)
def test_change_pin_to_remove_exising_pin(self): uuid = "change_pin_to_remove_exising_pin" pin = "5467" new_pin = None buyer = client.create_buyer(uuid, pin) assert buyer.get("pin") client.change_pin(uuid, new_pin) buyer = client.get_buyer(uuid) assert not buyer.get("pin")
def test_change_pin_to_remove_exising_pin(self): uuid = 'change_pin_to_remove_exising_pin' pin = '5467' new_pin = None buyer = client.create_buyer(uuid, pin) assert buyer.get('pin') client.change_pin(uuid, new_pin) buyer = client.get_buyer(uuid) assert not buyer.get('pin')
def test_change_pin_with_existing_pin(self): uuid = 'change_pin_with_existing_pin' pin = '5432' new_pin = pin[::-1] client.create_buyer(uuid, pin) client.change_pin(uuid, new_pin) buyer = client.get_buyer(uuid) assert buyer.get('pin') assert client.verify_pin(uuid, new_pin)
def test_change_pin_with_wrong_etag(self, slumber): wrong_etag = 'etag:wrong' buyer = mock.Mock(return_value=self.buyer_data) buyer.patch.side_effect = HttpClientError( response=self.create_error_response( status_code=412, content={'ERROR': ['RESOURCE_MODIFIED']})) slumber.generic.buyer.return_value = buyer with self.assertRaises(ResourceModified): client.change_pin(self.uuid, self.pin, wrong_etag)
def test_change_pin_without_existing_pin(self): uuid = 'change_pin_without_existing_pin' new_pin = '1234' buyer = client.create_buyer(uuid) assert not buyer.get('pin') client.change_pin(uuid, new_pin) buyer = client.get_buyer(uuid) assert buyer.get('pin') assert client.verify_pin(uuid, new_pin)
def has_pin(request): pin = request.session.get('uuid_has_pin') confirmed = request.session.get('uuid_has_confirmed_pin') if pin: if confirmed: return True else: client.change_pin(request.session['uuid'], None) request.session['uuid_has_pin'] = False return False
def create(request): form = forms.CreatePinForm() if request.method == 'POST': form = forms.CreatePinForm(uuid=get_user(request), data=request.POST) if form.is_valid(): if getattr(form, 'buyer_exists', False): try: res = client.change_pin(form.uuid, form.cleaned_data['pin'], etag=form.buyer_etag) except ResourceModified: return system_error(request, code=msg.RESOURCE_MODIFIED) else: res = client.create_buyer(form.uuid, form.cleaned_data['pin']) if form.handle_client_errors(res): set_user_has_pin(request, True) return http.HttpResponseRedirect(reverse('pin.confirm')) form.no_pin = True return render( request, 'pin/pin_form.html', { 'form': form, 'title': _('Create a Pin'), 'action': reverse('pin.create'), 'pin_form_tracking': { 'pin_error_codes': form.pin_error_codes, }, 'track_cancel': { 'action': 'pin cancel', 'label': 'Create Pin Page', } })
def create(request): form = forms.CreatePinForm() if request.method == 'POST': form = forms.CreatePinForm(uuid=get_user(request), data=request.POST) if form.is_valid(): if getattr(form, 'buyer_exists', False): try: res = client.change_pin(form.uuid, form.cleaned_data['pin'], etag=form.buyer_etag) except ResourceModified: return system_error(request, code=msg.RESOURCE_MODIFIED) else: res = client.create_buyer(form.uuid, form.cleaned_data['pin']) if form.handle_client_errors(res): set_user_has_pin(request, True) return http.HttpResponseRedirect(reverse('pin.confirm')) form.no_pin = True return render(request, 'pin/pin_form.html', {'form': form, 'title': _('Create a Pin'), 'action': reverse('pin.create'), 'pin_form_tracking' : { 'pin_error_codes': form.pin_error_codes, }, 'track_cancel': { 'action': 'pin cancel', 'label': 'Create Pin Page', }})
def test_change_pin_with_existing_pin(self, slumber): buyer = mock.Mock(return_value=self.buyer_data) buyer.patch.return_value = {} slumber.generic.buyer.return_value = buyer assert 'errors' not in client.change_pin(self.uuid, self.pin) buyer.patch.assert_called_with({'pin': '1234', 'pin_confirmed': False}, headers={'If-Match': ''})
def check_pin_status(request): if request.session.get('uuid_pin_is_locked'): return reverse('pin.is_locked') if request.session.get('uuid_pin_was_locked'): return reverse('pin.was_locked') last_success = request.session.get('last_pin_success') if (last_success and ((datetime.now() - last_success).seconds < settings.PIN_UNLOCK_LENGTH)): return get_payment_url(request) if request.session.get('uuid_has_pin'): if request.session.get('uuid_has_confirmed_pin'): return None else: client.change_pin(request.session['uuid'], None) request.session['uuid_has_pin'] = False return reverse('pin.create')
def check_pin_status(request): if request.session.get('uuid_pin_is_locked'): return reverse('pin.is_locked') if request.session.get('uuid_pin_was_locked'): return reverse('pin.was_locked') last_success = request.session.get('last_pin_success') if (last_success and ( (datetime.now() - last_success).seconds < settings.PIN_UNLOCK_LENGTH)): return get_payment_url() if request.session.get('uuid_has_pin'): if request.session.get('uuid_has_confirmed_pin'): return None else: client.change_pin(request.session['uuid'], None) request.session['uuid_has_pin'] = False return reverse('pin.create')
def test_change_pin_with_wrong_etag(self, slumber): wrong_etag = 'etag:wrong' buyer = mock.Mock(return_value=self.buyer_data) buyer.patch.side_effect = HttpClientError( response=self.create_error_response( status_code=412, content={'ERROR': [('The resource has been modified, ' 'please re-fetch it.')]})) slumber.generic.buyer.return_value = buyer res = client.change_pin(self.uuid, self.pin, wrong_etag) assert 'errors' in res eq_(res['errors'], [ERROR_STRINGS['The resource has been modified, please re-fetch it.']])
def check_pin_status(request): if request.session.get('uuid_pin_is_locked'): return reverse('pin.is_locked') if request.session.get('uuid_pin_was_locked'): return reverse('pin.was_locked') last_success = request.session.get('last_pin_success') if (last_success and ( (datetime.now() - last_success).seconds < settings.PIN_UNLOCK_LENGTH)): return get_wait_url(request) if request.session.get('uuid_has_pin'): if request.session.get('uuid_has_confirmed_pin'): return None else: try: client.change_pin(request.session['uuid'], None) except ResourceModified: return system_error(request, code=msg.RESOURCE_MODIFIED) request.session['uuid_has_pin'] = False return reverse('pin.create')
def update(self, request): form = ResetPinForm(uuid=request.session['uuid'], data=request.DATA, user_reset=request.session.get('user_reset', {})) if form.is_valid(): del request.session['user_reset'] res = client.change_pin(form.uuid, form.cleaned_data['pin'], pin_confirmed=True, clear_was_locked=True) if form.client_response_is_valid(res): return response.Response(status=204) return api_error(form, request)
def check_pin_status(request): if request.session.get('uuid_pin_is_locked'): return reverse('pin.is_locked') if request.session.get('uuid_pin_was_locked'): return reverse('pin.was_locked') last_success = request.session.get('last_pin_success') if (last_success and ((datetime.now() - last_success).seconds < settings.PIN_UNLOCK_LENGTH)): return get_wait_url(request) if request.session.get('uuid_has_pin'): if request.session.get('uuid_has_confirmed_pin'): return None else: try: client.change_pin(request.session['uuid'], None) except ResourceModified: return system_error(request, code=msg.RESOURCE_MODIFIED) request.session['uuid_has_pin'] = False return reverse('pin.create')
def create(request): form = forms.CreatePinForm() if request.method == "POST": form = forms.CreatePinForm(uuid=get_user(request), data=request.POST) if form.is_valid(): if hasattr(form, "buyer"): res = client.change_pin(form.buyer, form.cleaned_data["pin"]) else: res = client.create_buyer(form.uuid, form.cleaned_data["pin"]) if form.handle_client_errors(res): set_user_has_pin(request, True) return http.HttpResponseRedirect(reverse("pin.confirm")) return render(request, "pin/create.html", {"form": form})
def create(self, request): form = CreatePinForm(uuid=request.session['uuid'], data=request.DATA) if form.is_valid(): res = client.change_pin(form.uuid, form.cleaned_data['pin'], etag=form.buyer_etag, pin_confirmed=True, clear_was_locked=True) if form.client_response_is_valid(res): set_user_has_pin(request, True) return response.Response(status=204) return api_error(form, request)
def change(request): form = forms.ChangePinForm() if request.method == 'POST': # TODO(Wraithan): Get the buyer's UUID once identity is figured out # with webpay. stub_uuid = 'dat:uuid' form = forms.ChangePinForm(uuid=stub_uuid, data=request.POST) if form.is_valid(): res = client.change_pin(form.buyer, form.cleaned_data['pin']) if form.handle_client_errors(res): # TODO(Wraithan): Replace with proper redirect return render(request, 'pin/change_success.html', {'form': form}) return render(request, 'pin/change.html', {'form': form})
def create(request): form = forms.CreatePinForm() if request.method == 'POST': form = forms.CreatePinForm(uuid=get_user(request), data=request.POST) if form.is_valid(): if hasattr(form, 'buyer'): res = client.change_pin(form.buyer, form.cleaned_data['pin']) else: res = client.create_buyer(form.uuid, form.cleaned_data['pin']) if form.handle_client_errors(res): set_user_has_pin(request, True) return http.HttpResponseRedirect(reverse('pin.confirm')) return render(request, 'pin/pin_form.html', {'form': form, 'title': _('Create your PIN:'), 'action': reverse('pin.create') })
def create(self, request): form = CreatePinForm(uuid=request.session["uuid"], data=request.DATA) if form.is_valid(): if getattr(form, "buyer_exists", None): res = client.change_pin(form.uuid, form.cleaned_data["pin"], etag=form.buyer_etag) else: res = client.create_buyer(form.uuid, form.cleaned_data["pin"]) if form.handle_client_errors(res): set_user_has_pin(request, True) return response.Response(status=201) return response.Response(status=201) return app_error(request)
def create(request): form = forms.CreatePinForm() if request.method == 'POST': form = forms.CreatePinForm(uuid=get_user(request), data=request.POST) if form.is_valid(): if getattr(form, 'buyer_exists', False): res = client.change_pin(form.uuid, form.cleaned_data['pin']) else: res = client.create_buyer(form.uuid, form.cleaned_data['pin']) if form.handle_client_errors(res): set_user_has_pin(request, True) return http.HttpResponseRedirect(reverse('pin.confirm')) form.no_pin = True return render(request, 'pin/pin_form.html', {'form': form, 'title': _('Create a Pin'), 'action': reverse('pin.create')})
def update(self, request): form = ResetPinForm(uuid=request.session['uuid'], data=request.DATA) if not request.session.get('was_reverified', False): return app_error(request) if form.is_valid(): res = client.change_pin(form.uuid, form.cleaned_data['pin'], pin_confirmed=True, clear_was_locked=True) if form.handle_client_errors(res): request.session['was_reverified'] = False return response.Response(status=204) return app_error(request)
def create(self, request): form = CreatePinForm(uuid=request.session['uuid'], data=request.DATA) if form.is_valid(): if getattr(form, 'buyer_exists', None): res = client.change_pin(form.uuid, form.cleaned_data['pin'], etag=form.buyer_etag) else: res = client.create_buyer(form.uuid, form.cleaned_data['pin']) if form.handle_client_errors(res): set_user_has_pin(request, True) return response.Response(status=201) return response.Response(status=201) return app_error(request)
def create(self, request): form = CreatePinForm(uuid=request.session['uuid'], data=request.DATA) if form.is_valid(): if getattr(form, 'buyer_exists', None): res = client.change_pin(form.uuid, form.cleaned_data['pin'], etag=form.buyer_etag, pin_confirmed=True, clear_was_locked=True) else: res = client.create_buyer(form.uuid, pin=form.cleaned_data['pin'], pin_confirmed=True, email=request.session[ 'logged_in_user']) if form.handle_client_errors(res): set_user_has_pin(request, True) return response.Response(status=204) return app_error(request)
def test_change_pin_and_not_confirmed(self, slumber): buyer = self.setup_buyer(slumber) client.change_pin(self.uuid, '1234', pin_confirmed=False) buyer.patch.assert_called_with({'pin': '1234', 'pin_confirmed': False}, headers={'If-Match': ''})
def test_change_pin_with_etag(self, slumber): etag = 'etag:good' buyer = mock.Mock(return_value=self.buyer_data) buyer.patch.return_value = {} slumber.generic.buyer.return_value = buyer assert 'errors' not in client.change_pin(self.uuid, self.pin, etag)
def test_change_pin_to_remove_existing_pin(self, slumber): new_pin = None buyer = mock.Mock(return_value=self.buyer_data) buyer.patch.return_value = {} slumber.generic.buyer.return_value = buyer assert 'errors' not in client.change_pin(self.uuid, new_pin)
def test_change_pin(self): buyer_id = client.get_buyer(self.uuid)['id'] eq_(client.change_pin(buyer_id, '4321'), {}) assert client.verify_pin(self.uuid, '4321') eq_(client.change_pin(buyer_id, self.pin), {})