Skip to content

Commit 2babf1e

Browse files
authored
Merge pull request #30 from james-song/feature/issue-29
빌링키 추가, 조회 기능 구현
2 parents 21820bf + 75b54d5 commit 2babf1e

File tree

6 files changed

+56
-1
lines changed

6 files changed

+56
-1
lines changed

.gitignore

+5
Original file line numberDiff line numberDiff line change
@@ -105,3 +105,8 @@ atlassian-ide-plugin.xml
105105
com_crashlytics_export_strings.xml
106106
crashlytics.properties
107107
crashlytics-build.properties
108+
109+
.pytest_cache/
110+
.python-version
111+
venv/
112+

iamport/client.py

+12
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,18 @@ def pay_again(self, **kwargs):
9595

9696
return self._post(url, kwargs)
9797

98+
def customer_create(self, **kwargs):
99+
customer_uid = kwargs.get('customer_uid')
100+
for key in ['customer_uid', 'card_number', 'expiry', 'birth']:
101+
if key not in kwargs:
102+
raise KeyError('Essential parameter is missing!: %s' % key)
103+
url = '{}subscribe/customers/{}'.format(self.imp_url, customer_uid)
104+
return self._post(url, kwargs)
105+
106+
def customer_get(self, customer_uid):
107+
url = '{}subscribe/customers/{}'.format(self.imp_url, customer_uid)
108+
return self._get(url)
109+
98110
def pay_foreign(self, **kwargs):
99111
url = '{}subscribe/payments/foreign'.format(self.imp_url)
100112
for key in ['merchant_uid', 'amount', 'card_number', 'expiry']:

tests/test_customer_create.py

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# -*- coding: utf-8 -*-
2+
import pytest
3+
4+
5+
def test_customer_create(iamport):
6+
# Without 'card_number'
7+
payload_notEnough = {
8+
'customer_uid': 'customer_1234',
9+
'expiry': '2019-03',
10+
'birth': '500203',
11+
}
12+
13+
with pytest.raises(KeyError) as e:
14+
iamport.customer_create(**payload_notEnough)
15+
assert "Essential parameter is missing!: card_number" in str(e)
16+
17+
payload_full = {
18+
'customer_uid': 'customer_1234',
19+
'expiry': '2019-03',
20+
'birth': '500203',
21+
'card_number': '4092-0230-1234-1234',
22+
}
23+
24+
with pytest.raises(iamport.ResponseError) as e:
25+
iamport.customer_create(**payload_full)
26+
assert e.code == -1
27+
assert u'카드정보 인증 및 빌키 발급에 실패하였습니다.' in e.message

tests/test_customer_get.py

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# -*- coding: utf-8 -*-
2+
import pytest
3+
4+
5+
def test_customer_get(iamport):
6+
customer_uid = '000000'
7+
with pytest.raises(iamport.ResponseError) as e:
8+
iamport.customer_get(customer_uid)
9+
assert u'요청하신 customer_uid(000000)로 등록된 정보를 찾을 수 없습니다.' == e.message
10+

tests/test_is_paid.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ def test_is_paid_with_response(iamport):
66
'status': 'paid',
77
'amount': 1000,
88
}
9-
assert True is iamport.is_paid(amount=1000, resposne=mocked_response, merchant_uid='test')
9+
assert True is iamport.is_paid(amount=1000, response=mocked_response, merchant_uid='test')
1010

1111

1212
def test_is_paid_without_response(iamport):

tox.ini

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ envlist = py27, py34, py35, py36, pypy
44
[testenv]
55
passenv = CI TRAVIS TRAVIS_*
66
deps =
7+
pytest-runner
78
pytest
89
flake8
910
collective.checkdocs

0 commit comments

Comments
 (0)