Merge lp:~dobey/unity-scope-click/review-crash into lp:unity-scope-click

Proposed by dobey
Status: Merged
Approved by: Paweł Stołowski
Approved revision: 405
Merged at revision: 405
Proposed branch: lp:~dobey/unity-scope-click/review-crash
Merge into: lp:unity-scope-click
Diff against target: 96 lines (+37/-2)
4 files modified
libclickscope/click/reviews.cpp (+7/-2)
libclickscope/click/webclient.cpp (+5/-0)
libclickscope/click/webclient.h (+1/-0)
libclickscope/tests/test_reviews.cpp (+24/-0)
To merge this branch: bzr merge lp:~dobey/unity-scope-click/review-crash
Reviewer Review Type Date Requested Status
PS Jenkins bot continuous-integration Needs Fixing
Paweł Stołowski (community) Approve
Review via email: mp+283544@code.launchpad.net

Commit message

Only try to parse the JSON when we get a 200.

To post a comment you must log in.
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
Paweł Stołowski (stolowski) wrote :

+ qCritical() << "Status:" << status;

Should use qDebug(), no need to spam our logs with criticals on every reply.

Otherwise looking good.

review: Needs Fixing
405. By dobey

Remove the leftover debug log message.

Revision history for this message
Paweł Stołowski (stolowski) wrote :

Looks good, thanks!

review: Approve
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'libclickscope/click/reviews.cpp'
2--- libclickscope/click/reviews.cpp 2015-11-24 18:23:23 +0000
3+++ libclickscope/click/reviews.cpp 2016-01-27 18:26:06 +0000
4@@ -135,9 +135,14 @@
5
6 QObject::connect(response.data(), &click::web::Response::finished,
7 [=](QString reply) {
8+ auto status = response->get_status_code();
9 click::ReviewList reviews;
10- reviews = review_list_from_json(reply.toUtf8().constData());
11- callback(reviews, click::Reviews::Error::NoError);
12+ if (status == 200) {
13+ reviews = review_list_from_json(reply.toUtf8().constData());
14+ callback(reviews, click::Reviews::Error::NoError);
15+ } else {
16+ callback(reviews, click::Reviews::Error::NetworkError);
17+ }
18 });
19 QObject::connect(response.data(), &click::web::Response::error,
20 [=](QString) {
21
22=== modified file 'libclickscope/click/webclient.cpp'
23--- libclickscope/click/webclient.cpp 2015-11-24 19:14:11 +0000
24+++ libclickscope/click/webclient.cpp 2016-01-27 18:26:06 +0000
25@@ -183,6 +183,11 @@
26 return reply->rawHeader(header.c_str()).toUtf8().data();
27 }
28
29+int click::web::Response::get_status_code() const
30+{
31+ return reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt();
32+}
33+
34 void click::web::Response::replyFinished()
35 {
36 auto response = reply->readAll();
37
38=== modified file 'libclickscope/click/webclient.h'
39--- libclickscope/click/webclient.h 2015-11-24 19:14:11 +0000
40+++ libclickscope/click/webclient.h 2016-01-27 18:26:06 +0000
41@@ -81,6 +81,7 @@
42
43 virtual bool has_header(const std::string& header) const;
44 virtual std::string get_header(const std::string& header) const;
45+ virtual int get_status_code() const;
46
47 public slots:
48 void replyFinished();
49
50=== modified file 'libclickscope/tests/test_reviews.cpp'
51--- libclickscope/tests/test_reviews.cpp 2015-11-24 18:23:23 +0000
52+++ libclickscope/tests/test_reviews.cpp 2016-01-27 18:26:06 +0000
53@@ -200,12 +200,35 @@
54 response->replyFinished();
55 }
56
57+TEST_F(ReviewsTest, testFetchReviewsNot200)
58+{
59+ LifetimeHelper<click::network::Reply, MockNetworkReply> reply;
60+ auto response = responseForReply(reply.asSharedPtr());
61+
62+ EXPECT_CALL(reply.instance, attribute(_)).WillOnce(Return(QVariant(301)));
63+ EXPECT_CALL(reply.instance, readAll())
64+ .Times(1)
65+ .WillOnce(Return(FAKE_JSON_REVIEWS_RESULT_ONE.c_str()));
66+ EXPECT_CALL(*clientPtr, callImpl(_, _, _, _, _, _))
67+ .Times(1)
68+ .WillOnce(Return(response));
69+ click::ReviewList empty_reviews_list;
70+ EXPECT_CALL(*this, reviews_callback(empty_reviews_list, _)).Times(1);
71+
72+ reviewsPtr->fetch_reviews("", [this](click::ReviewList reviews,
73+ click::Reviews::Error error){
74+ reviews_callback(reviews, error);
75+ });
76+ response->replyFinished();
77+}
78+
79 TEST_F(ReviewsTest, testFetchReviewsEmptyJsonIsParsed)
80 {
81 LifetimeHelper<click::network::Reply, MockNetworkReply> reply;
82 auto response = responseForReply(reply.asSharedPtr());
83
84 QByteArray fake_json("[]");
85+ EXPECT_CALL(reply.instance, attribute(_)).WillOnce(Return(QVariant(200)));
86 EXPECT_CALL(reply.instance, readAll())
87 .Times(1)
88 .WillOnce(Return(fake_json));
89@@ -228,6 +251,7 @@
90 auto response = responseForReply(reply.asSharedPtr());
91
92 QByteArray fake_json(FAKE_JSON_REVIEWS_RESULT_ONE.c_str());
93+ EXPECT_CALL(reply.instance, attribute(_)).WillOnce(Return(QVariant(200)));
94 EXPECT_CALL(reply.instance, readAll())
95 .Times(1)
96 .WillOnce(Return(fake_json));

Subscribers

People subscribed via source and target branches

to all changes: