|
| 1 | +import business.tests.promocodes.base |
| 2 | +import rest_framework.status |
| 3 | + |
| 4 | + |
| 5 | +class TestSuccessfulPromoCreation( |
| 6 | + business.tests.promocodes.base.BasePromoCreateTestCase, |
| 7 | +): |
| 8 | + def test_successful_promo_creation_1(self): |
| 9 | + payload = { |
| 10 | + 'description': 'Increased cashback 10% for new bank clients!', |
| 11 | + 'image_url': 'https://cdn2.thecatapi.com/images/3lo.jpg', |
| 12 | + 'target': {}, |
| 13 | + 'max_count': 10, |
| 14 | + 'active_from': '2025-01-10', |
| 15 | + 'mode': 'COMMON', |
| 16 | + 'promo_common': 'sale-10', |
| 17 | + } |
| 18 | + response = self.client.post( |
| 19 | + self.promo_create_url, |
| 20 | + payload, |
| 21 | + format='json', |
| 22 | + HTTP_AUTHORIZATION='Bearer ' + self.token, |
| 23 | + ) |
| 24 | + self.assertEqual( |
| 25 | + response.status_code, |
| 26 | + rest_framework.status.HTTP_201_CREATED, |
| 27 | + ) |
| 28 | + |
| 29 | + def test_successful_promo_creation_2(self): |
| 30 | + payload = { |
| 31 | + 'description': 'Increased cashback 40% for new bank clients!', |
| 32 | + 'image_url': 'https://cdn2.thecatapi.com/images/3lo.jpg', |
| 33 | + 'target': {'age_from': 15, 'country': 'fr'}, |
| 34 | + 'max_count': 100, |
| 35 | + 'active_from': '2028-12-20', |
| 36 | + 'mode': 'COMMON', |
| 37 | + 'promo_common': 'sale-40', |
| 38 | + } |
| 39 | + response = self.client.post( |
| 40 | + self.promo_create_url, |
| 41 | + payload, |
| 42 | + format='json', |
| 43 | + HTTP_AUTHORIZATION='Bearer ' + self.token, |
| 44 | + ) |
| 45 | + self.assertEqual( |
| 46 | + response.status_code, |
| 47 | + rest_framework.status.HTTP_201_CREATED, |
| 48 | + ) |
| 49 | + |
| 50 | + def test_successful_promo_creation_3(self): |
| 51 | + payload = { |
| 52 | + 'description': 'Gift sleeping mask with car loan application', |
| 53 | + 'target': {'age_from': 28, 'age_until': 50, 'country': 'us'}, |
| 54 | + 'max_count': 1, |
| 55 | + 'active_from': '2025-01-01', |
| 56 | + 'active_until': '2028-12-30', |
| 57 | + 'mode': 'UNIQUE', |
| 58 | + 'promo_unique': ['uniq1', 'uniq2', 'uniq3'], |
| 59 | + } |
| 60 | + response = self.client.post( |
| 61 | + self.promo_create_url, |
| 62 | + payload, |
| 63 | + format='json', |
| 64 | + HTTP_AUTHORIZATION='Bearer ' + self.token, |
| 65 | + ) |
| 66 | + self.assertEqual( |
| 67 | + response.status_code, |
| 68 | + rest_framework.status.HTTP_201_CREATED, |
| 69 | + ) |
| 70 | + |
| 71 | + def test_successful_promo_creation_4(self): |
| 72 | + payload = { |
| 73 | + 'description': 'We gift a globe when ordering for 30000!', |
| 74 | + 'target': {'age_from': 28, 'age_until': 50, 'country': 'us'}, |
| 75 | + 'max_count': 1, |
| 76 | + 'active_until': '2025-01-10', |
| 77 | + 'mode': 'UNIQUE', |
| 78 | + 'promo_unique': ['only_youuuu', 'not_only_you'], |
| 79 | + } |
| 80 | + response = self.client.post( |
| 81 | + self.promo_create_url, |
| 82 | + payload, |
| 83 | + format='json', |
| 84 | + HTTP_AUTHORIZATION='Bearer ' + self.token, |
| 85 | + ) |
| 86 | + self.assertEqual( |
| 87 | + response.status_code, |
| 88 | + rest_framework.status.HTTP_201_CREATED, |
| 89 | + ) |
| 90 | + |
| 91 | + def test_successful_promo_creation_5(self): |
| 92 | + payload = { |
| 93 | + 'description': 'Increased cashback 10% for new bank clients!', |
| 94 | + 'image_url': 'http://cdn2.thecatapi.com/', |
| 95 | + 'target': {}, |
| 96 | + 'max_count': 10, |
| 97 | + 'active_from': '1950-01-01', |
| 98 | + 'mode': 'COMMON', |
| 99 | + 'promo_common': 'sale-10', |
| 100 | + } |
| 101 | + response = self.client.post( |
| 102 | + self.promo_create_url, |
| 103 | + payload, |
| 104 | + format='json', |
| 105 | + HTTP_AUTHORIZATION='Bearer ' + self.token, |
| 106 | + ) |
| 107 | + self.assertEqual( |
| 108 | + response.status_code, |
| 109 | + rest_framework.status.HTTP_201_CREATED, |
| 110 | + ) |
| 111 | + |
| 112 | + def test_successful_promo_creation_6_country_lower(self): |
| 113 | + payload = { |
| 114 | + 'description': 'Increased cashback 10% for new bank clients!', |
| 115 | + 'image_url': 'http://cdn2.thecatapi.com/', |
| 116 | + 'target': {'country': 'Us'}, |
| 117 | + 'max_count': 10, |
| 118 | + 'mode': 'COMMON', |
| 119 | + 'promo_common': 'sale-10', |
| 120 | + } |
| 121 | + response = self.client.post( |
| 122 | + self.promo_create_url, |
| 123 | + payload, |
| 124 | + format='json', |
| 125 | + HTTP_AUTHORIZATION='Bearer ' + self.token, |
| 126 | + ) |
| 127 | + self.assertEqual( |
| 128 | + response.status_code, |
| 129 | + rest_framework.status.HTTP_201_CREATED, |
| 130 | + ) |
| 131 | + |
| 132 | + def test_successful_promo_creation_6_country_upper(self): |
| 133 | + payload = { |
| 134 | + 'description': 'Increased cashback 10% for new bank clients!', |
| 135 | + 'image_url': 'http://cdn2.thecatapi.com/', |
| 136 | + 'target': {'country': 'US'}, |
| 137 | + 'max_count': 10, |
| 138 | + 'mode': 'COMMON', |
| 139 | + 'promo_common': 'sale-10', |
| 140 | + } |
| 141 | + response = self.client.post( |
| 142 | + self.promo_create_url, |
| 143 | + payload, |
| 144 | + format='json', |
| 145 | + HTTP_AUTHORIZATION='Bearer ' + self.token, |
| 146 | + ) |
| 147 | + self.assertEqual( |
| 148 | + response.status_code, |
| 149 | + rest_framework.status.HTTP_201_CREATED, |
| 150 | + ) |
| 151 | + |
| 152 | + def test_successful_promo_creation_7(self): |
| 153 | + payload = { |
| 154 | + 'description': 'Increased cashback 10% for new bank clients!', |
| 155 | + 'image_url': 'http://cdn2.thecatapi.com/', |
| 156 | + 'target': {'age_from': 100, 'age_until': 100}, |
| 157 | + 'max_count': 10, |
| 158 | + 'mode': 'COMMON', |
| 159 | + 'promo_common': 'sale-10', |
| 160 | + } |
| 161 | + response = self.client.post( |
| 162 | + self.promo_create_url, |
| 163 | + payload, |
| 164 | + format='json', |
| 165 | + HTTP_AUTHORIZATION='Bearer ' + self.token, |
| 166 | + ) |
| 167 | + self.assertEqual( |
| 168 | + response.status_code, |
| 169 | + rest_framework.status.HTTP_201_CREATED, |
| 170 | + ) |
0 commit comments