From 3f09180b85a8cb273b65494a46fa9790b45bc3a5 Mon Sep 17 00:00:00 2001 From: tastytea Date: Sat, 27 Apr 2019 22:03:16 +0200 Subject: [PATCH] Added tests for API::v1::media. --- .drone.yml | 10 ++--- CMakeLists.txt | 1 + README.md | 27 ++++++------- tests/test.gif | Bin 0 -> 35 bytes tests/test_api_v1_media.cpp | 73 ++++++++++++++++++++++++++++++++++++ 5 files changed, 93 insertions(+), 18 deletions(-) create mode 100644 tests/test.gif create mode 100644 tests/test_api_v1_media.cpp diff --git a/.drone.yml b/.drone.yml index 5b41a96..62c9c14 100644 --- a/.drone.yml +++ b/.drone.yml @@ -19,7 +19,7 @@ pipeline: - apt-get install -qy libcurl4-openssl-dev libjsoncpp-dev doxygen catch - apt-get install -qy -t sid libcurlpp-dev - rm -rf build && mkdir -p build && cd build - - cmake -DWITH_EXAMPLES=YES -DWITH_TESTS=YES -DEXTRA_TEST_ARGS="[pleroma]" .. + - cmake -DWITH_EXAMPLES=YES -DWITH_TESTS=YES -DEXTRA_TEST_ARGS="[pleroma]![upload]" .. - make VERBOSE=1 - make install DESTDIR=install - ctest @@ -52,7 +52,7 @@ pipeline: - apt-get install -qy libcurl4-openssl-dev libjsoncpp-dev doxygen catch - apt-get install -qy -t sid libcurlpp-dev - rm -rf build && mkdir -p build && cd build - - cmake -DWITH_EXAMPLES=YES -DWITH_TESTS=YES -DEXTRA_TEST_ARGS="[pleroma]" .. + - cmake -DWITH_EXAMPLES=YES -DWITH_TESTS=YES -DEXTRA_TEST_ARGS="[pleroma]![upload]" .. - make VERBOSE=1 - make install DESTDIR=install - ctest @@ -85,7 +85,7 @@ pipeline: - apt-get install -qy libcurl4-openssl-dev libjsoncpp-dev doxygen catch - apt-get install -qy -t sid libcurlpp-dev - rm -rf build && mkdir -p build && cd build - - cmake -DWITH_EXAMPLES=YES -DWITH_TESTS=YES -DEXTRA_TEST_ARGS="[pleroma]" .. + - cmake -DWITH_EXAMPLES=YES -DWITH_TESTS=YES -DEXTRA_TEST_ARGS="[pleroma]![upload]" .. - make VERBOSE=1 - make install DESTDIR=install - ctest @@ -115,7 +115,7 @@ pipeline: - apt-get install -qy libcurl4-openssl-dev libjsoncpp-dev doxygen catch - apt-get install -qy -t sid libcurlpp-dev - rm -rf build && mkdir -p build && cd build - - cmake -DWITH_EXAMPLES=YES -DWITH_TESTS=YES -DEXTRA_TEST_ARGS="[pleroma]" .. + - cmake -DWITH_EXAMPLES=YES -DWITH_TESTS=YES -DEXTRA_TEST_ARGS="[pleroma]![upload]" .. - make VERBOSE=1 - make install DESTDIR=install - ctest @@ -145,7 +145,7 @@ pipeline: - apt-get install -qy libcurl4-openssl-dev libjsoncpp-dev doxygen catch - apt-get install -qy -t sid libcurlpp-dev - rm -rf build && mkdir -p build && cd build - - cmake -DWITH_EXAMPLES=YES -DWITH_TESTS=YES -DEXTRA_TEST_ARGS="[pleroma]" .. + - cmake -DWITH_EXAMPLES=YES -DWITH_TESTS=YES -DEXTRA_TEST_ARGS="[pleroma]![upload]" .. - make VERBOSE=1 - make install DESTDIR=install - ctest diff --git a/CMakeLists.txt b/CMakeLists.txt index 55dabc6..b9df8ff 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -93,6 +93,7 @@ endif() # Compile tests if(WITH_TESTS) + configure_file("tests/test.gif" "${CMAKE_CURRENT_BINARY_DIR}" COPYONLY) include(tests.CMakeLists.txt) endif() diff --git a/README.md b/README.md index 85e2945..3f8598b 100644 --- a/README.md +++ b/README.md @@ -220,19 +220,20 @@ cmake --build . -- -j$(nproc --ignore=1) cmake options: - * `-DCMAKE_BUILD_TYPE=Debug` for a debug build - * `-DWITH_EASY=NO` to not build the Easy abstractions and to get rid of the - jsoncpp-dependency (not recommended) - * `-DWITH_EXAMPLES=YES` if you want to compile the examples - * `-DWITH_TESTS=YES` if you want to compile the tests - * `-DEXTRA_TEST_ARGS` to run only some tests - * Possible values: `[api]`, `[mastodon]`, `[glitch-soc]`, `[pleroma]` - * Example: `-DEXTRA_TEST_ARGS=[pleroma]![mastodon]` to run the tests for features - in Pleroma that are not in Mastodon. - * `-DWITH_DOC=NO` if you don't want to compile the HTML reference - * One of: - * `-DWITH_DEB=YES` if you want to be able to generate a deb-package - * `-DWITH_RPM=YES` if you want to be able to generate an rpm-package +* `-DCMAKE_BUILD_TYPE=Debug` for a debug build +* `-DWITH_EASY=NO` to not build the Easy abstractions and to get rid of the + jsoncpp-dependency (not recommended) +* `-DWITH_EXAMPLES=YES` if you want to compile the examples +* `-DWITH_TESTS=YES` if you want to compile the tests +* `-DEXTRA_TEST_ARGS` to run only some tests + * Possible values: `[api]`, `[mastodon]`, `[glitch-soc]`, `[pleroma]`, `[upload]` + * Example: `-DEXTRA_TEST_ARGS=[pleroma]![mastodon]` to run the tests for + features in Pleroma that are not in Mastodon. + * `[upload]` tags tests that upload files. +* `-DWITH_DOC=NO` if you don't want to compile the HTML reference +* One of: + * `-DWITH_DEB=YES` if you want to be able to generate a deb-package + * `-DWITH_RPM=YES` if you want to be able to generate an rpm-package Install with `make install`. diff --git a/tests/test.gif b/tests/test.gif new file mode 100644 index 0000000000000000000000000000000000000000..b636f4b8df536b0a85e7cea1a6cf3f0bd3179b96 GIT binary patch literal 35 jcmZ?wbh9u|WMp7uXkcLY4+c66KmZb9U}AD%WUvMRyAlZ1 literal 0 HcmV?d00001 diff --git a/tests/test_api_v1_media.cpp b/tests/test_api_v1_media.cpp new file mode 100644 index 0000000..b00f8d4 --- /dev/null +++ b/tests/test_api_v1_media.cpp @@ -0,0 +1,73 @@ +/* This file is part of mastodon-cpp. + * Copyright © 2019 tastytea + * + * 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 . + */ + +#include +#include +#include +#include "mastodon-cpp.hpp" +#include "easy/easy.hpp" +#include "easy/entities/attachment.hpp" +#include "environment_variables.hpp" + +using namespace Mastodon; + +SCENARIO ("/api/v1/media can be called successfully", + "[api][mastodon][pleroma][glitch-soc][upload]") +{ + REQUIRE (access_token != nullptr); + + GIVEN ("instance = " + instance) + { + Mastodon::Easy::API masto(instance, access_token); + return_call ret; + Easy::Attachment attachment; + bool exception = false; + + WHEN ("POST /api/v1/media is called") + { + try + { + ret = masto.post(API::v1::media, + { + { "file", { "test.gif" }}, + { "description", { "Test pixel." }}, + { "focus", { "0.0,0.0" }} + }); + attachment.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(attachment.valid()); + + REQUIRE(attachment.description() == "Test pixel."); + } + } + } +} +