Added tests for API::v1::filters_id.
the build was successful Details

This commit is contained in:
tastytea 2019-04-19 05:35:43 +02:00
parent 90a6873a38
commit 53b2a4bbc6
Signed by: tastytea
GPG Key ID: CFC39497F1B26E07
4 changed files with 135 additions and 1 deletions

View File

@ -219,7 +219,8 @@ scopes *read*, *write* and *follow* for some tests.
You can select the instance to use with `MASTODON_CPP_INSTANCE`, the default is
*likeable.space*. You can select the user ID with `MASTODON_CPP_USER_ID`, the
default is *9hnrrVPriLiLVAhfVo*. You can select the status ID with
`MASTODON_CPP_STATUS_ID`, the default is *9hwnuJMq3eTdO4s1PU*.
`MASTODON_CPP_STATUS_ID`, the default is *9hwnuJMq3eTdO4s1PU*. You can select
the filter ID with `MASTODON_CPP_FILTER_ID`.
Requirements for the test-user:

View File

@ -29,5 +29,7 @@ extern const char *env_user_id;
extern const string user_id;
extern const char *env_status_id;
extern const string status_id;
extern const char *env_filter_id;
extern const string filter_id;
#endif // MASTODON_CPP_TEST_ENVIRONMENT_VARIABLES_HPP

View File

@ -31,3 +31,5 @@ const char *env_user_id = getenv("MASTODON_CPP_USER_ID");
const string user_id = (env_user_id ? env_user_id : "9hnrrVPriLiLVAhfVo");
const char *env_status_id = getenv("MASTODON_CPP_STATUS_ID");
const string status_id = (env_status_id ? env_status_id : "9hwnuJMq3eTdO4s1PU");
const char *env_filter_id = getenv("MASTODON_CPP_FILTER_ID");
const string filter_id = (env_filter_id ? env_filter_id : "");

View File

@ -0,0 +1,129 @@
/* This file is part of mastodon-cpp.
* Copyright © 2019 tastytea <tastytea@tastytea.de>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <exception>
#include <string>
#include <catch.hpp>
#include "mastodon-cpp.hpp"
#include "easy/easy.hpp"
#include "easy/entities/filter.hpp"
#include "environment_variables.hpp"
using namespace Mastodon;
SCENARIO ("/api/v1/filters/:id can be called successfully",
"[api][mastodon][glitch-soc]")
{
REQUIRE (access_token != nullptr);
GIVEN ("instance = " + instance + ", user ID = " + user_id)
{
Mastodon::Easy::API masto(instance, access_token);
return_call ret;
Easy::Filter filter;
bool exception = false;
WHEN ("GET /api/v1/filters/" + filter_id + " is called")
{
try
{
ret = masto.get(API::v1::filters_id,
{{ "id", { "filter_id " }}});
filter.from_string(ret.answer);
}
catch (const std::exception &e)
{
exception = true;
WARN(e.what());
}
THEN("No exception is thrown")
AND_THEN ("No errors are returned")
AND_THEN ("Answer is valid")
AND_THEN ("The answer makes sense")
{
REQUIRE_FALSE(exception);
REQUIRE(ret.error_code == 0);
REQUIRE(ret.http_error_code == 200);
REQUIRE(filter.valid());
REQUIRE(filter.id() == filter_id);
}
}
WHEN ("PUT /api/v1/filters/" + filter_id + " is called")
{
try
{
ret = masto.put(API::v1::filters_id,
{
{ "id", { "filter_id " }},
{ "phrase", { "Katzenklappenreinigungs"
"vertragsangestellter"
"praktikantin" }},
{ "context", { "public", "notifications" }}
});
filter.from_string(ret.answer);
}
catch (const std::exception &e)
{
exception = true;
WARN(e.what());
}
THEN("No exception is thrown")
AND_THEN ("No errors are returned")
AND_THEN ("Answer is valid")
AND_THEN ("The answer makes sense")
{
REQUIRE_FALSE(exception);
REQUIRE(ret.error_code == 0);
REQUIRE(ret.http_error_code == 200);
REQUIRE(filter.valid());
REQUIRE(filter.phrase()[0] == 'K');
}
}
WHEN ("DELETE /api/v1/filters/" + filter_id + " is called")
{
try
{
ret = masto.del(API::v1::filters_id,
{{ "id", { "filter_id " }}});
}
catch (const std::exception &e)
{
exception = true;
WARN(e.what());
}
THEN("No exception is thrown")
AND_THEN ("No errors are returned")
{
REQUIRE_FALSE(exception);
REQUIRE(ret.error_code == 0);
REQUIRE(ret.http_error_code == 200);
}
}
}
}