Skip to content
This repository has been archived by the owner on Feb 13, 2021. It is now read-only.

Remove records in Airatable for test #42

Open
wants to merge 12 commits into
base: main
Choose a base branch
from

Conversation

yusuke-sforzando
Copy link
Contributor

@yusuke-sforzando yusuke-sforzando commented Dec 9, 2020

Describe the PR

To close #25 .
Added the ability to remove items registered in the test.

Screenshots

fortest

Detail of the change

airtable_client.py

Create delete_asset method:

def delete_asset_by_title(self, value: str):
    """Delete Airtable asset.

    Deletes the equipment registered in the Airtable with the value of the title field as an argument.

    Args:
        value (str): The values corresponding to the title-field in Airtable.

    Returns:
        Airtable API response (dict): Dictionary of successful or unsuccessful deletions and IDs of items.
    """
       
        ....

test_main.py, test_airtable_client.py

Add the code to remove the registered items.

Anticipated impacts

None.

To reproduce

Steps to check the behavior:

  1. Visit to Airtable
  2. Check the initial state of the table items
  3. Prepare Python environment
    python3 -m venv venv
    source venv/bin/activate
  4. pytest -vv .
  5. Check Airtable and make sure that the item is registered and deleted, as shown in the screenshot

Additional context

None.

@yusuke-sforzando yusuke-sforzando added the enhancement New feature or request label Dec 9, 2020
@yusuke-sforzando yusuke-sforzando added this to the Version 1.1 milestone Dec 9, 2020
@yusuke-sforzando yusuke-sforzando self-assigned this Dec 9, 2020
@shin-sforzando
Copy link
Collaborator

なぜ動名詞?

@yusuke-sforzando yusuke-sforzando changed the title Removing records in Airatable for test Remove records in Airatable for test Dec 9, 2020
@yusuke-sforzando
Copy link
Contributor Author

失礼しました。修正しました。

@codecov
Copy link

codecov bot commented Dec 9, 2020

Codecov Report

Merging #42 (7ef326f) into main (401930d) will increase coverage by 0.11%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main      #42      +/-   ##
==========================================
+ Coverage   79.88%   80.00%   +0.11%     
==========================================
  Files           5        5              
  Lines         169      175       +6     
  Branches       19       19              
==========================================
+ Hits          135      140       +5     
  Misses         26       26              
- Partials        8        9       +1     
Impacted Files Coverage Δ
airtable_client.py 87.50% <100.00%> (+4.16%) ⬆️
main.py 75.71% <0.00%> (-1.43%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 401930d...7ef326f. Read the comment docs.

@yusuke-sforzando yusuke-sforzando marked this pull request as ready for review December 9, 2020 12:26
Copy link
Collaborator

@tomoya-sforzando tomoya-sforzando left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

細かいですが、修正をお願いします。

@@ -43,10 +43,18 @@ def test_register(airtable_client):
"""Testing whether a dictionary with the proper field names can be registered correctly."""

assert airtable_client.register_asset(registerable_asset)
assert airtable_client.delete_asset("title", registerable_asset.title)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

このテストの名前だけど、test_register_asset_and_delete_asset_success()とか、対応しているメソッドを使ってちゃんとした方が良い

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

なるほどですね。承知しました。修正します。

tests/test_airtable_client.py Outdated Show resolved Hide resolved
tests/test_main.py Outdated Show resolved Hide resolved
"""

try:
return self.airtable_client.delete_by_field(field_name, field_value)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

これって何が返ってくるのか。Docstringに追記してほしいです

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

失礼しました。追記しておきます。

@@ -43,10 +43,18 @@ def test_register(airtable_client):
"""Testing whether a dictionary with the proper field names can be registered correctly."""

assert airtable_client.register_asset(registerable_asset)
assert airtable_client.delete_asset("title", registerable_asset.title)


def test_register_non_existent_key(airtable_client):
"""Testing an instance of the Airtable data class is an argument."""
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

この英文、どういう意味?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Airtableデータクラスが引数になっているかのテスト、という意味でしたが間違えているので修正します。

Copy link
Collaborator

@tomoya-sforzando tomoya-sforzando left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

@@ -36,3 +36,22 @@ def register_asset(self, asset: Asset):
except TypeError as te:
app.logger.error(te)
raise te

def delete_asset(self, field_name: str, field_value: str):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

このメソッドの存在意義がわからない。
引数でもらったものをそのまま self.airtable_client.delete_by_field(field_name, field_value) するだけなら、要らないじゃん。
そもそも Airtable field names. にどんなものがあるか覚えてないと使えないのも意味がわからない。
これなら、 delete_asset_by_title(self, value: str) -> Dict:return self.airtable_client.delete_by_field("title", value) したほうがいいじゃん。
なんで共同開発者に無駄な負担かけさせるの?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

そうですね。
Airtablefield name を意識させずに書くべきでした。
titleはメソッドに持たせます。
無駄な負担をかけてしまいました。
修正します。

"""Testing whether a dictionary with the proper field names can be registered correctly."""

assert airtable_client.register_asset(registerable_asset)
assert airtable_client.delete_asset("title", registerable_asset.title)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

テストで追加したいものを消したいんだよね?
テストで追加したものと同名のものを消したいんじゃないよね。
なんで airtable_client.register_asset() の返り値からID拾って airtable_client.delete(id) しないの?
そっちの方が楽だし素直じゃん。

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

そうですね。
こちらもその通りです。
こちらはIDで直接消せるように修正します。

@yusuke-sforzando yusuke-sforzando marked this pull request as draft December 10, 2020 11:15
assert airtable_client.register_asset(registerable_asset)
register_asset = airtable_client.register_asset(registerable_asset)
assert register_asset
assert airtable_client.airtable_client.delete(register_asset["id"])
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

delete できたことも assert する?悪いことはないか。

あ、わかった。
このテストの名前は、
test_register_asset_successだけでよくて、
test_delete_asset_by_title_successというテストが別に必要なんじゃない?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

わかりました。ちょっとやってみます。

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

でもここは本当はIDで消したいですよね。
タイトルで削除、というのは仮に今後PlayStation 5 (CFI-1000A01)を登録したいときに困っちゃう可能性がありますね。
やっぱりIDで消したい気もします。

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

とりあえずは修正しました。


with pytest.raises(TypeError):
airtable_client.register_asset({"test": "test"})


def test_delete_asset_failure(airtable_client):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

で、こちらのテストの名前が、test_delete_asset_by_title_failureになって対になるじゃない?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

そうですね、やってみます。

Copy link
Collaborator

@shin-sforzando shin-sforzando left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ダブルクォートとシングルクォートの混用もいいかげん修正してください。

@@ -87,6 +88,7 @@ def test_POST_register_airtable_success(test_client):
test_client.post("/registration", data={"asin": "B07XB5WX89"})
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

たとえば、このファイル中に B07XB5WX89 が3回も書かれている、つまりDRYじゃない。

@@ -87,6 +88,7 @@ def test_POST_register_airtable_success(test_client):
test_client.post("/registration", data={"asin": "B07XB5WX89"})
response = test_client.post("/register_airtable", data=imd, follow_redirects=True)
assert b"Registration completed!" in response.data
AirtableClient().delete_asset_by_title("テンマクデザイン サーカス TC DX")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ん?だからなんで登録したテストデータのIDで消さないの?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Removing records in Airtable for testing
3 participants