def __init__(self): rospy.init_node('state_machine') rospy.loginfo('state machine') self.rate = rospy.Rate(60) # set rate to 60 hz # publishers #rospy.init_node('automaton') self.sub = rospy.Subscriber('/tricks', Temperature, self.trickCallback) self.nod_trick = Nod() self.shake_trick = Shake() self.dab_trick = Shake()
def test_url_for(): def index(request): expected = '/hello/world/' url = url_for(endpoint, name='world') assert url == expected expected = 'http://localhost/hello/world/' url = url_for(endpoint, name='world', external=True) assert url == expected expected = '/hello/world/#awesome' url = url_for(endpoint, name='world', anchor='awesome') assert url == expected expected = 'http://localhost/hello/world/#awesome' url = url_for(endpoint, name='world', anchor='awesome', external=True) assert url == expected urls = [ Rule('/', index), Rule('/hello/<name>/', endpoint), ] app = Shake(urls) c = app.test_client() resp = c.get('/')
def test_send_file_attachment(): def index(request): filename = path_join(__file__, 'static/index.html') with io.open(filename) as f: resp = send_file(request, f, mimetype='text/html', as_attachment=True) cd_header = resp.headers['Content-Disposition'] value, options = parse_options_header(cd_header) assert value == 'attachment' resp = send_file(request, filename, as_attachment=True) cd_header = resp.headers['Content-Disposition'] value, options = parse_options_header(cd_header) assert value == 'attachment' assert options['filename'] == 'index.html' f = StringIO('Test') resp = send_file(request, f, attachment_filename='readme.txt', as_attachment=True) assert resp.mimetype == 'text/plain' cd_header = resp.headers['Content-Disposition'] value, options = parse_options_header(cd_header) assert value == 'attachment' assert options['filename'] == 'readme.txt' app = Shake() app.add_url('/', index) c = app.test_client() resp = c.get('/')
def test_fallback_error_code(): errors = { 400: BadRequest, 401: Unauthorized, 403: Forbidden, 404: NotFound, 405: MethodNotAllowed, 406: NotAcceptable, 408: RequestTimeout, 410: Gone, 411: LengthRequired, 412: PreconditionFailed, 413: RequestEntityTooLarge, 414: RequestURITooLarge, 415: UnsupportedMediaType, 500: InternalServerError, 501: NotImplemented, 502: BadGateway, 503: ServiceUnavailable, } settings = {'PAGE_ERROR': error, 'DEBUG': False} app = Shake(__file__, settings) @app.route('/<int:code>/') def index(request, code): print code raise errors[code] c = app.test_client() for code in errors: if code in app.error_handlers: continue resp = c.get('/%i/' % code) assert resp.status_code == code assert resp.data == 'error'
def test_default_error(): app = Shake(__file__) app.add_url('/', fail) c = app.test_client() with pytest.raises(AssertionError): c.get('/')
def test_flash_messagesech(): def t1(request): msgs = get_messages() assert msgs == [] def t2(request): flash(request, 'foo') flash(request, 'bar', 'error', extra='blub') msgs = get_messages() assert len(msgs) == 2 assert (msgs[0]['msg'], msgs[0]['cat'], msgs[0]['extra']) == \ ('foo', 'info', None) assert (msgs[1]['msg'], msgs[1]['cat'], msgs[1]['extra']) == \ ('bar', 'error', 'blub') msgs2 = get_messages() assert msgs2 == msgs urls = [ Rule('/t1', t1), Rule('/t2', t2), ] settings = {'SECRET_KEY': 'abc' * 20} app = Shake(urls, settings) c = app.test_client() c.get('/t1') c.get('/t2')
def test_i18n(): render = Render(i18n=views_dir) def ok(request): return render.from_string('{{ i18n.HELLO }}') def fail(request): return render.from_string('{{ i18n.FOOBAR }}') urls = [ Rule('/ok/', ok), Rule('/fail/', fail), ] app = Shake(urls) c = app.test_client() resp = c.get('/ok/?lang=en-US') assert resp.status_code == HTTP_OK assert resp.data == 'Hello World' resp = c.get('/ok/?lang=en_US') assert resp.status_code == HTTP_OK assert resp.data == 'Hello World' resp = c.get('/ok/?lang=es-AR') assert resp.data == 'Hola mundo' resp = c.get('/fail/?lang=en-US') assert resp.data == ''
def test_processors_order(): app = Shake(__file__) r = [] @app.route('/') def index(request): r.append('view') @app.before_request def br1(request): r.append('br1') @app.before_request def br2(request): r.append('br2') @app.after_request def ar1(response): r.append('ar1') return response @app.after_request def ar2(response): r.append('ar2') return response @app.on_exception def error(e): r.append('error') c = app.test_client() c.get('/') assert r == 'br1 br2 view ar1 ar2'.split()
def test_repeated_processors(): r = [] def index(request): r.append('controller') def rq1(request): r.append('rq1') def rs1(response): r.append('rs1') return response def on_error(e): r.append('error') urls = [ Rule('/', index), ] app = Shake(urls) app.before_request(rq1) app.before_request(rq1) app.before_response(rs1) app.before_response(rs1) app.on_exception(on_error) app.before_request(rq1) app.before_response(rs1) app.before_request(rq1) app.on_exception(on_error) c = app.test_client() c.get('/') assert r == ['rq1', 'controller', 'rs1']
def test_default_not_found(): app = Shake(__file__) app.add_url('/', index) c = app.test_client() resp = c.get('/bla') assert resp.status_code == HTTP_NOT_FOUND assert '<title>Page not found</title>' in resp.data
def test_string_endpoint(): app = Shake(__file__) app.add_url('/', 'tests.test_app.index') c = app.test_client() resp = c.get('/') assert resp.status_code == HTTP_OK assert resp.data == 'hello'
def test_callable_endpoint(): app = Shake(__file__) app.add_url('/', index) c = app.test_client() resp = c.get('/') assert resp.status_code == HTTP_OK assert resp.data == 'hello'
def test_default_not_allowed(): app = Shake(__file__) app.add_url('/', no_pass) c = app.test_client() resp = c.get('/') assert resp.status_code == HTTP_FORBIDDEN assert '<title>Access Denied</title>' in resp.data
def test_custom_not_allowed(): settings = {'PAGE_NOT_ALLOWED': not_allowed} app = Shake(__file__, settings) app.add_url('/', no_pass) c = app.test_client() resp = c.get('/') assert resp.status_code == HTTP_FORBIDDEN assert resp.data == 'access denied'
def test_custom_error(): settings = {'PAGE_ERROR': error, 'DEBUG': False} app = Shake(__file__, settings) app.add_url('/', fail) c = app.test_client() resp = c.get('/') assert resp.status_code == HTTP_ERROR assert resp.data == 'error'
def test_custom_not_found(): settings = {'PAGE_NOT_FOUND': not_found, 'DEBUG': True} app = Shake(__file__, settings) app.add_url('/', index) c = app.test_client() resp = c.get('/bla') assert resp.status_code == HTTP_NOT_FOUND assert resp.data == 'not found'
def test_default_error(): urls = [ Rule('/', fail), ] app = Shake(urls) c = app.test_client() with pytest.raises(AssertionError): c.get('/')
def test_session_nosecret(): app = Shake(__file__) @app.route('/') def p1(request): request.session['foo'] = 'bar' c = app.test_client() with pytest.raises(RuntimeError): print c.get('/')
def test_string_endpoint(): urls = [ Rule('/', 'tests.test_app.index'), ] app = Shake(urls) c = app.test_client() resp = c.get('/') assert resp.status_code == HTTP_OK assert resp.data == 'hello'
def test_default_not_found(): urls = [ Rule('/', index), ] app = Shake(urls) c = app.test_client() resp = c.get('/bla') assert resp.status_code == HTTP_NOT_FOUND assert '<title>Page not found</title>' in resp.data
def test_redirect(): app = Shake(__file__) @app.route('/') def redir(request): return redirect('/bla') c = app.test_client() resp = c.get('/') assert resp.status_code == HTTP_FOUND
def test_callable_endpoint(): urls = [ Rule('/', index), ] app = Shake(urls) c = app.test_client() resp = c.get('/') assert resp.status_code == HTTP_OK assert resp.data == 'hello'
def test_default_not_allowed(): urls = [ Rule('/', no_pass), ] app = Shake(urls) c = app.test_client() resp = c.get('/') assert resp.status_code == HTTP_FORBIDDEN assert '<title>Access Denied</title>' in resp.data
def test_csrf_token(): settings = {'SECRET_KEY': 'abc'*20} app = Shake(__file__, settings) environ = get_test_env() request = app.make_request(environ) csrf1 = get_csrf(request).value csrf2 = new_csrf(request).value csrf2_ = get_csrf(request).value assert csrf2 != csrf1 assert csrf2_ == csrf2
def test_csrf_token_query(): settings = {'SECRET_KEY': 'abc'*20} app = Shake(__file__, settings) environ = get_test_env() app.make_request(environ) csrf = get_csrf() tmpl = '{{ csrf.query }}' resp = app.render.from_string(tmpl, to_string=True) expected = '%s=%s' % (csrf.name, csrf.value) assert resp == expected
def test_default_response(): app = Shake(__file__) @app.route('/') def index(request): pass c = app.test_client() resp = c.get('/') assert resp.status_code == HTTP_OK assert resp.data == ''
def test_default_not_allowed(): settings = { 'PAGE_NOT_ALLOWED': not_allowed_page, } app = Shake(__file__, settings) app.add_url('/', no_pass) c = app.test_client() resp = c.get('/') assert resp.status_code == HTTP_FORBIDDEN assert '<title>Access Denied</title>' in resp.data
def test_custom_error(): urls = [ Rule('/', fail), ] settings = {'PAGE_ERROR': error, 'DEBUG': False} app = Shake(urls, settings) c = app.test_client() resp = c.get('/') assert resp.status_code == HTTP_ERROR assert resp.data == 'error'
def test_custom_not_found(): urls = [ Rule('/', index), ] settings = {'PAGE_NOT_FOUND': not_found} app = Shake(urls, settings) c = app.test_client() resp = c.get('/bla') assert resp.status_code == HTTP_NOT_FOUND assert resp.data == 'not found'
def test_csrf_token_input(): settings = {'SECRET_KEY': 'abc'*20} app = Shake(__file__, settings) environ = get_test_env() request = app.make_request(environ) csrf = get_csrf(request) tmpl = '{{ csrf.input }}' resp = app.render.from_string(tmpl, to_string=True) expected = '<input type="hidden" name="%s" value="%s">' \ % (csrf.name, csrf.value) assert resp == expected