File indexing completed on 2024-10-06 12:56:09
0001 // SPDX-FileCopyrightText: 2022 Carl Schwan <carl@carlschwan.eu> 0002 // SPDX-License-Identifier: GPL-3.0-or-later 0003 0004 #include "account/abstractaccount.h" 0005 #include <QNetworkReply> 0006 0007 class MockAccount : public AbstractAccount 0008 { 0009 Q_OBJECT 0010 0011 public: 0012 MockAccount(QObject *parent = nullptr); 0013 void get(const QUrl &url, 0014 bool authenticated, 0015 QObject *parent, 0016 std::function<void(QNetworkReply *)> callback, 0017 std::function<void(QNetworkReply *)> errorCallback = nullptr) override; 0018 0019 void post(const QUrl &url, 0020 const QJsonDocument &doc, 0021 bool authenticated, 0022 QObject *parent, 0023 std::function<void(QNetworkReply *)> callback, 0024 std::function<void(QNetworkReply *)> errorCallback, 0025 QHash<QByteArray, QByteArray> headers = {}) override; 0026 0027 void post(const QUrl &url, const QUrlQuery &formdata, bool authenticated, QObject *parent, std::function<void(QNetworkReply *)> callback) override; 0028 0029 QNetworkReply *post(const QUrl &url, QHttpMultiPart *message, bool authenticated, QObject *parent, std::function<void(QNetworkReply *)> callback) override; 0030 0031 void put(const QUrl &url, const QJsonDocument &doc, bool authenticated, QObject *parent, std::function<void(QNetworkReply *)> callback) override; 0032 0033 QNetworkReply *upload(const QUrl &filename, std::function<void(QNetworkReply *)> callback) override; 0034 0035 void patch(const QUrl &url, QHttpMultiPart *multiPart, bool authenticated, QObject *parent, std::function<void(QNetworkReply *)>) override; 0036 0037 void deleteResource(const QUrl &url, bool authenticated, QObject *parent, std::function<void(QNetworkReply *)> callback) override; 0038 0039 void writeToSettings() override; 0040 0041 void buildFromSettings(const AccountConfig &settings) override; 0042 0043 void validateToken() override; 0044 0045 bool hasFollowRequests() const override; 0046 0047 void checkForFollowRequests() override; 0048 0049 void registerPost(const QString &url, QNetworkReply *reply); 0050 0051 void registerGet(const QUrl &url, QNetworkReply *reply); 0052 0053 void setFakeIdentity(const QJsonObject &object); 0054 void clearFakeIdentity(); 0055 0056 private: 0057 QHash<QUrl, QNetworkReply *> m_postReplies; 0058 QHash<QUrl, QNetworkReply *> m_getReplies; 0059 };