From ae82030fe9808c9b7c9d1d9750220f3d5c48957a Mon Sep 17 00:00:00 2001 From: Arsentiy Milchakov Date: Mon, 27 Feb 2017 13:54:17 +0300 Subject: [PATCH] booking tests to internal server --- partners_api/booking_api.cpp | 29 ++++++++++--------- partners_api/booking_api.hpp | 10 ++----- .../partners_api_tests/booking_tests.cpp | 13 +++++---- 3 files changed, 26 insertions(+), 26 deletions(-) diff --git a/partners_api/booking_api.cpp b/partners_api/booking_api.cpp index 18e7f62fe2..15a4e4e41c 100644 --- a/partners_api/booking_api.cpp +++ b/partners_api/booking_api.cpp @@ -26,6 +26,7 @@ string const kBookingApiBaseUrl = "https://distribution-xml.booking.com/json/boo string const kExtendedHotelInfoBaseUrl = "http://hotels.milchakov.map6.devmail.ru/getDescription"; string const kPhotoOriginalUrl = "http://aff.bstatic.com/images/hotel/max500/"; string const kPhotoSmallUrl = "http://aff.bstatic.com/images/hotel/max300/"; +string g_BookingUrlForTesting = ""; bool RunSimpleHttpRequest(bool const needAuth, string const & url, string & result) { @@ -42,13 +43,15 @@ bool RunSimpleHttpRequest(bool const needAuth, string const & url, string & resu return false; } -string MakeApiUrl(string const & func, initializer_list> const & params, - bool testing) +string MakeApiUrl(string const & func, initializer_list> const & params) { ASSERT_NOT_EQUAL(params.size(), 0, ()); ostringstream os; - os << kBookingApiBaseUrl << "." << func << "?"; + if (!g_BookingUrlForTesting.empty()) + os << g_BookingUrlForTesting << "." << func << "?"; + else + os << kBookingApiBaseUrl << "." << func << "?"; bool firstParam = true; for (auto const & param : params) @@ -64,9 +67,6 @@ string MakeApiUrl(string const & func, initializer_list> co os << param.first << "=" << param.second; } - if (testing) - os << "&show_test=1"; - return os.str(); } @@ -237,8 +237,7 @@ void FillPriceAndCurrency(string const & src, string const & currency, string & namespace booking { // static -bool RawApi::GetHotelAvailability(string const & hotelId, string const & currency, string & result, - bool testing /* = false */) +bool RawApi::GetHotelAvailability(string const & hotelId, string const & currency, string & result) { char dateArrival[12]{}; char dateDeparture[12]{}; @@ -252,8 +251,7 @@ bool RawApi::GetHotelAvailability(string const & hotelId, string const & currenc string url = MakeApiUrl("getHotelAvailability", {{"hotel_ids", hotelId}, {"currency_code", currency}, {"arrival_date", dateArrival}, - {"departure_date", dateDeparture}}, - testing); + {"departure_date", dateDeparture}}); return RunSimpleHttpRequest(true, url, result); } @@ -278,14 +276,12 @@ string Api::GetDescriptionUrl(string const & baseUrl) const void Api::GetMinPrice(string const & hotelId, string const & currency, GetMinPriceCallback const & fn) { - auto const testingMode = m_testingMode; - - threads::SimpleThread([hotelId, currency, fn, testingMode]() + threads::SimpleThread([hotelId, currency, fn]() { string minPrice; string priceCurrency; string httpResult; - if (!RawApi::GetHotelAvailability(hotelId, currency, httpResult, testingMode)) + if (!RawApi::GetHotelAvailability(hotelId, currency, httpResult)) { fn(hotelId, minPrice, priceCurrency); return; @@ -332,4 +328,9 @@ void Api::GetHotelInfo(string const & hotelId, string const & lang, GetHotelInfo fn(info); }).detach(); } + +void SetBookingUrlForTesting(string const & url) +{ + g_BookingUrlForTesting = url; +} } // namespace booking diff --git a/partners_api/booking_api.hpp b/partners_api/booking_api.hpp index e0ddfdd587..2b2885b914 100644 --- a/partners_api/booking_api.hpp +++ b/partners_api/booking_api.hpp @@ -48,8 +48,7 @@ struct HotelInfo class RawApi { public: - static bool GetHotelAvailability(string const & hotelId, string const & currency, string & result, - bool testing = false); + static bool GetHotelAvailability(string const & hotelId, string const & currency, string & result); static bool GetExtendedInfo(string const & hotelId, string const & lang, string & result); }; @@ -59,8 +58,6 @@ using GetHotelInfoCallback = function; class Api { public: - void SetTestingMode(bool testing) { m_testingMode = testing; } - string GetBookHotelUrl(string const & baseUrl) const; string GetDescriptionUrl(string const & baseUrl) const; // Real-time information methods (used for retriving rapidly changing information). @@ -70,8 +67,7 @@ public: // Static information methods (use for information that can be cached). // These methods use caching server to prevent Booking from being ddossed. void GetHotelInfo(string const & hotelId, string const & lang, GetHotelInfoCallback const & fn); - -private: - bool m_testingMode = false; }; + +void SetBookingUrlForTesting(string const & url); } // namespace booking diff --git a/partners_api/partners_api_tests/booking_tests.cpp b/partners_api/partners_api_tests/booking_tests.cpp index 5ade4f9d07..d8b2d41884 100644 --- a/partners_api/partners_api_tests/booking_tests.cpp +++ b/partners_api/partners_api_tests/booking_tests.cpp @@ -2,14 +2,15 @@ #include "partners_api/booking_api.hpp" +#include "base/scope_guard.hpp" + namespace { -string const kHotelId = "98251"; // Special hotel id for testing. - UNIT_TEST(Booking_GetHotelAvailability) { + string const kHotelId = "98251"; // Booking hotel id for testing. string result; - TEST(booking::RawApi::GetHotelAvailability(kHotelId, "", result, true), ()); + TEST(booking::RawApi::GetHotelAvailability(kHotelId, "", result), ()); TEST(!result.empty(), ()); } @@ -23,9 +24,11 @@ UNIT_TEST(Booking_GetExtendedInfo) UNIT_TEST(Booking_GetMinPrice) { - booking::Api api; - api.SetTestingMode(true); + booking::SetBookingUrlForTesting("http://localhost:34568/booking/min_price"); + MY_SCOPE_GUARD(cleanup, []() { booking::SetBookingUrlForTesting(""); }); + string const kHotelId = "0000000"; // Internal hotel id for testing. + booking::Api api; { string price; string currency;