20#include <boost/test/unit_test.hpp>
33static const
std::
string RootUrl =
"http://fake.test/v1/";
76 BOOST_CHECK( conn.
GetLastError().find(
"empty response" ) != std::string::npos );
88 BOOST_CHECK( conn.
GetLastError().find(
"error code" ) != std::string::npos );
108 [](
const std::string&,
int& aStatusCode, std::string&, std::string& aError )
111 aError =
"connection refused";
115 BOOST_CHECK( !conn.IsValidEndpoint() );
128 std::vector<HTTP_LIB_PART> parts;
130 BOOST_CHECK( conn.
SelectAll( category, parts ) );
131 BOOST_REQUIRE_EQUAL( parts.size(), 2u );
133 BOOST_CHECK( !parts[0].detailsLoaded );
136 std::string categoryId;
150 BOOST_CHECK( conn.
SelectOne(
"res-10k", part ) );
154 bool foundFootprint =
false;
156 for(
const auto& [
name, properties] : part.
fields )
158 if(
name ==
"footprint" )
160 foundFootprint =
true;
161 BOOST_CHECK_EQUAL( std::get<0>( properties ),
"Resistor_SMD:R_0603_1608Metric" );
165 BOOST_CHECK( foundFootprint );
168 BOOST_CHECK( conn.
SelectOne(
"res-10k", part ) );
185 BOOST_CHECK( conn.
SelectOne(
"res-10k", part ) );
186 BOOST_CHECK( conn.
SelectOne(
"res-10k", part ) );
201 BOOST_CHECK( !conn.
SelectOne(
"missing", part ) );
202 BOOST_CHECK( conn.
GetLastError().find(
"404" ) != std::string::npos );
217 std::vector<HTTP_LIB_PART> parts;
218 BOOST_CHECK( !conn.
SelectAll( category, parts ) );
234 BOOST_CHECK( conn.
SelectOne(
"res-10k", part ) );
238 BOOST_CHECK( conn.
SelectOne(
"res-10k", part ) );
242 std::this_thread::sleep_for( std::chrono::milliseconds( 1100 ) );
244 BOOST_CHECK( conn.
SelectOne(
"res-10k", part ) );
bool GetCachedPartRelation(const std::string &aPartName, std::string &aPartId, std::string &aCategoryId) const
Resolve a cached part name to its part ID and category ID.
std::vector< HTTP_LIB_CATEGORY > getCategories() const
bool SelectAll(const HTTP_LIB_CATEGORY &aCategory, std::vector< HTTP_LIB_PART > &aParts)
Retrieve all parts from a specific category from the HTTP library.
bool IsValidEndpoint() const
bool SelectOne(const std::string &aPartID, HTTP_LIB_PART &aFetchedPart)
Retrieve a single part with full details from the HTTP library.
std::string GetLastError() const
std::string getCategoryDescription(const std::string &aCategoryName) const
In-process HTTP library server used by QA tests.
int RequestCount(const std::string &aUrl) const
Number of times aUrl has been requested.
void InstallStandardLibrary(const std::string &aRootUrl)
void SetResponse(const std::string &aUrl, RESPONSE aResponse)
Replace the response served for an exact URL.
HTTP_LIB_CONNECTION::RETRIEVER MakeRetriever()
std::string id
id of category
std::vector< std::pair< std::string, field_type > > fields
Connection parameters for one HTTP library.
HTTP_LIB_SOURCE_TYPE type
BOOST_AUTO_TEST_SUITE(CadstarPartParser)
BOOST_AUTO_TEST_SUITE_END()
static HTTP_LIB_CONNECTION connectToStandardLibrary(HTTP_LIB_FAKE_SERVER &aServer)
BOOST_AUTO_TEST_CASE(ValidEndpointSyncsCategories)
static HTTP_LIB_SOURCE makeTestSource()
static const std::string RootUrl
BOOST_CHECK_EQUAL(result, "25.4")