2. 발표자 소개
• 한종원
• Python과 Cloud Infra, Lean/Agile 방법론 그리고 애플의 제품을 사랑.
• 2012년 석사 학위를 마치고, startup을 시작
(이때부터 Python, AWS를 production level에서 사용)
• '의미가 있는 일을, 올바르게 하고 싶다.'
• 경력
• (현) DevOps 전문 스타트업 ‘HB Smith’ 대표
• 택시 O2O 서비스 스타트업 ‘Kanizsa Lab’의 backend server / infra devops 담당
• Cloud computing 전문 스타트업 'A2 company' co-founder (‘KINX’에 인수합병)
• NEXON 'MapleStory 국내 Live Team'에서 DBA, SA로 근무 (산업 기능 요원)
https://www.linkedin.com/in/addnull/
https://hbsmith.io
6. Django API server unit test
• Why Django?
• Python 이라서!
• 정형화된 code structure
• 풍부한 troubleshooting 과 사용자 그룹
-> 누가 개발해도 결과가 비슷
https://www.djangoproject.com/
7. Django API server unit test
• 물론 단점도 많습니다.
• 다소 느리고, 무겁죠.
• 살짝 아쉬운 ORM 최적화.
-> 난 API server만 만들고 싶고,
HTML template 같은 건 안쓰는데…
-> DML은 ORM 한테 맡겨도,
database schema(DDL)는 직접 관리하세요.
8. Django API server unit test
• 그럼 Django 말고 더 좋은게 있을까요?
-> 그래도 API 개발 기한(due date)을 지키기 위해선,
Django + DRF 만한 것도 없는 것 같아요.
http://www.django-rest-framework.org/
9. Django API server unit test
• What is Django API server unit test?
• 여기서 말하는 ‘unit’은 각각의 API를 의미
• 즉, unit test는 실제 API call을 해보고
의도한 결과가 나오는지 확인
• 되도록 가능한 모든 API call을 test
-> 실행되지 않는 bug는 bug가 아니다?!?!
10. Django API server unit test
• API call example
• HTTP method:
• base URL:
• endpoint(path):
• query parameters:
(GET) https://api.example.com/v1/users/?role=admin&status=active
GET, POST, PUT, DELETE …
https://api.example.com/v1
/users/
role=admin&status=active
11. Django API server unit test
• unit(API) test에서 “의도한 결과”란?
-> 성공(2XX) 뿐만 아니라 일부러 실패(4XX)하는지도 확인
12. Django API server unit test
• “되도록 가능한 모든” API call test를 위해서
• Django의 in-memory DB:
• DRF의 ‘APITestCase’ Class:
• ‘factory_boy’:
-> 매번 깨끗한 test DB 생성
-> API call template
-> random parameter value generator
https://github.com/FactoryBoy/factory_boy
13. Django API server unit test
• 오늘 발표에 사용된 code
• API 와 unit test example
• HTTP method:
• endpoint(path):
• query parameters:
GET
/numbers/
start=1&end=2
‘start’와 ‘end’라는 정수 2개 사이에 있는 모든 정수를 반환하는 API
https://github.com/HardBoiledSmith/tabris/tree/master/pycon_kr_2017_addnull
21. 나의 개발 환경 구축기
• 저는 Mac OS X 에서 PyCharm으로 개발합니다.
하지만 실제 서버 환경은 AWS의 Amazon Linux죠.
CentOS와는 다르다! CentOS와는!
22. 나의 개발 환경 구축기
• 개발 환경과 실제 서버 환경 차이에서 오는 문제들…
• 그럼 ‘Virtualenv’ 쓰면 어떤가요?
-> Mac OS X에서는 좀 이상하게 동작해요.
-> 그리고 결국 동일한 환경이 아니잖아요.
23. 나의 개발 환경 구축기
• 여기 Vagrant 라는 silver bullet이 있습니다.
• 심지어 Amazon Linux box도 있습니다.
https://www.vagrantup.com/
https://app.vagrantup.com/mvbcoding/boxes/awslinux/
24. 나의 개발 환경 구축기
• 즉, 개발을 위한 Amazon Linux VM을 만들었습니다.
25. 나의 개발 환경 구축기
• ‘Vagrantfile’
https://github.com/HardBoiledSmith/tabris/tree/master/pycon_kr_2017_addnull
26. 나의 개발 환경 구축기
• ‘provisioning.py’
https://github.com/HardBoiledSmith/tabris/tree/master/pycon_kr_2017_addnull
27. 나의 개발 환경 구축기
• Vagrant VM을 개발 환경으로 쓰면,
-> 실제 서버와 거의 동일한 환경을 5~10분만에 구축
-> 개발팀의 모든 개발자가 동일한 환경을 사용
-> 뭔가 개발 환경이 이상해지면, 속편하게 VM 날리고, 새로 VM 생성
misconfiguration
dependency hell
package version conflict
OOM garbage files
31. Remote Debugging
• PyCharm에서 지원하는 2가지 remote debugging
• Using a remote interpreter
• Using Python Debug Server
-> 기존 source code 수정 불필요 (추천)
-> 기존 source code 수정 필요
32. Remote Debugging
• PyCharm ‘Using a remote interpreter’ 설정 단계
1. Remote Interpreter
2. Debug Configuration
3. Auto Deployment
33. Remote Debugging - 1. Remote Interpreter 설정
• 1.1. [preferences] 에서
‘project interpreter’ 검색
1.2. 우측 상단의
톱니바퀴 클릭
1.3. ‘Add Remote’
36. Remote Debugging - 2. Debug Configuration 설정
• 2.4. 오른쪽 화면처럼 설정
-> 여기까지만해도, remote debugging
가능합니다.
-> 하지만, local(Mac OS X)에서
Python code를 변경한 내용이
remote debugging에 바로 반영하려면?
37. Remote Debugging - 3. Auto Deployment 설정
• 3.1. [Tools] -> [Deployment]
-> [Configuration]
3.2. 좌측 상단의 ‘+’ 버튼 클릭
3.3. ‘SFTP’ 선택
38. Remote Debugging - 3. Auto Deployment 설정
• 3.4. 아래 화면처럼 ‘Connection’ 항목과 ‘Mappings’ 항목 설정
39. Remote Debugging - 3. Auto Deployment 설정
• 3.6. [Tools] -> [Deployment] -> [Automatic Upload]
• Auto Deployment 결과 예시
-> 이제 local(Mac OS X)에서
Python code를 변경한 내용이
remote debugging에 바로 반영됩니다.
46. Wrap Up
• Django API server unit test
• Django + DRF + factory_boy
• 나의 개발 환경 구축기
• Mac OS X + Vagrant(Amazon Linux)
• Remote Debugging
• PyCharm ‘Using a remote interpreter’
47. Call to Action
• 저희는 API 개발팀을 위한 모니터링 서비스를 만들고 있습니다.
저희의 early bird 고객이 되어주세요.
• 아직 Python Korea FG 가입하지 않으셨다구요?
• 저희 사이트에서 개발팁을 가져가세요!
https://hbsmith.io
https://www.facebook.com/groups/pythonkorea/
https://medium.com/hbsmith