Browse Source

prototype patch resource on torrent

master
Jørgen Lien Sellæg 9 years ago
parent
commit
e285e768d0
  1. 15
      toREST/include/torrent.hpp
  2. 2
      toREST/src/main.cxx
  3. 20
      toREST/tests/torrent_test.cpp

15
toREST/include/torrent.hpp

@ -54,8 +54,19 @@ void get(torrent_session &session, response resp, request req) {
*resp << http_response;
}
template <class settings, class torrent_session, class request, class response>
void patch(settings opts, torrent_session &session, response resp, request req) {
template <class torrent_session, class request, class response>
void patch(torrent_session &session, response resp, request req) {
auto http_response = http::response();
const auto respond = [&](http::status status) {
const auto response_code = http::code(status);
http_response.set_body({{"code", response_code.first}, {"status", response_code.second}});
http_response.set_status(response_code.first);
*resp << http_response;
};
if (!session.is_valid()) {
return respond(http::service_unavailable);
}
}
}
}

2
toREST/src/main.cxx

@ -62,7 +62,7 @@ int main(int argc, char *argv[]) {
};
http_server.resource["^/session/torrents/([0-9a-fA-F]){40}(\\?.*)?\\/?$"]["PATCH"] = [&](std::shared_ptr<HttpServer::Response> resp, std::shared_ptr<HttpServer::Request> req) {
tr::session::torrents::id::patch(options, session, resp, req);
tr::session::torrents::id::patch(session, resp, req);
};
std::thread server_thread([&http_server]() {

20
toREST/tests/torrent_test.cpp

@ -25,7 +25,27 @@ SCENARIO("We are running a GET /session/torrents/id resource") {
tr::session::torrents::id::get(torrent_session, response, request);
CommonResponse::ok(response,{torrent_json});
}
WHEN("The torrent isn't valid"){
torrent_session.torrents_.back().valid = false;
THEN("the server should reply with bad request"){
tr::session::torrents::id::get(torrent_session, response, request);
CommonResponse::bad_request(response);
}
}
}
}
}
}
SCENARIO("We are running a PATCH /session/torrents/id resource") {
auto torrent_session = TestSession();
auto response = std::make_shared<TestResponse>();
auto request = std::make_shared<TestRequest>();
GIVEN("the server is not working properly and we recive a reqest") {
THEN("the server should reply with service unavailable") {
tr::session::torrents::id::patch(torrent_session, response, request);
CommonResponse::service_unavailable(response);
}
}
}

Loading…
Cancel
Save