Skip to content

Commit 769bd36

Browse files
authored
Merge pull request #48 from jha929/feature/workflows
깃헙 액션을 이용한 자동화 테스트 파이프라인 구현
2 parents 80c7474 + 39b90b1 commit 769bd36

File tree

9 files changed

+97
-28
lines changed

9 files changed

+97
-28
lines changed

.github/workflows/build.yml

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
name: Build Status
2+
3+
on: [push, pull_request]
4+
5+
jobs:
6+
build-ubuntu:
7+
name: Build Test
8+
runs-on: ubuntu-latest
9+
strategy:
10+
matrix:
11+
python-version: [3.6, 3.7, 3.8, 3.9]
12+
steps:
13+
- uses: actions/checkout@v2
14+
- name: Set up Python ${{ matrix.python-version }}
15+
uses: actions/setup-python@v2
16+
with:
17+
python-version: ${{ matrix.python-version }}
18+
- name: Install dependencies
19+
run: |
20+
python -m pip install --upgrade pip
21+
pip install -r requirements.txt
22+
- name: Run unit tests
23+
run: |
24+
python -m pytest --cov=iamport tests
25+
- name: Comment on coverage
26+
uses: coroo/[email protected]
27+
with:
28+
pytest-coverage: .coverage
29+
- name: Run convention tests
30+
run: |
31+
python -m flake8 iamport tests --ignore E203,W503,W504
32+
- name: Run type check
33+
run: |
34+
python -m mypy iamport
35+
- name: Run import sort check
36+
run: |
37+
python -m isort iamport tests --diff

iamport/client.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# -*- coding: utf-8 -*-
22

33
import json
4+
45
import requests
56

67
__all__ = ['IAMPORT_API_URL', 'Iamport']
@@ -39,9 +40,13 @@ def get_response(response):
3940

4041
def _get_token(self):
4142
url = '{}users/getToken'.format(self.imp_url)
42-
payload = {'imp_key': self.imp_key,
43-
'imp_secret': self.imp_secret}
44-
response = self.requests_session.post(url, headers={'Content-Type': 'application/json'}, data=json.dumps(payload))
43+
payload = {
44+
'imp_key': self.imp_key,
45+
'imp_secret': self.imp_secret
46+
}
47+
response = self.requests_session.post(
48+
url, headers={'Content-Type': 'application/json'}, data=json.dumps(payload)
49+
)
4550
return self.get_response(response).get('access_token')
4651

4752
def get_headers(self):
@@ -57,7 +62,7 @@ def _post(self, url, payload=None):
5762
headers['Content-Type'] = 'application/json'
5863
response = self.requests_session.post(url, headers=headers, data=json.dumps(payload))
5964
return self.get_response(response)
60-
65+
6166
def _delete(self, url):
6267
headers = self.get_headers()
6368
response = self.requests_session.delete(url, headers=headers)
@@ -197,7 +202,7 @@ def prepare_validate(self, merchant_uid, amount):
197202
response = self._get(url)
198203
response_amount = response.get('amount')
199204
return response_amount == amount
200-
205+
201206
def revoke_vbank_by_imp_uid(self, imp_uid):
202207
url = '{}vbanks/{}'.format(self.imp_url, imp_uid)
203208
return self._delete(url)

iamport/client.pyi

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,10 +67,10 @@ class Iamport(object):
6767

6868
def prepare_validate(self, merchant_uid: str, amount: Amount) -> Dict: ...
6969

70-
def revoke_vbank_by_imp_uid(self, imp_uid: str): -> Dict: ...
70+
def revoke_vbank_by_imp_uid(self, imp_uid: str) -> Dict: ...
7171

72-
def certification_by_imp_uid(self, imp_uid: str): -> Dict: ...
72+
def certification_by_imp_uid(self, imp_uid: str) -> Dict: ...
7373

74-
def find_certification(self, imp_uid: str): -> Dict: ...
74+
def find_certification(self, imp_uid: str) -> Dict: ...
7575

76-
def cancel_certification(self, imp_uid: str): -> Dict: ...
76+
def cancel_certification(self, imp_uid: str) -> Dict: ...

requirements.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
requests==2.26.0
2+
pytest==6.2.4
3+
pytest-cov==2.12.1
4+
flake8==3.9.2
5+
isort==5.9.3
6+
mypy==0.910
7+
types-requests==2.25.6

tests/conftest.py

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,25 @@
44
from iamport import Iamport
55

66
DEFAULT_TEST_IMP_KEY = 'imp_apikey'
7-
DEFAULT_TEST_IMP_SECRET = ('ekKoeW8RyKuT0zgaZsUtXXTLQ4AhPFW3ZGseDA6bkA5lamv9O'
8-
'qDMnxyeB9wqOsuO9W3Mx9YSJ4dTqJ3f')
7+
DEFAULT_TEST_IMP_SECRET = (
8+
'ekKoeW8RyKuT0zgaZsUtXXTLQ4AhPFW3ZGseDA6b'
9+
'kA5lamv9OqDMnxyeB9wqOsuO9W3Mx9YSJ4dTqJ3f'
10+
)
911

1012

1113
def pytest_addoption(parser):
12-
parser.addoption('--imp-key', default=DEFAULT_TEST_IMP_KEY,
13-
help='iamport client key for testing '
14-
'[default: %default]')
15-
parser.addoption('--imp-secret', default=DEFAULT_TEST_IMP_SECRET,
16-
help='iamport secret key for testing '
17-
'[default: %default]')
14+
parser.addoption(
15+
'--imp-key',
16+
default=DEFAULT_TEST_IMP_KEY,
17+
help='iamport client key for testing '
18+
'[default: %(default)s]'
19+
)
20+
parser.addoption(
21+
'--imp-secret',
22+
default=DEFAULT_TEST_IMP_SECRET,
23+
help='iamport secret key for testing '
24+
'[default: %(default)s]'
25+
)
1826

1927

2028
@fixture

tests/test_certification.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,4 @@ def test_find_certification(iamport):
1111

1212
with pytest.raises(iamport.HttpError) as e:
1313
iamport.cancel_certification(imp_uid)
14-
assert u'인증결과가 존재하지 않습니다.' == e.message
15-
14+
assert u'인증결과가 존재하지 않습니다.' == e.message

tests/test_customer_get.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,3 @@ def test_customer_get(iamport):
77
with pytest.raises(iamport.ResponseError) as e:
88
iamport.customer_get(customer_uid)
99
assert u'요청하신 customer_uid(000000)로 등록된 정보를 찾을 수 없습니다.' == e.message
10-

tests/test_pay_onetime.py

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,35 @@
11
# -*- coding: utf-8 -*-
2+
import random
3+
import string
24

35

46
def test_pay_onetime(iamport):
7+
merchant_uid = ''.join(
8+
random.choice(string.ascii_uppercase + string.digits)
9+
for _ in range(10)
10+
)
11+
512
# Without 'card_number'
6-
payload_notEnough = {
7-
'merchant_uid': 'qwer1234',
13+
payload_not_enough = {
14+
'merchant_uid': merchant_uid,
815
'amount': 5000,
916
'expiry': '2019-03',
1017
'birth': '500203',
1118
'pwd_2digit': '19'
1219
}
1320

1421
try:
15-
iamport.pay_onetime(**payload_notEnough)
22+
iamport.pay_onetime(**payload_not_enough)
1623
except KeyError as e:
1724
assert "Essential parameter is missing!: card_number" in str(e)
1825

26+
merchant_uid = ''.join(
27+
random.choice(string.ascii_uppercase + string.digits)
28+
for _ in range(10)
29+
)
30+
1931
payload_full = {
20-
'merchant_uid': 'qwer1234',
32+
'merchant_uid': merchant_uid,
2133
'amount': 5000,
2234
'card_number': '4092-0230-1234-1234',
2335
'expiry': '2019-03',

tests/test_prepare.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
# -*- coding: utf-8 -*-
2-
import datetime
3-
import time
2+
import random
3+
import string
44

55

66
def test_prepare(iamport):
77
amount = 12000
8-
mid = 'merchant_%d' % time.mktime(datetime.datetime.now().timetuple())
9-
8+
mid = ''.join(
9+
random.choice(string.ascii_uppercase + string.digits)
10+
for _ in range(10)
11+
)
1012
result = iamport.prepare(merchant_uid=mid, amount=amount)
1113
assert result['amount'] == amount
1214
assert result['merchant_uid'] == mid

0 commit comments

Comments
 (0)