Browse Source

now able to set name on add

master
Jørgen Lien Sellæg 9 years ago
parent
commit
f22456899a
  1. 6
      toREST/include/torrents.hpp
  2. 1
      toREST/tests/include/TorrentContext.hpp
  3. 1
      toREST/tests/stubs/SessionContext.cpp
  4. 15
      toREST/tests/torrents_test.cpp

6
toREST/include/torrents.hpp

@ -122,6 +122,12 @@ void post(settings opts, torrent_session &session, response resp, request req) {
}
params.download_limit = down_limit;
}
if (request_object.find("name") != request_object.end()) {
auto obj = request_object.at("name");
if(obj.is_string())
params.name = obj;
}
std::stringstream ss;
ss << params.info_hash;

1
toREST/tests/include/TorrentContext.hpp

@ -29,6 +29,7 @@ public:
auto paused = (params.flags & libtorrent::add_torrent_params::flag_paused) == libtorrent::add_torrent_params::flag_paused;
status_.paused = paused;
status_.save_path = params.save_path;
status_.name = params.name;
upload_limit_ = params.upload_limit;
download_limit_ = params.download_limit;
}

1
toREST/tests/stubs/SessionContext.cpp

@ -33,6 +33,7 @@ std::string TestSessionSettings::get_str(int type) {
if (type == listen_interfaces) {
return listen_interfaces_;
}
return "";
}
void TestSessionSettings::set_str(int type, std::string value) {
if (type == listen_interfaces) {

15
toREST/tests/torrents_test.cpp

@ -19,7 +19,7 @@ SCENARIO("We are running a GET /session/torrents resource") {
auto response = std::make_shared<TestResponse>();
auto request = std::make_shared<TestRequest>();
GIVEN("the server is not working properly") {
AND_WHEN("we recive a request") {
WHEN("we recive a request") {
tr::session::torrents::get(torrent_session, response, request);
THEN("the server should reply with service unavailable") {
CommonResponse::service_unavailable(response);
@ -88,11 +88,13 @@ SCENARIO("We are running a POST /session/torrents resource") {
request->content << nlohmann::json::object(
{{"magnet_uri", magnet_uri},
{"save_path", "music"}});
tr::session::torrents::post(settings, torrent_session, response, request);
THEN("the server should reply created") {
tr::session::torrents::post(settings, torrent_session, response, request);
CommonResponse::created(response, request, "/session/torrents/" + magnet_hash);
REQUIRE(torrent_session.get_torrents().size() == 1);
REQUIRE_FALSE(torrent_session.get_torrents()[0].status().paused);
REQUIRE(torrent_session.get_torrents()[0].upload_limit() == -1);
REQUIRE(torrent_session.get_torrents()[0].download_limit() == -1);
REQUIRE((torrent_session.get_torrents()[0]).status().save_path == "/music");
}
}
@ -106,20 +108,25 @@ SCENARIO("We are running a POST /session/torrents resource") {
CommonResponse::created(response, request, "/session/torrents/" + magnet_hash);
REQUIRE(torrent_session.get_torrents().size() == 1);
REQUIRE(torrent_session.get_torrents()[0].status().paused);
REQUIRE(torrent_session.get_torrents()[0].upload_limit() == -1);
REQUIRE(torrent_session.get_torrents()[0].download_limit() == -1);
REQUIRE((torrent_session.get_torrents()[0]).status().save_path == "/music");
}
}
GIVEN("we specify up an ddown speed") {
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", "100"},
{"down_speed", "100"}});
{"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/" + magnet_hash);
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() == 100);
REQUIRE(torrent_session.get_torrents()[0].download_limit() == 100);
REQUIRE((torrent_session.get_torrents()[0]).status().save_path == "/music");

Loading…
Cancel
Save