본문 바로가기

전체 글824

Get the mean of an array Description: It's the academic year's end, fateful moment of your school report. The averages must be calculated. All the students come to you and entreat you to calculate their average for them. Easy ! You just need to write a script. Return the average of the given array rounded down to its nearest integer. The array will never be empty. Solution: 1. Find the average. 2. Rounds down to an inte.. 2022. 4. 15.
Sum of Odd Cubed Numbers Description: Find the sum of the odd numbers within an array, after cubing the initial integers. The function should return undefined/None/nil/NULL if any of the values aren't numbers. Note: Booleans should not be considered as numbers. Solution: 1. If the element in the array is not of type 'int', None is returned. 2. If the cube of the remaining elements is odd, the values ​​are added. 3. Retu.. 2022. 4. 14.
@pytest.fixture 로 test 데이터 세팅하기 pytest.fixture 는 왜 사용할까? 테스트 코드를 작성하다보면 ‘클라이언트’나 ‘토큰’, ‘객체’ 등이 필요할 수 있습니다. 보통은 setup 이나 teardown 등으로 데이터를 세팅할 수 있지만 pytest에는 fixture 데코레이터를 통해 필요한 데이터를 세팅하고 어떤 테스트 함수든지 재활용할 수 있습니다. 테스트 코드 예시 아래는 로그인 api를 테스트 하는 함수입니다. # test_login.py def test_login_api(client, create_user): data = { "email": "test@test.com", "password": "password", } r = client.post("/api/v1/login", json=data) r_message = r.jso.. 2022. 4. 14.
Century From Year Introduction The first century spans from the year 1 up to and including the year 100, the second century - from the year 101 up to and including the year 200, etc. Task Given a year, return the century it is in. Examples 1705 --> 18 1900 --> 19 1601 --> 17 2000 --> 20 Solution: 1. Divide 'year' by 100. 2. Returns the decimal point rounded up. import math def century(year): return math.ceil(year.. 2022. 4. 13.
로그인시 Access Token, Refresh Token 보내주기 액세스 토큰을 사용하는 이유 서버가 액세스 토큰을 클라이언트에게 주면 클라이언트는 매 요청시 액세스 토큰을 서버로 보내주어 로그인 상태을 알려줍니다. 이러한 방식은 HTTP의 무상태 특성을 보완하기 위한 한 가지 방법이지만 액세스 토큰을 주는 방식은 전달 과정에서 탈취 당할 우려가 있어 보안에 문제가 있습니다. 이를 해결하기 위해 토큰에 만료기간을 주어, 만약 탈취를 당하더라도 시간이 지나면 토큰을 사용할 수 없게 만들 수 있습니다. 하지만 이는 로그인 상태가 주기적으로 풀린다는 뜻이고 사용자에게 큰 불편을 줄 것입니다. 그래서 사람들은 리프레시 토큰을 생각해내었습니다. 리프레시 토큰으로 액세스 토큰 재발급 리프레시 토큰은 액세스 토큰이 만료되었을 경우 이를 확인하고 다시 액세스 토큰을 발급하는 방법입니.. 2022. 4. 13.
Isograms Description: An isogram is a word that has no repeating letters, consecutive or non-consecutive. Implement a function that determines whether a string that contains only letters is an isogram. Assume the empty string is an isogram. Ignore letter case. Example: (Input --> Output) "Dermatoglyphics" --> true "aba" --> false "moOse" --> false (ignore letter case) Solution: 1. Change all 'string' to .. 2022. 4. 12.