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

This commit is contained in:
tastytea 2019-04-14 21:57:22 +02:00
parent 0166cc7b53
commit 09793c5511
Signed by: tastytea
GPG Key ID: CFC39497F1B26E07
4 changed files with 236 additions and 118 deletions

View File

@ -8,6 +8,8 @@ pipeline:
- LANG=C.utf8 - LANG=C.utf8
- CXX=g++-6 - CXX=g++-6
- CXXFLAGS=-pipe -O2 - CXXFLAGS=-pipe -O2
secrets:
- mastodon_cpp_access_token
commands: commands:
- rm /etc/apt/apt.conf.d/docker-clean - rm /etc/apt/apt.conf.d/docker-clean
- echo "APT::Default-Release \"stretch\";" >> /etc/apt/apt.conf.d/00default_release - echo "APT::Default-Release \"stretch\";" >> /etc/apt/apt.conf.d/00default_release
@ -33,6 +35,8 @@ pipeline:
- LANG=C.utf8 - LANG=C.utf8
- CXX=g++-7 - CXX=g++-7
- CXXFLAGS=-pipe -O2 - CXXFLAGS=-pipe -O2
secrets:
- mastodon_cpp_access_token
commands: commands:
- rm /etc/apt/apt.conf.d/docker-clean - rm /etc/apt/apt.conf.d/docker-clean
- apt-get update -q - apt-get update -q
@ -64,6 +68,8 @@ pipeline:
- LANG=C.utf8 - LANG=C.utf8
- CXX=g++-8 - CXX=g++-8
- CXXFLAGS=-pipe -O2 - CXXFLAGS=-pipe -O2
secrets:
- mastodon_cpp_access_token
commands: commands:
- rm /etc/apt/apt.conf.d/docker-clean - rm /etc/apt/apt.conf.d/docker-clean
- apt-get update -q - apt-get update -q

View File

@ -26,77 +26,80 @@ using namespace Mastodon;
SCENARIO ("/api/v1/accounts/:id can be called successfully", SCENARIO ("/api/v1/accounts/:id can be called successfully",
"[api][mastodon][pleroma][glitch-soc]") "[api][mastodon][pleroma][glitch-soc]")
{ {
GIVEN ("Mastodon::API") GIVEN ("id and return_call")
{ {
Mastodon::API masto("likeable.space", ""); const string id = "9hnrrVPriLiLVAhfVo";
return_call ret; return_call ret;
bool exception = false; bool exception = false;
bool username_found = false;
WHEN ("/api/v1/accounts/9hnrrVPriLiLVAhfVo is called") GIVEN ("Mastodon::API")
{ {
try Mastodon::API masto("likeable.space", "");
bool username_found = false;
WHEN ("/api/v1/accounts/" + id + " is called")
{ {
ret = masto.get(API::v1::accounts_id, try
{{ "id", { "9hnrrVPriLiLVAhfVo" }}}); {
username_found = ret.answer.find( ret = masto.get(API::v1::accounts_id,
"\"username\":\"testaccount\"") != std::string::npos; {{ "id", { id }}});
} username_found = ret.answer.find(
catch (const std::exception &e) "\"username\":\"testaccount\"") != std::string::npos;
{ }
exception = true; catch (const std::exception &e)
} {
THEN("No exception is thrown") exception = true;
{ }
REQUIRE_FALSE(exception); THEN("No exception is thrown")
} {
THEN ("No errors are returned") REQUIRE_FALSE(exception);
{ }
REQUIRE(ret.error_code == 0); THEN ("No errors are returned")
REQUIRE(ret.http_error_code == 200); {
} REQUIRE(ret.error_code == 0);
THEN ("The answer makes sense") REQUIRE(ret.http_error_code == 200);
{ }
REQUIRE(username_found); THEN ("The answer makes sense")
{
REQUIRE(username_found);
}
} }
} }
}
GIVEN ("Mastodon::Easy::API") GIVEN ("Mastodon::Easy::API")
{
Mastodon::Easy::API masto("likeable.space", "");
return_call ret;
Easy::Account account;
bool exception = false;
WHEN ("/api/v1/accounts/9hnrrVPriLiLVAhfVo is called")
{ {
try Mastodon::Easy::API masto("likeable.space", "");
Easy::Account account;
WHEN ("/api/v1/accounts/" + id + " is called")
{ {
ret = masto.get(API::v1::accounts_id, try
{{ "id", { "9hnrrVPriLiLVAhfVo" }}}); {
account = Easy::Account(ret.answer); ret = masto.get(API::v1::accounts_id,
} {{ "id", { id }}});
catch (const std::exception &e) account = Easy::Account(ret.answer);
{ }
exception = true; catch (const std::exception &e)
} {
THEN("No exception is thrown") exception = true;
{ }
REQUIRE_FALSE(exception); THEN("No exception is thrown")
} {
THEN ("No errors are returned") REQUIRE_FALSE(exception);
{ }
REQUIRE(ret.error_code == 0); THEN ("No errors are returned")
REQUIRE(ret.http_error_code == 200); {
} REQUIRE(ret.error_code == 0);
THEN ("Answer is valid") REQUIRE(ret.http_error_code == 200);
{ }
REQUIRE(account.valid()); THEN ("Answer is valid")
} {
THEN ("The answer makes sense") REQUIRE(account.valid());
{ }
REQUIRE(account.username() == "testaccount"); THEN ("The answer makes sense")
{
REQUIRE(account.username() == "testaccount");
}
} }
} }
} }

View File

@ -0,0 +1,107 @@
/* 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 <cstdlib>
#include <catch.hpp>
#include "mastodon-cpp.hpp"
#include "easy/easy.hpp"
#include "easy/entities/account.hpp"
using namespace Mastodon;
SCENARIO ("/api/v1/accounts/verify_credentials can be called successfully",
"[api][mastodon][pleroma][glitch-soc]")
{
GIVEN ("access token return_call")
{
const char *access_token = std::getenv("MASTODON_CPP_ACCESS_TOKEN");
return_call ret;
bool exception = false;
bool username_found = false;
REQUIRE (access_token != nullptr);
GIVEN ("Mastodon::API")
{
Mastodon::API masto("likeable.space", access_token);
WHEN ("/api/v1/accounts/verify_credentials is called")
{
try
{
ret = masto.get(API::v1::accounts_verify_credentials);
username_found = ret.answer.find(
"\"username\":\"testaccount\"") != std::string::npos;
}
catch (const std::exception &e)
{
exception = true;
}
THEN("No exception is thrown")
{
REQUIRE_FALSE(exception);
}
THEN ("No errors are returned")
{
REQUIRE(ret.error_code == 0);
REQUIRE(ret.http_error_code == 200);
}
THEN ("The answer makes sense")
{
REQUIRE(username_found);
}
}
}
GIVEN ("Mastodon::Easy::API")
{
Mastodon::Easy::API masto("likeable.space", access_token);
Easy::Account account;
WHEN ("/api/v1/accounts/verify_credentials is called")
{
try
{
ret = masto.get(API::v1::accounts_verify_credentials);
account = Easy::Account(ret.answer);
}
catch (const std::exception &e)
{
exception = true;
}
THEN("No exception is thrown")
{
REQUIRE_FALSE(exception);
}
THEN ("No errors are returned")
{
REQUIRE(ret.error_code == 0);
REQUIRE(ret.http_error_code == 200);
}
THEN ("Answer is valid")
{
REQUIRE(account.valid());
}
THEN ("The answer makes sense")
{
REQUIRE(account.username() == "testaccount");
}
}
}
}
}

View File

@ -26,75 +26,77 @@ using namespace Mastodon;
SCENARIO ("/api/v1/instance can be called successfully", SCENARIO ("/api/v1/instance can be called successfully",
"[api][mastodon][pleroma][glitch-soc]") "[api][mastodon][pleroma][glitch-soc]")
{ {
GIVEN ("Mastodon::API") GIVEN ("return_call")
{ {
Mastodon::API masto("likeable.space", "");
return_call ret; return_call ret;
bool exception = false; bool exception = false;
bool uri_found = false;
WHEN ("/api/v1/instance is called") GIVEN ("Mastodon::API")
{ {
try Mastodon::API masto("likeable.space", "");
bool uri_found = false;
WHEN ("/api/v1/instance is called")
{ {
ret = masto.get(API::v1::instance); try
uri_found = ret.answer.find( {
"\"uri\":\"https://likeable.space\"") != std::string::npos; ret = masto.get(API::v1::instance);
} uri_found = ret.answer.find(
catch (const std::exception &e) "\"uri\":\"https://likeable.space\"") != std::string::npos;
{ }
exception = true; catch (const std::exception &e)
} {
THEN("No exception is thrown") exception = true;
{ }
REQUIRE_FALSE(exception); THEN("No exception is thrown")
} {
THEN ("No errors are returned") REQUIRE_FALSE(exception);
{ }
REQUIRE(ret.error_code == 0); THEN ("No errors are returned")
REQUIRE(ret.http_error_code == 200); {
} REQUIRE(ret.error_code == 0);
THEN ("The answer makes sense") REQUIRE(ret.http_error_code == 200);
{ }
REQUIRE(uri_found); THEN ("The answer makes sense")
{
REQUIRE(uri_found);
}
} }
} }
}
GIVEN ("Mastodon::Easy::API") GIVEN ("Mastodon::Easy::API")
{
Mastodon::Easy::API masto("likeable.space", "");
return_call ret;
Easy::Instance instance;
bool exception = false;
WHEN ("/api/v1/instance is called")
{ {
try Mastodon::Easy::API masto("likeable.space", "");
Easy::Instance instance;
WHEN ("/api/v1/instance is called")
{ {
ret = masto.get(API::v1::instance); try
instance = Easy::Instance(ret.answer); {
} ret = masto.get(API::v1::instance);
catch (const std::exception &e) instance = Easy::Instance(ret.answer);
{ }
exception = true; catch (const std::exception &e)
} {
THEN("No exception is thrown") exception = true;
{ }
REQUIRE_FALSE(exception); THEN("No exception is thrown")
} {
THEN ("No errors are returned") REQUIRE_FALSE(exception);
{ }
REQUIRE(ret.error_code == 0); THEN ("No errors are returned")
REQUIRE(ret.http_error_code == 200); {
} REQUIRE(ret.error_code == 0);
THEN ("Answer is valid") REQUIRE(ret.http_error_code == 200);
{ }
REQUIRE(instance.valid()); THEN ("Answer is valid")
} {
THEN ("The answer makes sense") REQUIRE(instance.valid());
{ }
REQUIRE(instance.uri() == "https://likeable.space"); THEN ("The answer makes sense")
{
REQUIRE(instance.uri() == "https://likeable.space");
}
} }
} }
} }