Skip to content

Commit

Permalink
[revert] print削除の切り戻し
Browse files Browse the repository at this point in the history
  • Loading branch information
PigeonsHouse committed Jul 12, 2022
1 parent fc3f7fa commit 7dd2398
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 0 deletions.
3 changes: 3 additions & 0 deletions cruds/tags/tag.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ def create_tag(db: Session, name: str, color_code: str) -> GetTag:
db.commit()
db.refresh(tag_orm)

print(tag_orm.name)
print(tag_orm.color)

tag = GetTag.from_orm(tag_orm)

return tag
Expand Down
1 change: 1 addition & 0 deletions cruds/url_infos/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

def create_url_info(db: Session, url: str, url_type: str, work_id: str, user_id: str):
pattern = url_type_pattern.get(url_type, '')
print(pattern)
if not re.match(pattern, url):
raise HTTPException(status_code=400, detail='url pattern is invalid')
url_info_orm = models.UrlInfo(
Expand Down
1 change: 1 addition & 0 deletions tests/fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ def use_test_db_fixture():
get_db関数をテストDBで上書きする
"""
if not sqlalchemy_utils.database_exists(DATABASE_URL):
print('[INFO] CREATE DATABASE')
sqlalchemy_utils.create_database(DATABASE_URL)

# Reset test tables
Expand Down
2 changes: 2 additions & 0 deletions tests/test_asset.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ def test_post_asset_without_auth(use_test_db_fixture):
"asset_type": asset_type
})

print(res.request)

assert res.status_code == 403, 'Assetの投稿に失敗する'

def test_post_correct_image_asset(use_test_db_fixture, user_token_factory_for_test):
Expand Down
4 changes: 4 additions & 0 deletions tests/test_tag.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ def test_post_tag(use_test_db_fixture, user_token_factory_for_test):
assert res.status_code == 200, 'tagの作成に成功する'

res_json = res.json()
print(res_json)
assert res_json['name'] == name
assert res_json['color'] == color

Expand Down Expand Up @@ -80,6 +81,7 @@ def test_get_tag_by_tag_id(use_test_db_fixture, tag_for_test, user_token_factory

res_json = res.json()

print(res_json)
assert res_json['id'] == tag_id
assert res_json['name'] == name
assert res_json['color'] == color
Expand All @@ -104,6 +106,7 @@ def test_put_tag(use_test_db_fixture, tag_for_test, user_token_factory_for_test)
assert res.status_code == 200, 'タグの編集に成功する'

res_json = res.json()
print(res_json)
assert res_json['id'] == tag_id
assert res_json['name'] == name
assert res_json['color'] == color
Expand All @@ -124,4 +127,5 @@ def test_put_tag(use_test_db_fixture, tag_for_test, user_token_factory_for_test)
assert res.status_code == 200, 'タグの削除に成功する'

res_json = res.json()
print(res_json)
assert res_json == {'status': 'OK'}
23 changes: 23 additions & 0 deletions tests/test_user.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ def test_get_me(use_test_db_fixture, user_factory_for_test, user_token_factory_f
自分の情報を取得
"""
token = user_token_factory_for_test()
print('Token', token)
res = client.get('/api/v1/users/@me', headers={
"Authorization": f"Bearer { token.access_token }"
})
Expand Down Expand Up @@ -42,13 +43,15 @@ def test_get_me_with_expired_access_token(use_test_db_fixture, user_factory_for_
assert res.status_code == 403, '有効期限切れのアクセストークンを使った自分の情報の取得に失敗する'

def test_get_user_by_id(use_test_db_fixture, users_factory_for_test):
print("test_get_user_by_id :::::::: ユーザーの情報を取得")
"""
ユーザーの情報を取得
"""
count = 0
users_info = users_factory_for_test()
for user_info in users_info:
count+=1
print(f"===========================test_get_user_by_id: {count}==========================")
user_id: str = user_info.id
email: str = user_info.email
name: str = user_info.name
Expand All @@ -62,19 +65,22 @@ def test_get_user_by_id(use_test_db_fixture, users_factory_for_test):
assert res.json()['display_name'] == display_name

def test_get_user_by_not_correct_id(use_test_db_fixture, users_factory_for_test):
print("test_get_user_by_not_correct_id :::::::: 間違ったユーザーIDでユーザーの情報を取得")
"""
間違ったユーザーIDでユーザーの情報を取得
"""
count = 0
users_info = users_factory_for_test()
for user_info in users_info:
count+=1
print(f"===========================test_get_user_by_not_correct_id: {count}==========================")
user_id: str = user_info.id + "hoge"

res = client.get(f'/api/v1/users/{user_id}')
assert res.status_code == 404, 'ユーザーの情報の取得に失敗する'

def test_get_users(use_test_db_fixture, users_factory_for_test):
print("test_get_users :::::::: ユーザー一覧を取得")
"""
ユーザー一覧を取得
"""
Expand All @@ -84,24 +90,31 @@ def test_get_users(use_test_db_fixture, users_factory_for_test):
res = client.get(f'/api/v1/users')
for user_info in users_info:
count+=1
print(f"===========================test_get_users: {count}==========================")
print(user_info)
print(res.json())
user_id: str = user_info.id

assert res.status_code == 200, 'ユーザー一覧の取得に成功する'
assert res.json()[index]['id'] == user_id
index += 1

def test_get_users_with_limit(use_test_db_fixture, users_factory_for_test):
print("test_get_users_with_limit :::::::: 取得するユーザー数を制限してユーザー一覧を取得")
"""
取得するユーザー数を制限してユーザー一覧を取得
"""
limit = 3
users_info = users_factory_for_test()
res = client.get(f'/api/v1/users?limit={limit}')

print(res.json())

assert res.status_code == 200, '取得するユーザー数を制限してユーザー一覧の取得に成功する'
assert len(res.json()) == limit

def test_get_users_with_offset_id(use_test_db_fixture, users_factory_for_test):
print("test_get_users_with_offset_id :::::::: オフセットを指定してユーザー一覧を取得")
"""
オフセットを指定してユーザー一覧を取得
"""
Expand All @@ -114,6 +127,7 @@ def test_get_users_with_offset_id(use_test_db_fixture, users_factory_for_test):
assert res.json()[0]['id'] == user_id

def test_get_users_with_not_exit_offset_id(use_test_db_fixture, users_factory_for_test):
print("test_get_users_with_not_exit_offset_id :::::::: 存在しないオフセットIDを指定してユーザー一覧を取得")
"""
存在しないオフセットIDを指定してユーザー一覧を取得
"""
Expand All @@ -125,6 +139,7 @@ def test_get_users_with_not_exit_offset_id(use_test_db_fixture, users_factory_fo


def test_put_all_info_of_user_me(use_test_db_fixture, user_factory_for_test, user_token_factory_for_test, session_for_test):
print("test_put_all_info_of_user_me :::::::: ユーザーの情報をすべて編集")
"""
ユーザーの情報をすべて編集
"""
Expand All @@ -141,6 +156,7 @@ def test_put_all_info_of_user_me(use_test_db_fixture, user_factory_for_test, use
new_twitter_id:str = "new_twitter_id"
new_github_id:str = "new_github_id"

print('Token', token)
res = client.put('/api/v1/users/@me', headers={
"Authorization": f"Bearer { token.access_token }"
}, json={
Expand All @@ -162,6 +178,7 @@ def test_put_all_info_of_user_me(use_test_db_fixture, user_factory_for_test, use
assert res.json()['profile'] != profile

def test_put_a_info_of_user_me(use_test_db_fixture, user_factory_for_test, user_token_factory_for_test, session_for_test):
print("test_put_a_info_of_user_me :::::::: ユーザーの情報を1つ編集")
"""
ユーザーの情報を1つ編集
"""
Expand All @@ -174,6 +191,7 @@ def test_put_a_info_of_user_me(use_test_db_fixture, user_factory_for_test, user_

new_display_name: str = "new_display_name"

print('Token', token)
res = client.put('/api/v1/users/@me', headers={
"Authorization": f"Bearer { token.access_token }"
}, json={
Expand All @@ -187,13 +205,15 @@ def test_put_a_info_of_user_me(use_test_db_fixture, user_factory_for_test, user_
assert res.json()['profile'] == profile

def test_put_user_avatar_with_not_url_format(use_test_db_fixture, user_token_factory_for_test):
print("test_put_user_avatar_with_not_url_format :::::::: ユーザーのアイコンをURLフォーマットが間違ったものに編集")
"""
ユーザーのアイコンをURLフォーマットが間違ったものに編集
"""
token = user_token_factory_for_test()

new_avatar_url: str = "newavatar.png"

print('Token', token)
res = client.put('/api/v1/users/@me', headers={
"Authorization": f"Bearer { token.access_token }"
}, json={
Expand All @@ -203,6 +223,7 @@ def test_put_user_avatar_with_not_url_format(use_test_db_fixture, user_token_fac
assert res.status_code == 422, 'ユーザーのアイコンの編集に失敗する'

def test_put_unauthorized(use_test_db_fixture):
print("test_put_unauthorized :::::::: アクセストークンなしで自分の情報を変更する")
"""
アクセストークンなしで自分の情報を変更する
"""
Expand All @@ -221,6 +242,7 @@ def test_put_unauthorized(use_test_db_fixture):
assert res.status_code == 403, 'アクセストークンなしで自分の情報の変更に失敗する'

def test_put_with_expired_access_token(use_test_db_fixture, user_token_factory_for_test):
print("test_put_with_expired_access_token :::::::: 期限切れのアクセストークンを用いて自分の情報を変更する")
"""
期限切れのアクセストークンを用いて自分の情報を変更する
"""
Expand All @@ -231,6 +253,7 @@ def test_put_with_expired_access_token(use_test_db_fixture, user_token_factory_f
new_avatar_url: str = "https://newavatar.png"
new_profile: str = "new_profile"

print('Token', token)
res = client.put('/api/v1/users/@me', headers={
"Authorization": f"Bearer { token.access_token }"
}, json={
Expand Down
1 change: 1 addition & 0 deletions utils/discord.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ def discord_verify_user_belongs_to_valid_guild(access_token: str) -> bool:
guilds = discord_fetch_user_guilds(access_token=access_token)
valid_guild_id = os.environ.get('DISCORD_GUILD_ID')
for guild in guilds:
print(guild.id, '==', valid_guild_id)
if guild.id == valid_guild_id:
return True

Expand Down

0 comments on commit 7dd2398

Please sign in to comment.