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NjU2OTEzNzcwNjQ1MjI1NDIzKgAwAVAB"}' |
| 39 | +_GET_AD_SELECTION_DATA_SHELL_CMD_RESPONSE_FOR_SELLER_EMPTY = '{"output_proto":"Ei5QbGFjZWhvbGRlci1TaG91bGQtTWF0Y2gtV2l0aC1BcHAtUGFja2FnZS1OYW1lGAEiFC00NzU2\nMjI2NjQ2NTEwODU1MjUzKgAwAVAB\n"}' |
| 40 | +_GET_AD_SELECTION_DATA_SHELL_CMD_INVALID_PROTO_RESPONSE = '{"output_proto":"EvgBCngKCXdpbm5pbmdDQRIFc2hvZXMSIGJhLWJ1eWVyLTVqeXk1dWxhZ3EtdWMuYS5ydW4uYXBwEgRrZXkxEgRrZXkyGgExKgJ7fUIvY29tLmV4YW1wbGUuYWRzZXJ2aWNlcy5zYW1wbGVzLmZsZWRnZS5zYW1wbGVhcA=="}' |
38 | 41 |
|
39 | 42 |
|
40 | 43 | _GET_AD_SELECTION_DATA_EXPECTED_RESPONSE = json.loads( |
41 | 44 | '{"buyerInput":{"interestGroups":[{"name":"winningCA","biddingSignalsKeys":["shoes","ba-buyer-5jyy5ulagq-uc.a.run.app","key1","key2"],"adRenderIds":["1"],"userBiddingSignals":"{}","origin":"com.example.adservices.samples.fledge.sampleapp"},{"name":"shirts_server","biddingSignalsKeys":["shoes","ba-buyer-5jyy5ulagq-uc.a.run.app","key1","key2"],"adRenderIds":["2"],"userBiddingSignals":"{}","origin":"com.example.adservices.samples.fledge.sampleapp"}]},"auctionSignals":"{}","buyerSignals":"{}","seller":"Placeholder-Should-Match-With-Seller-Origin-Domain-In-SFE-Config","publisherName":"Placeholder-Should-Match-With-App-Package-Name","enableDebugReporting":true,"consentedDebugConfig":{"isConsented":true,"token":"1234567890"},"protectedAppSignalsBuyerInput":{"protectedAppSignals":{}},"clientType":"CLIENT_TYPE_ANDROID","topLevelSeller":"Placeholder-Should-Match-With-Top-Level-Seller-Origin-Domain-In-SFE-Config","buyerKvExperimentGroupId":0,"enableUnlimitedEgress":true}' |
42 | 45 | ) |
| 46 | +_GET_AD_SELECTION_DATA_EXPECTED_RESPONSE_FOR_SELLER = json.loads( |
| 47 | + '{"auction_config":{"seller_signals":"Replace-With-Seller-Signals","auction_signals":"Replace-With-Auction-Signals","buyer_list":["example.com"],"seller":"Replace-With-Seller","per_buyer_config":{"example.com":{"buyer_signals":"Replace-With-Buyer-Signals","auction_signals":"Replace-With-Auction-Signals"}}},"client_type":"CLIENT_TYPE_ANDROID","raw_protected_audience_input":{"raw_buyer_input":{"example.com":{"interest_groups":[{"name":"winningCA","origin":"com.example.adservices.samples.fledge.sampleapp","bidding_signals_keys":["shoes","example.com","key1","key2"],"ad_render_ids":["1"],"component_ads":[],"user_bidding_signals":"{}"},{"name":"shirts_server","origin":"com.example.adservices.samples.fledge.sampleapp","bidding_signals_keys":["shoes","example.com","key1","key2"],"ad_render_ids":["2"],"component_ads":[],"user_bidding_signals":"{}"}]}},"publisher_name":"Placeholder-Should-Match-With-App-Package-Name","enable_debug_reporting":true,"generation_id":"-5656913770645225423","consented_debug_config":{"is_consented":false,"token":"","is_debug_info_in_response":false}}}' |
| 48 | +) |
| 49 | +_GET_AD_SELECTION_DATA_EXPECTED_RESPONSE_FOR_SELLER_EMPTY = json.loads( |
| 50 | + '{"client_type":"CLIENT_TYPE_ANDROID","auction_config":{"seller_signals":"Replace-With-Seller-Signals","auction_signals":"Replace-With-Auction-Signals","buyer_list":[],"seller":"Replace-With-Seller","per_buyer_config":{}},"raw_protected_audience_input":{"raw_buyer_input":{},"publisher_name":"Placeholder-Should-Match-With-App-Package-Name","enable_debug_reporting":true,"generation_id":"-4756226646510855253","consented_debug_config":{"is_consented":false,"token":"","is_debug_info_in_response":false}}}' |
| 51 | +) |
43 | 52 |
|
44 | 53 | _GET_AD_SELECTION_DATA_SHELL_CMD_NO_DATA_RESPONSE = ( |
45 | 54 | "could not find data for buyer: test-buyer" |
@@ -154,6 +163,78 @@ def test_get_ad_selection_data_happy_path(self): |
154 | 163 | json_output = json.loads(output) |
155 | 164 | self.assertEqual(json_output, _GET_AD_SELECTION_DATA_EXPECTED_RESPONSE) |
156 | 165 |
|
| 166 | + def test_get_ad_selection_data_happy_path_for_seller(self): |
| 167 | + self.adb.set_shell_outputs( |
| 168 | + [_GET_AD_SELECTION_DATA_SHELL_CMD_RESPONSE_FOR_SELLER] |
| 169 | + ) |
| 170 | + |
| 171 | + output = self.ad_selection.get_ad_selection_data() |
| 172 | + |
| 173 | + self.assertContainsSubset( |
| 174 | + utilities.split_adb_command(ad_selection._COMMAND_PREFIX) |
| 175 | + + [ |
| 176 | + ad_selection._GET_AD_SELECTION_DATA_COMMAND, |
| 177 | + ], |
| 178 | + self.adb.shell_calls[0], |
| 179 | + ) |
| 180 | + print("output: ") |
| 181 | + print(output) |
| 182 | + json_output = json.loads(output) |
| 183 | + self.assertEqual( |
| 184 | + json_output, _GET_AD_SELECTION_DATA_EXPECTED_RESPONSE_FOR_SELLER |
| 185 | + ) |
| 186 | + |
| 187 | + def test_get_ad_selection_data_happy_path_for_seller_empty(self): |
| 188 | + self.adb.set_shell_outputs( |
| 189 | + [_GET_AD_SELECTION_DATA_SHELL_CMD_RESPONSE_FOR_SELLER_EMPTY] |
| 190 | + ) |
| 191 | + |
| 192 | + output = self.ad_selection.get_ad_selection_data() |
| 193 | + |
| 194 | + self.assertContainsSubset( |
| 195 | + utilities.split_adb_command(ad_selection._COMMAND_PREFIX) |
| 196 | + + [ |
| 197 | + ad_selection._GET_AD_SELECTION_DATA_COMMAND, |
| 198 | + ], |
| 199 | + self.adb.shell_calls[0], |
| 200 | + ) |
| 201 | + json_output = json.loads(output) |
| 202 | + self.assertEqual( |
| 203 | + json_output, _GET_AD_SELECTION_DATA_EXPECTED_RESPONSE_FOR_SELLER_EMPTY |
| 204 | + ) |
| 205 | + |
| 206 | + def test_get_ad_selection_data_invalid_proto(self): |
| 207 | + self.adb.set_shell_outputs( |
| 208 | + [_GET_AD_SELECTION_DATA_SHELL_CMD_INVALID_PROTO_RESPONSE] |
| 209 | + ) |
| 210 | + |
| 211 | + output = self.ad_selection.get_ad_selection_data(buyer="test-buyer") |
| 212 | + |
| 213 | + self.assertStartsWith(output, ad_selection._FAILURE_TEMPLATE % "") |
| 214 | + self.assertContainsSubset( |
| 215 | + utilities.split_adb_command(ad_selection._COMMAND_PREFIX) |
| 216 | + + [ |
| 217 | + ad_selection._GET_AD_SELECTION_DATA_COMMAND, |
| 218 | + ], |
| 219 | + self.adb.shell_calls[0], |
| 220 | + ) |
| 221 | + |
| 222 | + def test_get_ad_selection_data_invalid_proto_seller(self): |
| 223 | + self.adb.set_shell_outputs( |
| 224 | + [_GET_AD_SELECTION_DATA_SHELL_CMD_INVALID_PROTO_RESPONSE] |
| 225 | + ) |
| 226 | + |
| 227 | + output = self.ad_selection.get_ad_selection_data() |
| 228 | + |
| 229 | + self.assertStartsWith(output, ad_selection._FAILURE_TEMPLATE % "") |
| 230 | + self.assertContainsSubset( |
| 231 | + utilities.split_adb_command(ad_selection._COMMAND_PREFIX) |
| 232 | + + [ |
| 233 | + ad_selection._GET_AD_SELECTION_DATA_COMMAND, |
| 234 | + ], |
| 235 | + self.adb.shell_calls[0], |
| 236 | + ) |
| 237 | + |
157 | 238 | def test_get_ad_selection_data_no_data_for_buyer(self): |
158 | 239 | self.adb.set_shell_outputs( |
159 | 240 | [_GET_AD_SELECTION_DATA_SHELL_CMD_NO_DATA_RESPONSE] |
|
0 commit comments