mirror of
https://github.com/Gnucash/gnucash.git
synced 2025-02-25 18:55:30 -06:00
[price-quotes] Paramaterize GncMockQuoteSource construction.
So we can have different results passed back for different tests.
This commit is contained in:
parent
2b87066687
commit
d307295076
@ -47,11 +47,12 @@ class GncMockQuoteSource final : public GncQuoteSource
|
||||
{
|
||||
const std::string m_version{"9.99"};
|
||||
const StrVec m_sources{"currency", "yahoo_json"};
|
||||
const StrVec m_quotes{
|
||||
"{\"EUR\":{\"symbol\":\"EUR\",\"currency\":\"USD\",\"success\":\"1\",\"inverted\":0,\"last\":1.0004},\"AAPL\":{\"eps\":6.05,\"success\":1,\"year_range\":\" 129.04 - 182.94\",\"currency\":\"USD\",\"exchange\":\"Sourced from Yahoo Finance (as JSON)\",\"volume\":73539475,\"close\":157.22,\"high\":158.39,\"open\":156.64,\"div_yield\":0.5660857,\"last\":157.96,\"isodate\":\"2022-09-01\",\"method\":\"yahoo_json\",\"name\":\"AAPL (Apple Inc.)\",\"pe\":26.10909,\"low\":154.67,\"type\":\"EQUITY\",\"symbol\":\"AAPL\",\"date\":\"09/01/2022\"},\"HPE\":{\"symbol\":\"HPE\",\"date\":\"09/01/2022\",\"low\":13.13,\"type\":\"EQUITY\",\"method\":\"yahoo_json\",\"name\":\"HPE (Hewlett Packard Enterprise Comp)\",\"isodate\":\"2022-09-01\",\"pe\":4.7921147,\"last\":13.37,\"high\":13.535,\"close\":13.6,\"open\":13.5,\"div_yield\":3.5294116,\"volume\":16370483,\"exchange\":\"Sourced from Yahoo Finance (as JSON)\",\"currency\":\"USD\",\"year_range\":\" 12.4 - 17.76\",\"eps\":2.79,\"success\":1},\"FKCM\":{\"success\":0,\"symbol\":\"FKCM\",\"errormsg\":\"Error retrieving quote for FKCM - no listing for this name found. Please check symbol and the two letter extension (if any)\"}}"
|
||||
};
|
||||
const StrVec m_errors{};
|
||||
const StrVec m_quotes;
|
||||
const StrVec m_errors;
|
||||
public:
|
||||
GncMockQuoteSource(StrVec&& quotes, StrVec&& errors) :
|
||||
m_quotes{std::move(quotes)}, m_errors{std::move(errors)}{}
|
||||
~GncMockQuoteSource() override = default;
|
||||
virtual const std::string& get_version() const noexcept override { return m_version; }
|
||||
virtual const StrVec& get_sources() const noexcept override { return m_sources; }
|
||||
virtual QuoteResult get_quotes(const std::string&) const override;
|
||||
@ -145,7 +146,11 @@ TEST_F(GncQuotesTest, online_wiggle)
|
||||
|
||||
TEST_F(GncQuotesTest, offline_wiggle)
|
||||
{
|
||||
GncQuotesImpl quotes(m_book, std::make_unique<GncMockQuoteSource>());
|
||||
StrVec quote_vec{
|
||||
"{\"EUR\":{\"symbol\":\"EUR\",\"currency\":\"USD\",\"success\":\"1\",\"inverted\":0,\"last\":1.0004},\"AAPL\":{\"eps\":6.05,\"success\":1,\"year_range\":\" 129.04 - 182.94\",\"currency\":\"USD\",\"exchange\":\"Sourced from Yahoo Finance (as JSON)\",\"volume\":73539475,\"close\":157.22,\"high\":158.39,\"open\":156.64,\"div_yield\":0.5660857,\"last\":157.96,\"isodate\":\"2022-09-01\",\"method\":\"yahoo_json\",\"name\":\"AAPL (Apple Inc.)\",\"pe\":26.10909,\"low\":154.67,\"type\":\"EQUITY\",\"symbol\":\"AAPL\",\"date\":\"09/01/2022\"},\"HPE\":{\"symbol\":\"HPE\",\"date\":\"09/01/2022\",\"low\":13.13,\"type\":\"EQUITY\",\"method\":\"yahoo_json\",\"name\":\"HPE (Hewlett Packard Enterprise Comp)\",\"isodate\":\"2022-09-01\",\"pe\":4.7921147,\"last\":13.37,\"high\":13.535,\"close\":13.6,\"open\":13.5,\"div_yield\":3.5294116,\"volume\":16370483,\"exchange\":\"Sourced from Yahoo Finance (as JSON)\",\"currency\":\"USD\",\"year_range\":\" 12.4 - 17.76\",\"eps\":2.79,\"success\":1},\"FKCM\":{\"success\":0,\"symbol\":\"FKCM\",\"errormsg\":\"Error retrieving quote for FKCM - no listing for this name found. Please check symbol and the two letter extension (if any)\"}}"
|
||||
};
|
||||
StrVec err_vec;
|
||||
GncQuotesImpl quotes(m_book, std::make_unique<GncMockQuoteSource>(std::move(quote_vec), std::move(err_vec)));
|
||||
quotes.fetch(m_book);
|
||||
auto pricedb{gnc_pricedb_get_db(m_book)};
|
||||
EXPECT_EQ(3u, gnc_pricedb_get_num_prices(pricedb));
|
||||
|
Loading…
Reference in New Issue
Block a user