Пример #1
0
def test_conversion():
    # encode things in a dict that is then converted into json
    d = dict(method='convert_units_to_ml', params=['8oz'], id=1)
    encoded = simplejson.dumps(d)
    
    environ = {
        'PATH_INFO': '/rpc',
        'REQUEST_METHOD': 'POST',
        'CONTENT_LENGTH': '1000',
        'wsgi.input': StringIO.StringIO(encoded)
    }
    
    d = {}
    
    def my_start_response(s, h, return_in=d):
        d['status'] = s
        d['headers'] = h
    
    json_conversion = _run_rpc_call(environ, my_start_response)
    
    # decode response
    json_parsed = simplejson.loads("".join(json_conversion))
    
    # compare results
    assert json_parsed['result'] == to_ml('8oz')
Пример #2
0
def build_conversion_results(in_amt):
    # run calculation
    out_amt = to_ml(in_amt)
    
    # set variables dictionary
    vars = dict(inAmt=in_amt, outAmt=out_amt)
    
    # render the correct template
    template = env.get_template('conversion_results.html')
    return template.render(vars)
Пример #3
0
 def rpc_convert_units_to_ml(self, amount):
     return to_ml(amount)