Merge lp:~alecu/unity-scope-click/show-purchaseable-flag into lp:unity-scope-click/devel

Proposed by Alejandro J. Cura
Status: Merged
Approved by: Alejandro J. Cura
Approved revision: 377
Merged at revision: 375
Proposed branch: lp:~alecu/unity-scope-click/show-purchaseable-flag
Merge into: lp:unity-scope-click/devel
Diff against target: 196 lines (+107/-0)
5 files modified
libclickscope/click/configuration.cpp (+9/-0)
libclickscope/click/configuration.h (+3/-0)
libclickscope/tests/test_configuration.cpp (+20/-0)
scope/clickstore/store-query.cpp (+4/-0)
scope/tests/test_query.cpp (+71/-0)
To merge this branch: bzr merge lp:~alecu/unity-scope-click/show-purchaseable-flag
Reviewer Review Type Date Requested Status
PS Jenkins bot (community) continuous-integration Approve
dobey (community) Approve
Diego Sarmentero (community) Approve
Review via email: mp+229108@code.launchpad.net

Commit message

Hide purchaseable apps behind an envvar flag

To post a comment you must log in.
Revision history for this message
Diego Sarmentero (diegosarmentero) wrote :

+1

review: Approve
376. By Alejandro J. Cura

Remove garbage left while devel

Revision history for this message
dobey (dobey) wrote :

58 + ASSERT_EQ(unsetenv(Configuration::PURCHASES_ENVVAR), 0);

You also need to add this line in the tests in tests_query.cpp where the environment variable is being set. As the tests are a single process, setting the environment, and not unsetting it at the end of each test where it is set, can bleed the value over to other tests.

review: Needs Fixing
377. By Alejandro J. Cura

Unset the environ variable to enable purchases in every test

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

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'libclickscope/click/configuration.cpp'
2--- libclickscope/click/configuration.cpp 2014-07-07 12:10:34 +0000
3+++ libclickscope/click/configuration.cpp 2014-07-31 19:37:19 +0000
4@@ -106,6 +106,15 @@
5 return arch;
6 }
7
8+bool Configuration::get_purchases_enabled()
9+{
10+ const char* env_value = std::getenv(PURCHASES_ENVVAR);
11+ if (env_value == NULL) {
12+ return PURCHASES_DEFAULT;
13+ }
14+ return std::string("1") == env_value;
15+}
16+
17 std::string Configuration::get_language_base()
18 {
19 std::string language = get_language();
20
21=== modified file 'libclickscope/click/configuration.h'
22--- libclickscope/click/configuration.h 2014-07-15 08:57:57 +0000
23+++ libclickscope/click/configuration.h 2014-07-31 19:37:19 +0000
24@@ -44,10 +44,13 @@
25 constexpr static const int FRAMEWORKS_EXTENSION_LENGTH = 10; // strlen(".framework")
26 constexpr static const char* ARCH_ENVVAR {"U1_SEARCH_ARCH"};
27 constexpr static const char* LANGUAGE_ENVVAR {"LANGUAGE"};
28+ constexpr static const char* PURCHASES_ENVVAR {"CLICK_STORE_ENABLE_PURCHASES"};
29+ constexpr static const bool PURCHASES_DEFAULT = false;
30 static const std::vector<const char*> FULL_LANG_CODES;
31
32 virtual std::vector<std::string> get_available_frameworks();
33 virtual std::string get_architecture();
34+ static bool get_purchases_enabled();
35
36 virtual std::string get_language_base();
37 virtual std::string get_language();
38
39=== modified file 'libclickscope/tests/test_configuration.cpp'
40--- libclickscope/tests/test_configuration.cpp 2014-07-07 12:10:34 +0000
41+++ libclickscope/tests/test_configuration.cpp 2014-07-31 19:37:19 +0000
42@@ -224,3 +224,23 @@
43 ASSERT_EQ(unsetenv(Configuration::ARCH_ENVVAR), 0);
44 ASSERT_NE("otherarch", Configuration().get_architecture());
45 }
46+
47+TEST(Configuration, getPurchasesEnabledOverrideTrue)
48+{
49+ ASSERT_EQ(setenv(Configuration::PURCHASES_ENVVAR, "1", 1), 0);
50+ EXPECT_EQ(true, Configuration().get_purchases_enabled());
51+ ASSERT_EQ(unsetenv(Configuration::PURCHASES_ENVVAR), 0);
52+}
53+
54+TEST(Configuration, getPurchasesEnabledOverrideFalse)
55+{
56+ ASSERT_EQ(setenv(Configuration::PURCHASES_ENVVAR, "0", 1), 0);
57+ EXPECT_EQ(false, Configuration().get_purchases_enabled());
58+ ASSERT_EQ(unsetenv(Configuration::PURCHASES_ENVVAR), 0);
59+}
60+
61+TEST(Configuration, getPurchasesEnabledDefault)
62+{
63+ ASSERT_EQ(unsetenv(Configuration::PURCHASES_ENVVAR), 0);
64+ ASSERT_EQ(false, Configuration().get_purchases_enabled());
65+}
66
67=== modified file 'scope/clickstore/store-query.cpp'
68--- scope/clickstore/store-query.cpp 2014-07-22 10:23:44 +0000
69+++ scope/clickstore/store-query.cpp 2014-07-31 19:37:19 +0000
70@@ -276,6 +276,10 @@
71
72 bool purchased = false;
73 if (pkg.price > 0.00f) {
74+ if (!Configuration::get_purchases_enabled()) {
75+ // Don't show priced apps if flag not set
76+ return;
77+ }
78 // Check if the priced app was already purchased.
79 purchased = impl->pay_package.verify(pkg.name);
80 }
81
82=== modified file 'scope/tests/test_query.cpp'
83--- scope/tests/test_query.cpp 2014-07-21 20:49:18 +0000
84+++ scope/tests/test_query.cpp 2014-07-31 19:37:19 +0000
85@@ -104,6 +104,7 @@
86 const std::string &icon,
87 const scopes::CategoryRenderer &renderer_template));
88 using click::Query::get_installed_packages; // allow tests to access protected method
89+ using click::Query::push_package;
90 };
91
92 class MockQueryRun : public MockQueryBase {
93@@ -358,6 +359,7 @@
94
95 TEST(QueryTest, testQueryRunCallsPayPackageVerify)
96 {
97+ ASSERT_EQ(setenv(Configuration::PURCHASES_ENVVAR, "1", 1), 0);
98 click::Packages packages {
99 {"name", "title", 0.99, "icon", "uri"}
100 };
101@@ -386,10 +388,12 @@
102 EXPECT_CALL(q, finished(_));
103
104 q.wrap_add_available_apps(reply, no_installed_packages, FAKE_CATEGORY_TEMPLATE);
105+ ASSERT_EQ(unsetenv(Configuration::PURCHASES_ENVVAR), 0);
106 }
107
108 TEST(QueryTest, testQueryRunPurchased)
109 {
110+ ASSERT_EQ(setenv(Configuration::PURCHASES_ENVVAR, "1", 1), 0);
111 click::Packages packages {
112 {"name", "title", 0.99, "icon", "uri"}
113 };
114@@ -419,10 +423,12 @@
115 EXPECT_CALL(q, finished(_));
116
117 q.wrap_add_available_apps(reply, no_installed_packages, FAKE_CATEGORY_TEMPLATE);
118+ ASSERT_EQ(unsetenv(Configuration::PURCHASES_ENVVAR), 0);
119 }
120
121 TEST(QueryTest, testQueryRunPurchasedAndInstalled)
122 {
123+ ASSERT_EQ(setenv(Configuration::PURCHASES_ENVVAR, "1", 1), 0);
124 click::Packages packages {
125 {"name", "title", 0.99, "icon", "uri"}
126 };
127@@ -454,4 +460,69 @@
128 EXPECT_CALL(q, finished(_));
129
130 q.wrap_add_available_apps(reply, one_installed_package, FAKE_CATEGORY_TEMPLATE);
131+ ASSERT_EQ(unsetenv(Configuration::PURCHASES_ENVVAR), 0);
132+}
133+
134+TEST(QueryTest, testPushPackageSkipsPricedApps)
135+{
136+ ASSERT_EQ(setenv(Configuration::PURCHASES_ENVVAR, "0", 1), 0);
137+
138+ click::Packages packages {
139+ {"org.example.app1", "app title1", 1.99, "icon", "uri"},
140+ {"org.example.app2", "app title2", 0.0, "icon", "uri"}
141+ };
142+ MockIndex mock_index(packages);
143+ scopes::SearchMetadata metadata("en_EN", "phone");
144+ PackageSet no_installed_packages;
145+ click::DepartmentLookup dept_lookup;
146+ click::HighlightList highlights;
147+ MockPayPackage pay_pkg;
148+ const unity::scopes::CannedQuery query("foo.scope", FAKE_QUERY, "");
149+ MockQuery q(query, mock_index, dept_lookup, nullptr, highlights, metadata, pay_pkg);
150+ EXPECT_CALL(mock_index, do_search(FAKE_QUERY, _));
151+
152+ scopes::CategoryRenderer renderer("{}");
153+ auto ptrCat = std::make_shared<FakeCategory>("id", "", "", renderer);
154+ EXPECT_CALL(q, register_category(_, _, _, _, _)).Times(2).WillRepeatedly(Return(ptrCat));
155+
156+ scopes::testing::MockSearchReply mock_reply;
157+ scopes::SearchReplyProxy reply(&mock_reply, [](unity::scopes::SearchReply*){});
158+ auto expected_name2 = packages.back().name;
159+ EXPECT_CALL(q, push_result(_, HasPackageName(expected_name2)));
160+ q.wrap_add_available_apps(reply, no_installed_packages, FAKE_CATEGORY_TEMPLATE);
161+
162+ ASSERT_EQ(unsetenv(Configuration::PURCHASES_ENVVAR), 0);
163+}
164+
165+TEST(QueryTest, testPushPackagePushesPricedApps)
166+{
167+ ASSERT_EQ(setenv(Configuration::PURCHASES_ENVVAR, "1", 1), 0);
168+
169+ click::Packages packages {
170+ {"org.example.app1", "app title1", 1.99, "icon", "uri"},
171+ {"org.example.app2", "app title2", 0.0, "icon", "uri"}
172+ };
173+ MockIndex mock_index(packages);
174+ scopes::SearchMetadata metadata("en_EN", "phone");
175+ PackageSet no_installed_packages;
176+ click::DepartmentLookup dept_lookup;
177+ click::HighlightList highlights;
178+ MockPayPackage pay_pkg;
179+ const unity::scopes::CannedQuery query("foo.scope", FAKE_QUERY, "");
180+ MockQuery q(query, mock_index, dept_lookup, nullptr, highlights, metadata, pay_pkg);
181+ EXPECT_CALL(mock_index, do_search(FAKE_QUERY, _));
182+
183+ scopes::CategoryRenderer renderer("{}");
184+ auto ptrCat = std::make_shared<FakeCategory>("id", "", "", renderer);
185+ EXPECT_CALL(q, register_category(_, _, _, _, _)).Times(2).WillRepeatedly(Return(ptrCat));
186+
187+ scopes::testing::MockSearchReply mock_reply;
188+ scopes::SearchReplyProxy reply(&mock_reply, [](unity::scopes::SearchReply*){});
189+ auto expected_name1 = packages.front().name;
190+ EXPECT_CALL(q, push_result(_, HasPackageName(expected_name1)));
191+ auto expected_name2 = packages.back().name;
192+ EXPECT_CALL(q, push_result(_, HasPackageName(expected_name2)));
193+ q.wrap_add_available_apps(reply, no_installed_packages, FAKE_CATEGORY_TEMPLATE);
194+
195+ ASSERT_EQ(unsetenv(Configuration::PURCHASES_ENVVAR), 0);
196 }

Subscribers

People subscribed via source and target branches

to all changes: