Skip to content

Commit 576480f

Browse files
committed
Merge pull request #2 from maxmind/greg/gift-inputs
Add new gift inputs
2 parents 7de84af + 4bd1b51 commit 576480f

File tree

5 files changed

+30
-16
lines changed

5 files changed

+30
-16
lines changed

HISTORY.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,12 @@
33
History
44
-------
55

6+
0.2.0 (2015-XX-XX)
7+
------------------
8+
9+
* Added `is_gift` and `has_gift_message` to `order` input dictionary
10+
validation.
11+
612
0.1.0 (2015-06-29)
713
++++++++++++++++++
814

minfraud/validation.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,8 @@ def _uri(s):
230230
'amount': _price,
231231
'currency': _currency_code,
232232
'discount_code': _unicode_or_printable_ascii,
233+
'has_gift_message': bool,
234+
'is_gift': bool,
233235
'referrer_uri': _uri,
234236
'subaffiliate_id': _unicode_or_printable_ascii,
235237
},

tests/data/full-request.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@
6060
"discount_code": "FIRST",
6161
"affiliate_id": "af12",
6262
"subaffiliate_id": "saf42",
63+
"is_gift": true,
64+
"has_gift_message": false,
6365
"referrer_uri": "http://www.amazon.com/"
6466
},
6567
"shopping_cart": [

tests/test_validation.py

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,12 @@ def check_positive_number(self, f):
4646
for bad in ('1.2', '1', -1, -1.1, 0):
4747
self.check_invalid_transaction(f(bad))
4848

49+
def check_bool(self, object, key):
50+
for good in (True, False):
51+
self.check_transaction({object: {key: good}})
52+
for bad in ('', 0, 'True'):
53+
self.check_invalid_transaction({object: {key: bad}})
54+
4955

5056
class TestAccount(unittest.TestCase, ValidationBase):
5157
def test_account_user_id(self):
@@ -160,7 +166,7 @@ def test_missing_device(self):
160166
def test_user_agent(self):
161167
self.check_str_type('device', 'user_agent')
162168

163-
def test_user_agent(self):
169+
def test_accept_language(self):
164170
self.check_str_type('device', 'accept_language')
165171

166172

@@ -219,6 +225,12 @@ def test_affiliate_id(self):
219225
def test_subaffiliate_id(self):
220226
self.check_str_type('order', 'subaffiliate_id')
221227

228+
def test_is_gift(self):
229+
self.check_bool('order', 'is_gift')
230+
231+
def test_has_gift_message(self):
232+
self.check_bool('order', 'has_gift_message')
233+
222234
def test_referrer_uri(self):
223235
for good in ('http://www.mm.com/fadsf', 'https://x.org/'):
224236
self.check_transaction({'order': {'referrer_uri': good}})
@@ -234,11 +246,7 @@ def test_processor(self):
234246
self.check_invalid_transaction({'payment': {'processor': bad}})
235247

236248
def test_was_authorized(self):
237-
for good in (True, False):
238-
self.check_transaction({'payment': {'was_authorized': good}})
239-
for bad in ('', 0, 'True'):
240-
self.check_invalid_transaction(
241-
{'payment': {'was_authorized': bad}})
249+
self.check_bool('payment', 'was_authorized')
242250

243251
def test_decline_code(self):
244252
self.check_str_type('payment', 'decline_code')
@@ -251,9 +259,6 @@ def test_category(self):
251259
def test_item_id(self):
252260
self.check_transaction({'shopping_cart': [{'item_id': 'cat'}]})
253261

254-
def test_item_id(self):
255-
self.check_transaction({'shopping_cart': [{'item_id': 'cat'}]})
256-
257262
def test_amount(self):
258263
self.check_positive_number(lambda v: {'shopping_cart': [{'price': v}]})
259264

tests/test_webservice.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -99,13 +99,11 @@ def test_400_with_no_body(self):
9999

100100
def test_400_with_unexpected_content_type(self):
101101
with self.assertRaisesRegex(
102-
HTTPError,
103-
"Received a 400 error but it did not include the expected JSON"
104-
" body: b?'?plain'?"):
102+
HTTPError, "Received a 400 with the following body: b?'?plain'?"):
105103
self.create_error(headers={'Content-Type': 'text/plain'},
106104
text='plain')
107105

108-
def test_400_with_unexpected_content_type(self):
106+
def test_400_without_json_body(self):
109107
with self.assertRaisesRegex(
110108
HTTPError,
111109
"Received a 400 error but it did not include the expected JSON"
@@ -147,9 +145,10 @@ def create_error(self, mock, status_code=400, text='', headers=None):
147145
def create_success(self, mock, text=None, headers=None, client=None):
148146
if headers is None:
149147
headers = {
150-
'Content-Type': 'application/vnd.maxmind.com-minfraud-{0}+json;'
151-
' charset=UTF-8; version=2.0'.format(
152-
self.type)
148+
'Content-Type':
149+
'application/vnd.maxmind.com-minfraud-{0}+json;'
150+
' charset=UTF-8; version=2.0'.format(
151+
self.type)
153152
}
154153
if text is None:
155154
text = self.response

0 commit comments

Comments
 (0)