def test_delete(self, auth0_app): delete_instances = self.get_delete_instances() not_delete_instances = self.get_not_delete_instances() res = auth0_app.get(self.get_url()) assert res.status_code == 200 # タイトルと見出しの検証 assert get_title(res) == self.get_title() assert get_heading(res) == f"以下の{self.get_title()}を削除しますか?" # 削除ボタンを押して削除 form = res.forms[self.form_id] res = form.submit() assert res.status_code == 302 assert res.location == self.success_url # レコードが削除されたことを確認 assert self.model.objects.count() == len(not_delete_instances) for delete_instance in delete_instances: assert not self.model.objects.filter( pk=delete_instance.pk).exists() for not_delete_instance in not_delete_instances: assert self.model.objects.get(pk=not_delete_instance.pk)
def test_list(self, auth0_app): instance_list = self.get_fixture() # 日付型を正しく処理させるためにDBから読み直し for instance in instance_list: instance.refresh_from_db() with mock.patch.object(ForwardManyToOneDescriptor, "get_object", side_effect=Exception): res = auth0_app.get(self.url) # タイトルと見出しの検証 assert get_title(res) == self.get_title() assert get_heading(res) == self.get_title() if self.display_as == "table": selector = "#object-list > tr > td:first-child" else: selector = "#object-list > li" item_list = ObjectItemList(res.html.select(selector)) # TODO: POSTで送信するボタンが検知できていない for item, instance in zip(item_list, instance_list): assert item.all_links() == [self.get_anchor_link(instance)] + list( self.get_action_links(instance)) assert item_list.anchor_texts() == self.get_anchor_texts(instance_list) # パースペクティブの検証 perspectives = [ anchor["data-perspective"] for anchor in list(res.html.select(".perspectives a")) ] assert perspectives == list(self.perspective_keys)
def test_list(self, auth0_app, parent_model_factory): parent_instance = parent_model_factory() instance_list = self.get_fixture(parent_instance) # 日付型を正しく処理させるためにDBから読み直し for instance in instance_list: instance.refresh_from_db() with mock.patch.object(ForwardManyToOneDescriptor, "get_object", side_effect=Exception): res = auth0_app.get(self.get_url(parent_instance)) # タイトルと見出しの検証 assert get_title(res) == self.get_title(parent_instance) assert get_heading(res) == self.get_title(parent_instance) selector = "#object-list > li" item_list = ObjectItemList(res.html.select(selector)) # TODO: POSTで送信するボタンが検知できていない for item, instance in zip(item_list, instance_list): anchor_links = list( filter(lambda link: link is not None, [self.get_anchor_link(instance)])) assert item.all_links() == anchor_links + list( self.get_action_links(instance)) assert item_list.anchor_texts() == self.get_anchor_texts(instance_list)
def assert_heading(auth0_app, url, heading): # 画面取得 res = auth0_app.get(url) assert res.status_code == 200 # 見出しの検証 assert get_heading(res) == heading
def test_display(self, auth0_app, keys): # 画面取得 res = auth0_app.get(self.get_url()) assert res.status_code == 200 # タイトルと見出しの検証 assert get_title(res) == self.get_title() assert get_heading(res) == self.get_title() # 入力項目の検証 form = res.forms[self.form_id] assert get_input_fields(form) == list(keys), "入力フィールドの順番が正しくありません。"
def test_display(self, auth0_app, model_factory, maximum_inputs): instance = model_factory() # 画面取得 res = auth0_app.get(self.get_url(instance)) assert res.status_code == 200 # タイトルと見出しの検証 assert get_title(res) == self.get_title() assert get_heading(res) == self.get_title() # 入力項目の検証 form = res.forms[self.form_id] assert get_input_fields(form) == list( maximum_inputs.keys()), "入力フィールドの順番が正しくありません。"
def test_display(self, auth0_app, maximum_inputs, src_model_factory): # コピー元のインスタンスを作成 src_instance = src_model_factory() # 画面取得 res = auth0_app.get(self.get_url(src_instance)) assert res.status_code == 200 # タイトルと見出しの検証 assert get_title(res) == self.get_title() assert get_heading(res) == self.get_title() # 入力項目の検証(順不同) form = res.forms[self.form_id] expected_input_fields = set( list(maximum_inputs.keys()) + list(self.copy_fields)) # 重複を排除 assert sorted(get_input_fields(form)) == sorted(expected_input_fields)
def test_list(self, auth0_app): instance_list = self.get_fixture() with mock.patch.object(ForwardManyToOneDescriptor, "get_object", side_effect=Exception): res = auth0_app.get(self.url) # タイトルと見出しの検証 assert get_title(res) == self.get_title() assert get_heading(res) == self.get_title() item_list = ObjectItemList(res.html.select("#object-list > li")) assert item_list.links() == self.get_anchor_urls(instance_list) assert item_list.anchor_texts() == self.get_anchor_texts(instance_list) # パースペクティブの検証 perspectives = [ anchor["data-perspective"] for anchor in list(res.html.select(".perspectives a")) ] assert perspectives == list(self.perspective_keys)