Browse Source

Add test case to check int format on speed

master
Jørgen Lien Sellæg 9 years ago
parent
commit
ece53bc6f7
  1. 7
      toREST/src/main.cxx
  2. 19
      toREST/tests/torrents_test.cpp

7
toREST/src/main.cxx

@ -29,7 +29,7 @@ int main(int argc, char *argv[]) {
HttpServer http_server(http_port, http_threads);
libtorrent::session session;
const auto stats_metrics = libtorrent::session_stats_metrics();
http_server.default_resource["GET"] = [](std::shared_ptr<HttpServer::Response> resp, std::shared_ptr<HttpServer::Request> req) {
auto response = http::response();
response.set_status(http::not_found);
@ -47,10 +47,15 @@ int main(int argc, char *argv[]) {
http_server.resource["^/session/torrents(\\?.*)?\\/?$"]["GET"] = [&](std::shared_ptr<HttpServer::Response> resp, std::shared_ptr<HttpServer::Request> req) {
tr::session::torrents::get(session, resp, req);
};
http_server.resource["^/session/torrents(\\?.*)?\\/?$"]["POST"] = [&](std::shared_ptr<HttpServer::Response> resp, std::shared_ptr<HttpServer::Request> req) {
tr::session::torrents::post(options, session, resp, req);
};
http_server.resource["^/session/torrents(\\?.*)?\\/?$"]["DELETE"] = [&](std::shared_ptr<HttpServer::Response> resp, std::shared_ptr<HttpServer::Request> req) {
tr::session::torrents::del(session, resp, req);
};
std::thread server_thread([&http_server]() {
http_server.start();
});

19
toREST/tests/torrents_test.cpp

@ -136,6 +136,25 @@ SCENARIO("We are running a POST /session/torrents resource") {
REQUIRE((torrent_session.get_torrents()[0]).status().save_path == "/music");
}
}
GIVEN("we specify up an down speed") {
const std::string name = "Dent";
request->content << nlohmann::json::object(
{{"magnet_uri", magnet_uri},
{"save_path", "music"},
{"up_speed", 90},
{"down_speed", "100"},
{"name", name}});
THEN("the server should reply with bad request") {
tr::session::torrents::post(settings, torrent_session, response, request);
CommonResponse::created(response, request, "/session/torrents/" + torrent_id);
REQUIRE(torrent_session.get_torrents().size() == 1);
REQUIRE_FALSE(torrent_session.get_torrents()[0].status().paused);
REQUIRE(torrent_session.get_torrents()[0].status().name == name);
REQUIRE(torrent_session.get_torrents()[0].upload_limit() == 90);
REQUIRE(torrent_session.get_torrents()[0].download_limit() == 100);
REQUIRE((torrent_session.get_torrents()[0]).status().save_path == "/music");
}
}
}
WHEN("we recive an invalid request") {
GIVEN("the request doesn't contain valid json") {

Loading…
Cancel
Save