예제 #1
0
	def test_cant_register_without_name_or_endpoint(self):
		player_data = {
			"name": uuid4().hex,
		}

		response, data = request('player', 'POST', player_data)
		assert response.status == 400, (response, data)

		player_data = {
			"endpoint": uuid4().hex,
		}

		response, data = request('player', 'POST', player_data)
		assert response.status == 400, (response, data)
예제 #2
0
	def test_list_players(self):
		response, data = request('players')
		assert response.status == 200, (response, data)

		players = json.loads(data)['players']

		assert len(players) == 0, players

		create_player()

		response, data = request('players')
		assert response.status == 200, (response, data)

		players = json.loads(data)['players']

		assert len(players) == 1, players
예제 #3
0
def test_request_content_type(content_type_header):
    response = test.request(headers={content_type_header: _content_types.CSV})
    assert response.content_type == _content_types.CSV

    response = _worker.Request(
        test.environ(headers={"ContentType": _content_types.NPY}))
    assert response.content_type == _content_types.NPY
def test_request():
    request = test.request(data='42')

    assert request.content_type == _content_types.JSON
    assert request.accept == _content_types.JSON
    assert request.content == '42'

    request = test.request(data=_encoders.encode([6, 9.3], _content_types.NPY),
                           content_type=_content_types.NPY,
                           accept=_content_types.CSV)

    assert request.content_type == _content_types.NPY
    assert request.accept == _content_types.CSV

    result = _encoders.decode(request.data, _content_types.NPY)
    np.testing.assert_array_equal(result, np.array([6, 9.3]))
def test_transformer_transform_with_unsupported_content_type():
    bad_request = test.request(data=None, headers={"ContentType": "fake/content-type"})
    with patch("sagemaker_containers._worker.Request", lambda: bad_request):
        response = _transformer.Transformer().transform()

    assert response.status_code == http_client.UNSUPPORTED_MEDIA_TYPE

    response_body = json.loads(response.response[0].decode("utf-8"))
    assert response_body["error"] == "UnsupportedFormatError"
    assert bad_request.content_type in response_body["error-message"]
def test_transformer_transform_with_unsupported_content_type():
    bad_request = test.request(data=None, content_type='fake/content-type')
    with patch('sagemaker_containers._worker.Request', lambda: bad_request):
        response = _transformer.Transformer().transform()

    assert response.status_code == http_client.UNSUPPORTED_MEDIA_TYPE

    response_body = json.loads(response.response[0].decode('utf-8'))
    assert response_body['error'] == 'UnsupportedFormatError'
    assert bad_request.content_type in response_body['error-message']
예제 #7
0
	def test_register_with_id(self):
		player_data = {
			"id": uuid4().hex,
			"name": uuid4().hex,
			"endpoint": "http://example.com/"
		}

		response, data = request('player', 'POST', player_data)
		assert response.status == 201, (response, data)

		player = json.loads(data)['player']

		assert player['id'] == player_data['id'], (response, data)
def test_transformer_transform_with_unsupported_accept_type():
    def empty_fn(*args):
        pass

    bad_request = test.request(data=None, headers={"Accept": "fake/content-type"})
    with patch("sagemaker_containers._worker.Request", lambda: bad_request):
        t = _transformer.Transformer(model_fn=empty_fn, input_fn=empty_fn, predict_fn=empty_fn)
        response = t.transform()

    assert response.status_code == http_client.NOT_ACCEPTABLE

    response_body = json.loads(response.response[0].decode("utf-8"))
    assert response_body["error"] == "UnsupportedFormatError"
    assert bad_request.accept in response_body["error-message"]
예제 #9
0
def weixin_test(request):
    import test
    tmpobj = test.request()
    instr = smart_str(request.GET.get("input",None))
    #instr = instr.decode('utf-8','ignore')
    #print instr + 'new\n'
    tmpobj.setmessage(instr)
    if request.GET.get("type",None):
        tmpobj.locationmessage(request.GET.get("type"))
    a = process(tmpobj)
    #print a
    a = a.replace('<','&lt;')
    a = a.replace('>','&gt;')
    
    return HttpResponse("<title>test page</title><body><pre>%s</pre></body>" % a)
예제 #10
0
	def test_register(self):
		player_data = {
			"name": uuid4().hex,
			"endpoint": "http://example.com/"
		}

		response, data = request('player', 'POST', player_data)
		assert response.status == 201, (response, data)

		player = json.loads(data)['player']

		assert 'id' in player, player
		assert 'secret' in player, player
		assert player['name'] == player_data['name'], player
		assert player['endpoint'] == player_data['endpoint'], player
def test_transformer_transform_with_unsupported_accept_type():
    def empty_fn(*args):
        pass

    bad_request = test.request(data=None, accept='fake/content_type')
    with patch('sagemaker_containers._worker.Request', lambda: bad_request):
        t = _transformer.Transformer(model_fn=empty_fn,
                                     input_fn=empty_fn,
                                     predict_fn=empty_fn)
        response = t.transform()

    assert response.status_code == http_client.NOT_ACCEPTABLE

    response_body = json.loads(response.response[0].decode('utf-8'))
    assert response_body['error'] == 'UnsupportedFormatError'
    assert bad_request.accept in response_body['error-message']
예제 #12
0
 def test_basic(self):
     response = test.request('GET', '/')
     self.assertEquals(404, response.status)
     self.assertEquals('404 Not Found', response.read())
    response = _transformer.default_output_fn(2, _content_types.CSV)
    assert response.response == 4
    assert response.headers['accept'] == _content_types.CSV


def test_default_model_fn():
    with pytest.raises(NotImplementedError):
        _transformer.default_model_fn('model_dir')


def test_predict_fn():
    with pytest.raises(NotImplementedError):
        _transformer.default_predict_fn('data', 'model')


request = test.request(data='42', content_type=_content_types.JSON)


def test_transformer_initialize_with_default_model_fn():
    with pytest.raises(NotImplementedError):
        _transformer.Transformer().initialize()


error_from_fn = ValueError('Failed')


def fn_with_error(*args, **kwargs):
    raise error_from_fn


def test_transformer_initialize_with_client_error():
예제 #14
0
def test_request_content_type():
    response = test.request(content_type=_content_types.CSV)
    assert response.content_type == _content_types.CSV

    response = test.request(headers={'ContentType': _content_types.NPY})
    assert response.content_type == _content_types.NPY
    response = _transformer.default_output_fn(2, _content_types.CSV)
    assert response.response == 4
    assert response.mimetype == _content_types.CSV


def test_default_model_fn():
    with pytest.raises(NotImplementedError):
        _transformer.default_model_fn("model_dir")


def test_predict_fn():
    with pytest.raises(NotImplementedError):
        _transformer.default_predict_fn("data", "model")


request = test.request(data="42", headers={"ContentType": _content_types.JSON})


def test_transformer_initialize_with_default_model_fn():
    with pytest.raises(NotImplementedError):
        _transformer.Transformer().initialize()


error_from_fn = ValueError("Failed")


def fn_with_error(*args, **kwargs):
    raise error_from_fn


def test_transformer_initialize_with_client_error():
예제 #16
0
def test_request_accept_env():
    request = test.request()
    assert request.accept == '42'
예제 #17
0
    response = _transformer.default_output_fn(2, _content_types.CSV)
    assert response.response == 4
    assert response.headers['accept'] == _content_types.CSV


def test_default_model_fn():
    with pytest.raises(NotImplementedError):
        _transformer.default_model_fn('model_dir')


def test_predict_fn():
    with pytest.raises(NotImplementedError):
        _transformer.default_predict_fn('data', 'model')


request = test.request(data='42', headers={'ContentType': _content_types.JSON})


def test_transformer_initialize_with_default_model_fn():
    with pytest.raises(NotImplementedError):
        _transformer.Transformer().initialize()


error_from_fn = ValueError('Failed')


def fn_with_error(*args, **kwargs):
    raise error_from_fn


def test_transformer_initialize_with_client_error():
예제 #18
0
 def test_basic(self):
     response = test.request('GET', '/UNLICENSE')
     self.assertEquals(200, response.status)
     self.assertEquals(os.stat('UNLICENSE').st_size, len(response.read()))