|
2 | 2 | import responses |
3 | 3 |
|
4 | 4 | from admitad.exceptions import HttpException |
5 | | -from admitad.items import PromoOffersForCampaign, PromoOfferRequestTrackingCode |
| 5 | +from admitad.items import PromoOffersForCampaign, PromoOfferRequestTrackingCode, PromoOffersRevocationStatus |
6 | 6 | from admitad.tests.base import BaseTestCase |
7 | 7 |
|
8 | 8 |
|
@@ -171,5 +171,113 @@ def test_get_tracking_promo_code_request_invalid_id(self) -> None: |
171 | 171 | self.client.PromoOfferRequestTrackingCode.get(request_id=0) |
172 | 172 |
|
173 | 173 |
|
| 174 | +class PromoOffersRevocationStatusTestCase(BaseTestCase): |
| 175 | + |
| 176 | + def test_get_promo_offers_revocation_status_success_multiple_codes(self) -> None: |
| 177 | + with responses.RequestsMock() as resp: |
| 178 | + resp.add( |
| 179 | + resp.GET, |
| 180 | + self.prepare_url(PromoOffersRevocationStatus.REVOCATION_STATUS_URL, pk=123, params={ |
| 181 | + 'website_id': 456 |
| 182 | + }), |
| 183 | + match_querystring=True, |
| 184 | + json=[ |
| 185 | + {"promocode_value": "SAVE20", "status": "active"}, |
| 186 | + {"promocode_value": "DISCOUNT15", "status": "revoked"}, |
| 187 | + {"promocode_value": "PROMO50", "status": "active"} |
| 188 | + ], |
| 189 | + status=200 |
| 190 | + ) |
| 191 | + result = self.client.PromoOffersRevocationStatus.get( |
| 192 | + _id=123, |
| 193 | + website_id=456 |
| 194 | + ) |
| 195 | + |
| 196 | + self.assertEqual(len(result), 3) |
| 197 | + self.assertEqual(result[0]['promocode_value'], 'SAVE20') |
| 198 | + self.assertEqual(result[0]['status'], 'active') |
| 199 | + self.assertEqual(result[1]['promocode_value'], 'DISCOUNT15') |
| 200 | + self.assertEqual(result[1]['status'], 'revoked') |
| 201 | + self.assertEqual(result[2]['promocode_value'], 'PROMO50') |
| 202 | + self.assertEqual(result[2]['status'], 'active') |
| 203 | + |
| 204 | + def test_get_promo_offers_revocation_status_empty_response(self) -> None: |
| 205 | + with responses.RequestsMock() as resp: |
| 206 | + resp.add( |
| 207 | + resp.GET, |
| 208 | + self.prepare_url(PromoOffersRevocationStatus.REVOCATION_STATUS_URL, pk=123, params={ |
| 209 | + 'website_id': 456 |
| 210 | + }), |
| 211 | + match_querystring=True, |
| 212 | + json=[], |
| 213 | + status=200 |
| 214 | + ) |
| 215 | + result = self.client.PromoOffersRevocationStatus.get( |
| 216 | + _id=123, |
| 217 | + website_id=456 |
| 218 | + ) |
| 219 | + |
| 220 | + self.assertEqual(result, []) |
| 221 | + |
| 222 | + def test_get_promo_offers_revocation_status_missing_website_id(self) -> None: |
| 223 | + with responses.RequestsMock() as resp: |
| 224 | + resp.add( |
| 225 | + resp.GET, |
| 226 | + self.prepare_url(PromoOffersRevocationStatus.REVOCATION_STATUS_URL, pk=123), |
| 227 | + json={"error": "Missing required parameter: website_id"}, |
| 228 | + status=400 |
| 229 | + ) |
| 230 | + with self.assertRaises(HttpException): |
| 231 | + self.client.PromoOffersRevocationStatus.get(_id=123) |
| 232 | + |
| 233 | + def test_get_promo_offers_revocation_status_invalid_website_id(self) -> None: |
| 234 | + with responses.RequestsMock() as resp: |
| 235 | + resp.add( |
| 236 | + resp.GET, |
| 237 | + self.prepare_url(PromoOffersRevocationStatus.REVOCATION_STATUS_URL, pk=123, params={ |
| 238 | + 'website_id': 'invalid' |
| 239 | + }), |
| 240 | + match_querystring=True, |
| 241 | + json={"error": "website_id must be an integer"}, |
| 242 | + status=400 |
| 243 | + ) |
| 244 | + with self.assertRaises(HttpException): |
| 245 | + self.client.PromoOffersRevocationStatus.get( |
| 246 | + _id=123, |
| 247 | + website_id='invalid' |
| 248 | + ) |
| 249 | + |
| 250 | + def test_get_promo_offers_revocation_status_offer_not_found(self) -> None: |
| 251 | + with responses.RequestsMock() as resp: |
| 252 | + resp.add( |
| 253 | + resp.GET, |
| 254 | + self.prepare_url(PromoOffersRevocationStatus.REVOCATION_STATUS_URL, pk=999, params={ |
| 255 | + 'website_id': 456 |
| 256 | + }), |
| 257 | + match_querystring=True, |
| 258 | + json={"error": "Promo offer not found or has no active promo codes"}, |
| 259 | + status=404 |
| 260 | + ) |
| 261 | + with self.assertRaises(HttpException): |
| 262 | + self.client.PromoOffersRevocationStatus.get( |
| 263 | + _id=999, |
| 264 | + website_id=456 |
| 265 | + ) |
| 266 | + |
| 267 | + def test_get_promo_offers_revocation_status_invalid_offer_id(self) -> None: |
| 268 | + with self.assertRaises(ValueError): |
| 269 | + self.client.PromoOffersRevocationStatus.get( |
| 270 | + _id=0, |
| 271 | + website_id=456 |
| 272 | + ) |
| 273 | + |
| 274 | + def test_get_promo_offers_revocation_status_invalid_website_id_zero(self) -> None: |
| 275 | + with self.assertRaises(ValueError): |
| 276 | + self.client.PromoOffersRevocationStatus.get( |
| 277 | + _id=123, |
| 278 | + website_id=0 |
| 279 | + ) |
| 280 | + |
| 281 | + |
174 | 282 | if __name__ == '__main__': |
175 | 283 | unittest.main() |
0 commit comments