전체 글 315

[Pytest] 4. Pytest with Django (Feat. pytest-Django)

pytest-django 설치 Django 프레임워크에서 Pytest를 진행 하기 위해선 pytest-django 패키지 설치가 필요하다. $ pip install pytest-django https://pytest-django.readthedocs.io/en/latest/ pytest-django Documentation — pytest-django documentation © Copyright 2022, Andreas Pelme and contributors. Revision 1f3708ab. pytest-django.readthedocs.io django 셋팅 1. Django 프로젝트 생성 2. Django APP 생성 3. Settings.py에 DB 정보 및 APP 등록 (만약에 DOT_ENV..

Python/Advanced 2022.11.06

[Pytest] 3. Pytest 문법 (Feat. fixture, parametize)

Basic pytest 기본 사용법 # test1.py import pytest def func(x): return x + 1 def test_add(): assert func(4) == 4 $ pytest test1.py Fixture Fixture란 Testing 을 하기 위해 공통적으로 필요한 자원을 사전에 준비해놓는 방법 (1) square_10이란 함수를 Fixture로 준비. (테스트 간 매반 호출됨) # 함수를 fixture로 @pytest.fixture def square_10(): return 10 * 10 def test_square(square_10): assert square_10 == 100 # 121 (2) square_10이란 함수를 Fixture로 미리 준비 및 활용 @pyt..

Python/Advanced 2022.11.06

[Pytest] 2. Pytest 명령어 옵션 (command)

Pytest 명령어 옵션 1. 해당 디렉토리 내 모든 test_.py, *_test.py 실행 $ pytest 2. 특정 디렉토리 내부 실행 $ python -m pytest / 3. 특정 테스트 함수만 실행시 (k 옵션) $ pytest .py -k 4. 하나라도 Fail시 멈추고 싶을 때 $ pytest -x 5. 각 테스트 함수 결과 출력 (보다 자세히) $ pytest -vv 6. . 모든 test 실행 결과 출력 pytest -rA (pass포함) pytest -ra (pass 제외) 7. 결과에 Color 입히고 싶을때 (kernel 창 등에서 쓰기 좋음) $ pytest --color=yes 8. 캐시 파일 초기화 - 정확성에 대한 CI 과정에 사용 권장 (clear-cache ) $ pyt..

Python/Advanced 2022.11.05

[Pytest] 1. Pytest란? (+ 프레임워크 별 사용)

Pytest란? Python 코드를 단위 테스트 (= 유닛테스트) 하기 위한 TEST Framework로, Python 기반 프로젝트의 TDD (Test Driven Development)에 주로 사용 과거 TDD 종류 기반 정리 글 링크 [SW 개발] 테스트 중심의 개발 TDD (with. Unit, E2E, Integration) "의도하지 않은 결함 수가 많아지면 개발자는 변경을 주저한다" 테스트 주도 개발 (TDD) 란? Test Driven Development 의 약자로 테스트 주도 개발이란는 뜻을 가지는 소프트웨어 개발 방법론 중 하나이 yubi5050.tistory.com Pytest 특징 테스트를 작성하는 데 있어 함수만 정의하면 되므로 편리 (단, pytest만의 고유한 방식을 익혀야 ..

Python/Advanced 2022.11.04

[기술면접 대비] Django, DRF, 배포

Django 👉 Django의 장단점은? 장점 : 관리자 admin 패널 제공, 기존에 개발되어 있는 다양한 패키지들이 많음, 로그인 로그아웃 등 미리 구현 단점 : 기본적으로 요소들이 다 포함되어 있기 때문에 오히려 무겁다는 점, 자유도가 떨어집니다. 👉 Django의 MTV 패턴 시스템은 무엇입니까? Model : DB에 대한 ORM Model Template : 사용자에게 보여지는 화면 View : 프로그램이 동작하는 비즈니스 로직 부분 참고 링크 [Django] MTV 패턴과 동작 Flow Django https://www.djangoproject.com/ The web framework for perfectionists with deadlines | Django Django Django make..

[FastAPI] (7) MySQL 연결 및 API Test

MySQL 설치 및 DB 생성 1-1. MySql 설치 (로컬 pc에 직접 설치) https://www.mysql.com/downloads/ MySQL :: MySQL Downloads MySQL Cluster CGE MySQL Cluster is a real-time open source transactional database designed for fast, always-on access to data under high throughput conditions. MySQL Cluster MySQL Cluster Manager Plus, everything in MySQL Enterprise Edition Learn More » C www.mysql.com 1-2. Docker MySQL 설치 doc..

Python/FastAPI 2022.11.01

[기술면접 대비] Web 일반 & 보안

HTTP 👉 HTTP 란? Hyper Text Transfer Protocol로 클라이언트와 서버 간에 정보를 주고 받는 프로토콜 (규약) HTTP Request 메시지 = Request Header + Request Body HTTP Response 메시지 = Response Header + Response Body 👉 HTTP Header HTTP 메시지에 대한 정보를 포함하며, key-value 형태 content-type : 본문의 Type을 나타냄. ex) application/json, text/html Accept : 클라이언트가 처리 가능한 Type을 나타냄 ex) application/json, text/html 등 👉 HTTP 의 주요 특징 비연결 (서버-클라 전송 완료시 연결 종료, ..

[FastAPI] (6) 보일러 플레이트 (Boiler Plate)

BoilerPlate란? BoilerPlate Code란 재 사용할 수 있는 뼈대 코드로, 보일러 플레이트를 작성해 놓고, 프로젝트 신규 생성 시마다 적용하여 사용 가능하다. 폴더 구조 FastAPI BoilerPlate ┌─FastAPI BoilerPlate │ └─deployments │ │ │ └─ Dockerfile ├─src │ ├─app.py : 최초 main 실행 함수 │ │ │ ├─dtos/ : Input, Output 전달 Object │ │ │ ├─db/ : DB Connect and CRUD │ │ │ ├─models/ : DB models │ │ │ ├─router/ : API Router │ │ │ ├─services/ : 비즈니스 로직 서비스 │ │ │ └─test/ : 모듈별 ..

Python/FastAPI 2022.10.27

[FastAPI] (5) FastAPI Validation - Path, Query, Field

Path, Query, Field Pydantic의 데이터 검증에 덧붙여 FastAPI의 Field, Path, Query를 사용해 매개변수를 명시적으로 정의하고, 좀더 세부적인 데이터 검증이 가능하다. gt, ge, lt, le : 숫자 대소비교 (greater than, less than 등) min_length, max_length : 문자열 길이 값 min_items, max_items : List, Set등의 Collection 객체 담당 regex 등 도 사용 가능 방법에는 크게 2가지가 존재 함수 인자에서 FastAPI의 Path, Query를 활용하는 방법 BaseModel을 상속한 Class에서 Pydantic의 Field 사용 방법 예제 공통 부분 - 임의 데이터셋 생성 예제 1과 예제..

Python/FastAPI 2022.10.26

[FastAPI] (4) FastAPI POST 작성법

POST Method FastAPI 에서 POST Method는 다음과 같은 특징이 있다. Schema Dependency가 존재한다. (Pydantic) BaseModel을 상속 받은 객체로 인자를 넘겨 받아야 한다. POST Method 예제 1 Pydantic의 이메일 (EmailStr), 파일 경로, 우편 번호, URL(HttpURL) 를 사용하면 다양한 형태의 값을 쉽게 검증 가능 from fastapi import FastAPI, status from pydantic import BaseModel, HttpUrl from typing import Optional app = FastAPI() class User(BaseModel): name:str url:Optional[HttpUrl] = No..

Python/FastAPI 2022.10.26