def on_post(self, req, resp): """Handles POST requests""" payload = json.loads(req.stream.read()) logger.debug('Recieved {} '.format(payload)) try: r = Recipient(payload) r.validate() key = rs.add(r) logger.debug('Added recipient at {}'.format(key)) except InvalidUKMobileNumberException, e: logger.error(e) raise falcon.HTTPBadRequest( 'You need to supply a valid UK mobile number.', 'See docs for more details.')
def test_not_correct_type(test_recipient): with pytest.raises(InvalidUKMobileNumberException): bad_recipient = Recipient(dict(number=44123456)) bad_recipient.validate()
def test_invalid_uk_number(test_recipient): with pytest.raises(InvalidUKMobileNumberException): bad_recipient = Recipient(dict(number='123456')) bad_recipient.validate()