Added tests for API::v1::accounts_verify_credentials.
the build was successful
Details
the build was successful
Details
This commit is contained in:
parent
0166cc7b53
commit
09793c5511
|
@ -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
|
||||||
|
|
|
@ -26,19 +26,23 @@ 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 ("id and return_call")
|
||||||
|
{
|
||||||
|
const string id = "9hnrrVPriLiLVAhfVo";
|
||||||
|
return_call ret;
|
||||||
|
bool exception = false;
|
||||||
|
|
||||||
GIVEN ("Mastodon::API")
|
GIVEN ("Mastodon::API")
|
||||||
{
|
{
|
||||||
Mastodon::API masto("likeable.space", "");
|
Mastodon::API masto("likeable.space", "");
|
||||||
return_call ret;
|
|
||||||
bool exception = false;
|
|
||||||
bool username_found = false;
|
bool username_found = false;
|
||||||
|
|
||||||
WHEN ("/api/v1/accounts/9hnrrVPriLiLVAhfVo is called")
|
WHEN ("/api/v1/accounts/" + id + " is called")
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
ret = masto.get(API::v1::accounts_id,
|
ret = masto.get(API::v1::accounts_id,
|
||||||
{{ "id", { "9hnrrVPriLiLVAhfVo" }}});
|
{{ "id", { id }}});
|
||||||
username_found = ret.answer.find(
|
username_found = ret.answer.find(
|
||||||
"\"username\":\"testaccount\"") != std::string::npos;
|
"\"username\":\"testaccount\"") != std::string::npos;
|
||||||
}
|
}
|
||||||
|
@ -65,16 +69,14 @@ SCENARIO ("/api/v1/accounts/:id can be called successfully",
|
||||||
GIVEN ("Mastodon::Easy::API")
|
GIVEN ("Mastodon::Easy::API")
|
||||||
{
|
{
|
||||||
Mastodon::Easy::API masto("likeable.space", "");
|
Mastodon::Easy::API masto("likeable.space", "");
|
||||||
return_call ret;
|
|
||||||
Easy::Account account;
|
Easy::Account account;
|
||||||
bool exception = false;
|
|
||||||
|
|
||||||
WHEN ("/api/v1/accounts/9hnrrVPriLiLVAhfVo is called")
|
WHEN ("/api/v1/accounts/" + id + " is called")
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
ret = masto.get(API::v1::accounts_id,
|
ret = masto.get(API::v1::accounts_id,
|
||||||
{{ "id", { "9hnrrVPriLiLVAhfVo" }}});
|
{{ "id", { id }}});
|
||||||
account = Easy::Account(ret.answer);
|
account = Easy::Account(ret.answer);
|
||||||
}
|
}
|
||||||
catch (const std::exception &e)
|
catch (const std::exception &e)
|
||||||
|
@ -100,4 +102,5 @@ SCENARIO ("/api/v1/accounts/:id can be called successfully",
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -26,11 +26,14 @@ 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 ("return_call")
|
||||||
|
{
|
||||||
|
return_call ret;
|
||||||
|
bool exception = false;
|
||||||
|
|
||||||
GIVEN ("Mastodon::API")
|
GIVEN ("Mastodon::API")
|
||||||
{
|
{
|
||||||
Mastodon::API masto("likeable.space", "");
|
Mastodon::API masto("likeable.space", "");
|
||||||
return_call ret;
|
|
||||||
bool exception = false;
|
|
||||||
bool uri_found = false;
|
bool uri_found = false;
|
||||||
|
|
||||||
WHEN ("/api/v1/instance is called")
|
WHEN ("/api/v1/instance is called")
|
||||||
|
@ -64,9 +67,7 @@ SCENARIO ("/api/v1/instance can be called successfully",
|
||||||
GIVEN ("Mastodon::Easy::API")
|
GIVEN ("Mastodon::Easy::API")
|
||||||
{
|
{
|
||||||
Mastodon::Easy::API masto("likeable.space", "");
|
Mastodon::Easy::API masto("likeable.space", "");
|
||||||
return_call ret;
|
|
||||||
Easy::Instance instance;
|
Easy::Instance instance;
|
||||||
bool exception = false;
|
|
||||||
|
|
||||||
WHEN ("/api/v1/instance is called")
|
WHEN ("/api/v1/instance is called")
|
||||||
{
|
{
|
||||||
|
@ -98,4 +99,5 @@ SCENARIO ("/api/v1/instance can be called successfully",
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Reference in New Issue