kopia lustrzana https://github.com/ukhas/habitat-cpp-connector
Tolerate missing pcfgs; see habitat b6b492b3
rodzic
0c98dd02be
commit
a1d56d58cd
|
@ -290,14 +290,19 @@ vector<Json::Value> *Uploader::flights()
|
|||
|
||||
const Json::Value &key = row["key"], &doc = row["doc"];
|
||||
|
||||
if (!doc.isObject() || !key.isArray() || key.size() != 3 ||
|
||||
!key[2u].isIntegral())
|
||||
throw runtime_error("Invalid response: bad key or doc in row");
|
||||
bool doc_ok = doc.isObject() && doc.size();
|
||||
bool key_ok = key.isArray() && key.size() == 3 && key[2u].isIntegral();
|
||||
|
||||
if (!key_ok)
|
||||
throw runtime_error("Invalid response: bad key in row");
|
||||
|
||||
bool is_pcfg = key[2u].asBool();
|
||||
|
||||
if (!is_pcfg)
|
||||
{
|
||||
if (!doc_ok)
|
||||
throw runtime_error("Invalid response: bad doc in row");
|
||||
|
||||
result->push_back(doc);
|
||||
/* copies the doc */
|
||||
|
||||
|
@ -307,7 +312,8 @@ vector<Json::Value> *Uploader::flights()
|
|||
}
|
||||
else
|
||||
{
|
||||
current_pcfg_list->append(doc);
|
||||
if (doc_ok)
|
||||
current_pcfg_list->append(doc);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -749,6 +749,8 @@ class TestCPPConnector:
|
|||
for i in xrange(100):
|
||||
pcfgs.append({"_id": "pcfg_{0}".format(i),
|
||||
"type": "payload_configuration", "i": i})
|
||||
for i in xrange(20):
|
||||
pcfgs.append({"_id": "nonexistant_{0}".format(i)})
|
||||
for i in xrange(100):
|
||||
payloads = random.sample(pcfgs, random.randint(1, 5))
|
||||
doc = {"_id": "flight_{0}", "type": "flight", "i": i,
|
||||
|
@ -758,12 +760,22 @@ class TestCPPConnector:
|
|||
end = self.callbacks.fake_rfc3339(2000 + i)
|
||||
rows.append({"id": doc["_id"], "key": [end, start, 0],
|
||||
"value": None, "doc": doc})
|
||||
|
||||
expect_payloads = []
|
||||
for p in payloads:
|
||||
p_id = p["_id"]
|
||||
if "nonexistant" in p_id:
|
||||
# nonexistant referenced docs should not be in
|
||||
# _payload_docs
|
||||
p = None
|
||||
else:
|
||||
expect_payloads.append(p)
|
||||
|
||||
rows.append({"id": doc["_id"], "key": [end, start, 1],
|
||||
"value": {"_id": p["_id"]}, "doc": p})
|
||||
"value": {"_id": p_id}, "doc": p})
|
||||
|
||||
doc = copy.deepcopy(doc)
|
||||
doc["_payload_docs"] = payloads
|
||||
doc["_payload_docs"] = expect_payloads
|
||||
expect_result.append(doc)
|
||||
|
||||
fake_view_response = \
|
||||
|
|
Ładowanie…
Reference in New Issue