From cea09f1d378b7f4e413e610f47a45f68f7e5eb17 Mon Sep 17 00:00:00 2001 From: Benjamin Bertrand <benjamin.bertrand@ess.eu> Date: Mon, 8 Jun 2020 16:00:31 +0200 Subject: [PATCH] Fix flake8 errors F541 f-string is missing placeholders --- app/models.py | 12 ++++++------ app/network/views.py | 4 ++-- tests/functional/test_api.py | 8 ++++---- tests/functional/test_web.py | 20 ++++++++++---------- 4 files changed, 22 insertions(+), 22 deletions(-) diff --git a/app/models.py b/app/models.py index b5d25a7..a62ed57 100644 --- a/app/models.py +++ b/app/models.py @@ -1347,12 +1347,12 @@ class Host(CreatedMixin, SearchableMixin, db.Model): raise ValidationError(r"Host name shall match [a-z0-9\-]{2,20}") existing_cname = Cname.query.filter_by(name=lower_string).first() if existing_cname: - raise ValidationError(f"Host name matches an existing cname") + raise ValidationError("Host name matches an existing cname") existing_interface = Interface.query.filter( Interface.name == lower_string, Interface.host_id != self.id ).first() if existing_interface: - raise ValidationError(f"Host name matches an existing interface") + raise ValidationError("Host name matches an existing interface") return lower_string def stack_members(self): @@ -1479,12 +1479,12 @@ class Interface(CreatedMixin, db.Model): ) existing_cname = Cname.query.filter_by(name=lower_string).first() if existing_cname: - raise ValidationError(f"Interface name matches an existing cname") + raise ValidationError("Interface name matches an existing cname") existing_host = Host.query.filter( Host.name == lower_string, Host.id != self.host.id ).first() if existing_host: - raise ValidationError(f"Interface name matches an existing host") + raise ValidationError("Interface name matches an existing host") return lower_string @validates("mac") @@ -1609,10 +1609,10 @@ class Cname(CreatedMixin, db.Model): raise ValidationError(r"cname shall match [a-z0-9\-]{2,20}") existing_interface = Interface.query.filter_by(name=lower_string).first() if existing_interface: - raise ValidationError(f"cname matches an existing interface") + raise ValidationError("cname matches an existing interface") existing_host = Host.query.filter_by(name=lower_string).first() if existing_host: - raise ValidationError(f"cname matches an existing host") + raise ValidationError("cname matches an existing host") return lower_string def to_dict(self, recursive=False): diff --git a/app/network/views.py b/app/network/views.py index 951af4d..f1bfcd4 100644 --- a/app/network/views.py +++ b/app/network/views.py @@ -183,7 +183,7 @@ def view_host(name): ): if not current_user.can_set_boot_profile(host): flash( - f"You don't have the proper permissions to set the boot profile. Please contact an admin user.", + "You don't have the proper permissions to set the boot profile. Please contact an admin user.", "warning", ) return redirect(url_for("network.view_host", name=name)) @@ -213,7 +213,7 @@ def view_host(name): else: if not current_user.can_create_vm(host): flash( - f"You don't have the proper permissions to create this VM. Please contact an admin user.", + "You don't have the proper permissions to create this VM. Please contact an admin user.", "warning", ) return redirect(url_for("network.view_host", name=name)) diff --git a/tests/functional/test_api.py b/tests/functional/test_api.py index a2cec3e..dd5dc39 100644 --- a/tests/functional/test_api.py +++ b/tests/functional/test_api.py @@ -2304,7 +2304,7 @@ def test_patch_host_invalid_device_type(client, host_factory, admin_token): response = patch( client, f"{API_URL}/network/hosts/{host.id}", data=data, token=admin_token ) - check_response_message(response, f"foo is not a valid devicetype", 400) + check_response_message(response, "foo is not a valid devicetype", 400) @pytest.mark.parametrize("groups", (["group1"], ["group1", "group2"])) @@ -2347,7 +2347,7 @@ def test_patch_host_invalid_ansible_group(client, host_factory, admin_token): response = patch( client, f"{API_URL}/network/hosts/{host.id}", data=data, token=admin_token ) - check_response_message(response, f"unknown_group is not a valid ansiblegroup", 400) + check_response_message(response, "unknown_group is not a valid ansiblegroup", 400) @pytest.mark.parametrize("items", (["AAA001"], ["AAB001", "AAB002"])) @@ -2386,7 +2386,7 @@ def test_patch_host_invalid_item(client, host_factory, admin_token): response = patch( client, f"{API_URL}/network/hosts/{host.id}", data=data, token=admin_token ) - check_response_message(response, f"ABC002 is not a valid item", 400) + check_response_message(response, "ABC002 is not a valid item", 400) def test_patch_host_network_permission( @@ -2747,7 +2747,7 @@ def test_patch_network_invalid_domain(client, network_factory, admin_token): response = patch( client, f"{API_URL}/network/networks/{network.id}", data=data, token=admin_token ) - check_response_message(response, f"foo is not a valid domain", 400) + check_response_message(response, "foo is not a valid domain", 400) def test_delete_item_success(client, admin_token, item): diff --git a/tests/functional/test_web.py b/tests/functional/test_web.py index eed25c3..e9a5c6b 100644 --- a/tests/functional/test_web.py +++ b/tests/functional/test_web.py @@ -380,14 +380,14 @@ def test_create_host(client, network_scope_factory, network_factory, device_type # (form validation error because the network is not part of the choices # for this user) login(client, "user_lab", "userlab") - response = client.post(f"/network/hosts/create", data=form) + response = client.post("/network/hosts/create", data=form) assert response.status_code == 200 # The host wasn't created assert models.Host.query.filter_by(name=name).first() is None logout(client) # Success with user_prod user login(client, "user_prod", "userprod") - response = client.post(f"/network/hosts/create", data=form, follow_redirects=True) + response = client.post("/network/hosts/create", data=form, follow_redirects=True) assert response.status_code == 200 # The host was created assert b"created!" in response.data @@ -429,7 +429,7 @@ def test_create_host_invalid_fields( # Invalid mac data = form.copy() data["mac"] = "ea:ea:60:45:a8:96:se" - response = client.post(f"/network/hosts/create", data=data, follow_redirects=True) + response = client.post("/network/hosts/create", data=data, follow_redirects=True) assert response.status_code == 200 assert b"Register new host" in response.data assert b"Invalid MAC address" in response.data @@ -439,7 +439,7 @@ def test_create_host_invalid_fields( # Invalid hostname data = form.copy() data["name"] = "invalid_host" - response = client.post(f"/network/hosts/create", data=data, follow_redirects=True) + response = client.post("/network/hosts/create", data=data, follow_redirects=True) assert response.status_code == 200 assert b"Register new host" in response.data assert b"Invalid input" in response.data @@ -803,7 +803,7 @@ def test_create_item_invalid_ics_id(logged_rw_client): ics_id = "AAA1100" form = {"ics_id": ics_id, "serial_number": "12345"} response = logged_rw_client.post( - f"/inventory/items/create", data=form, follow_redirects=True + "/inventory/items/create", data=form, follow_redirects=True ) assert response.status_code == 200 assert b"Register new item" in response.data @@ -824,7 +824,7 @@ def test_create_item_with_stack_member( "host_id": host.id, "stack_member": 1, } - response = logged_rw_client.post(f"/inventory/items/create", data=form) + response = logged_rw_client.post("/inventory/items/create", data=form) assert response.status_code == 302 item2 = models.Item.query.filter_by(ics_id=ics_id).first() assert host.stack_members() == [item1, item2] @@ -842,7 +842,7 @@ def test_create_item_with_host_and_no_stack_member( "host_id": host.id, "stack_member": "", } - response = logged_rw_client.post(f"/inventory/items/create", data=form) + response = logged_rw_client.post("/inventory/items/create", data=form) assert response.status_code == 302 item = models.Item.query.filter_by(ics_id=ics_id).first() assert item.host == host @@ -944,20 +944,20 @@ def test_view_networks(client, network_scope_factory, network_factory): ) # user_lab doesn't have the permissions to see any network login(client, "user_lab", "userlab") - response = client.get(f"/network/networks") + response = client.get("/network/networks") assert response.status_code == 200 assert network1.vlan_name not in str(response.data) assert network2.vlan_name not in str(response.data) logout(client) # user_prod user has only access to network1 login(client, "user_prod", "userprod") - response = client.get(f"/network/networks") + response = client.get("/network/networks") assert network1.vlan_name in str(response.data) assert network2.vlan_name not in str(response.data) logout(client) # admin can see all networks login(client, "admin", "adminpasswd") - response = client.get(f"/network/networks") + response = client.get("/network/networks") assert network1.vlan_name in str(response.data) assert network2.vlan_name in str(response.data) -- GitLab