def test_supports_latin1(self): schema = Schema((st.String("morning"),)) with self.app.test_request_context( data=u'{"morning": "mañana"}'.encode("latin-1"), content_type="application/json; charset=ISO-8859-1" ): data = parse_request_data(schema) self.assertEquals({"morning": u"mañana"}, data)
def test_supports_latin1(self): schema = Schema((st.String('morning'), )) with self.app.test_request_context( data=u'{"morning": "mañana"}'.encode('latin-1'), content_type='application/json; charset=ISO-8859-1'): data = parse_request_data(schema) self.assertEquals({'morning': u'mañana'}, data)
def test_utf8_explicit(self): schema = Schema((st.String("morning"),)) with self.app.test_request_context( data=u'{"morning": "утро"}'.encode("utf-8"), content_type="application/json; charset=UTF-8" ): data = parse_request_data(schema) self.assertEquals({"morning": u"утро"}, data)
def test_utf8_explicit(self): schema = Schema((st.String('morning'), )) with self.app.test_request_context( data=u'{"morning": "утро"}'.encode('utf-8'), content_type='application/json; charset=UTF-8'): data = parse_request_data(schema) self.assertEquals({'morning': u'утро'}, data)
def apply_password_reset(code): if not g.config('password-reset', 'enabled'): abort(404) data = parse_request_data(required=_APPLY_SCHEMA) token = ResetTokensDAO.get(code) if not token or token.complete: abort(404) user = fetch_user(token.user_id, admin_mode=True) update_user_data(user, data) ResetTokensDAO.complete_for_user(token.user_id) return make_json_response(None, status_code=204)
def reset_password(): if not g.config('password-reset', 'enabled'): abort(404) data = parse_request_data(allowed=_RESET_SCHEMA) user = _find_user(data) if user is None: return make_json_response(None, status_code=204) token = ResetTokensDAO.create(user.id, user.email) send_reset_password(user.email, token.code, user.name, link_template=data.get('link-template'), greeting=getattr(user, 'fullname', '')) return make_json_response(None, status_code=204)
def accept_invite(code): data = parse_request_data(_ACCEPT_SCHEMA, _ACCEPT_REQUIRES) invite, user = _invite_and_user(code) data['enabled'] = True try: update_user_data(user, data) user = auth.admin_client_set().identity_admin.users.get(user.id) except osc_exc.NotFound: abort(404) InvitesDAO.complete_for_user(user.id) return make_json_response(user_to_view(user, invite), 200)
def test_basics(self): params = {} with self.request_context(params): self.assertEquals(params, parse_request_data(None, None))
def test_date_is_parsed(self): timestamp = datetime(2012, 5, 11, 17, 42, 53) schema = Schema((st.Timestamp('test'), )) params = {'test': '2012-05-11T17:42:53Z'} with self.request_context(params): self.assertEquals({'test': timestamp}, parse_request_data(schema))
def test_allowed_ok(self): schema = Schema((st.Int('test'), )) params = {'test': 42} with self.request_context(params): self.assertEquals(params, parse_request_data(schema))
def test_allowed_missing(self): schema = Schema((st.Int('req'), )) params = {} with self.request_context({}): self.assertEquals(params, parse_request_data(schema))
def test_required_ok(self): schema = Schema((st.Int('req'), )) params = {'req': 42} with self.request_context(params): self.assertEquals(params, parse_request_data(None, schema))
def test_required_ok(self): schema = Schema((st.Int("req"),)) params = {"req": 42} with self.request_context(params): self.assertEquals(params, parse_request_data(None, schema))
def test_allowed_missing(self): schema = Schema((st.Int("req"),)) params = {} with self.request_context({}): self.assertEquals(params, parse_request_data(schema))
def test_allowed_ok(self): schema = Schema((st.Int("test"),)) params = {"test": 42} with self.request_context(params): self.assertEquals(params, parse_request_data(schema))
def test_date_is_parsed(self): timestamp = datetime(2012, 5, 11, 17, 42, 53) schema = Schema((st.Timestamp("test"),)) params = {"test": "2012-05-11T17:42:53Z"} with self.request_context(params): self.assertEquals({"test": timestamp}, parse_request_data(schema))