Browse Source

Can now add torrents paused

master
Jørgen Lien Sellæg 9 years ago
parent
commit
7f1140e372
  1. 15
      toREST/include/torrents.hpp
  2. 2
      toREST/tests/include/TorrentContext.hpp
  3. 14
      toREST/tests/torrents_test.cpp

15
toREST/include/torrents.hpp

@ -84,6 +84,21 @@ void post(settings opts, torrent_session &session, response resp, request req) {
} else } else
params.save_path = boost::filesystem::path(opts.root_dir / opts.default_download_dir).string(); params.save_path = boost::filesystem::path(opts.root_dir / opts.default_download_dir).string();
params.flags = params.flags & ~libtorrent::add_torrent_params::flag_paused;
if (request_object.find("paused") != request_object.end()) {
bool paused = false;
auto obj = request_object.at("paused");
if (obj.is_boolean())
paused = request_object.at("paused");
else if (obj.is_string()) {
std::string p = obj;
paused = p == "true";
}
if (paused)
params.flags |= libtorrent::add_torrent_params::flag_paused;
}
session.async_add_torrent(params); session.async_add_torrent(params);
std::stringstream ss; std::stringstream ss;

2
toREST/tests/include/TorrentContext.hpp

@ -26,6 +26,8 @@ public:
class TestTorrent { class TestTorrent {
public: public:
TestTorrent(const libtorrent::add_torrent_params &params) : hash(params.info_hash.to_string()) { TestTorrent(const libtorrent::add_torrent_params &params) : hash(params.info_hash.to_string()) {
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_.save_path = params.save_path;
} }
TestTorrent() : hash("12a") {} TestTorrent() : hash("12a") {}

14
toREST/tests/torrents_test.cpp

@ -89,9 +89,23 @@ SCENARIO("We are running a POST /session/torrents resource") {
{{"magnet_uri", magnet_uri}, {{"magnet_uri", magnet_uri},
{"save_path", "music"}}); {"save_path", "music"}});
tr::session::torrents::post(settings, torrent_session, response, request); tr::session::torrents::post(settings, torrent_session, response, request);
THEN("the server should reply created") {
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().save_path == "/music");
}
}
GIVEN("we specify the torrent field to be paused") {
request->content << nlohmann::json::object(
{{"magnet_uri", magnet_uri},
{"save_path", "music"},
{"paused", "true"}});
THEN("the server should reply with bad request") { 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); CommonResponse::created(response, request, "/session/torrents/" + magnet_hash);
REQUIRE(torrent_session.get_torrents().size() == 1); REQUIRE(torrent_session.get_torrents().size() == 1);
REQUIRE(torrent_session.get_torrents()[0].status().paused);
REQUIRE((torrent_session.get_torrents()[0]).status().save_path == "/music"); REQUIRE((torrent_session.get_torrents()[0]).status().save_path == "/music");
} }
} }

Loading…
Cancel
Save