Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Commit

Permalink
Remove unnecessary json.dumps from tests (#13303)
Browse files Browse the repository at this point in the history
  • Loading branch information
dklimpel authored Jul 17, 2022
1 parent 5d4028f commit efee345
Show file tree
Hide file tree
Showing 13 changed files with 143 additions and 200 deletions.
1 change: 1 addition & 0 deletions changelog.d/13303.misc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Remove unnecessary `json.dumps` from tests.
23 changes: 9 additions & 14 deletions tests/rest/client/test_account.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import json
import os
import re
from email.parser import Parser
Expand Down Expand Up @@ -96,9 +95,7 @@ def attempt_wrong_password_login(self, username: str, password: str) -> None:
"""
body = {"type": "m.login.password", "user": username, "password": password}

channel = self.make_request(
"POST", "/_matrix/client/r0/login", json.dumps(body).encode("utf8")
)
channel = self.make_request("POST", "/_matrix/client/r0/login", body)
self.assertEqual(channel.code, HTTPStatus.FORBIDDEN, channel.result)

def test_basic_password_reset(self) -> None:
Expand Down Expand Up @@ -480,16 +477,14 @@ def test_pending_invites(self) -> None:
self.assertEqual(memberships[0].room_id, room_id, memberships)

def deactivate(self, user_id: str, tok: str) -> None:
request_data = json.dumps(
{
"auth": {
"type": "m.login.password",
"user": user_id,
"password": "test",
},
"erase": False,
}
)
request_data = {
"auth": {
"type": "m.login.password",
"user": user_id,
"password": "test",
},
"erase": False,
}
channel = self.make_request(
"POST", "account/deactivate", request_data, access_token=tok
)
Expand Down
16 changes: 5 additions & 11 deletions tests/rest/client/test_directory.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import json
from http import HTTPStatus

from twisted.test.proto_helpers import MemoryReactor
Expand Down Expand Up @@ -97,8 +96,7 @@ def test_room_creation_too_long(self) -> None:

# We use deliberately a localpart under the length threshold so
# that we can make sure that the check is done on the whole alias.
data = {"room_alias_name": random_string(256 - len(self.hs.hostname))}
request_data = json.dumps(data)
request_data = {"room_alias_name": random_string(256 - len(self.hs.hostname))}
channel = self.make_request(
"POST", url, request_data, access_token=self.user_tok
)
Expand All @@ -110,8 +108,7 @@ def test_room_creation(self) -> None:
# Check with an alias of allowed length. There should already be
# a test that ensures it works in test_register.py, but let's be
# as cautious as possible here.
data = {"room_alias_name": random_string(5)}
request_data = json.dumps(data)
request_data = {"room_alias_name": random_string(5)}
channel = self.make_request(
"POST", url, request_data, access_token=self.user_tok
)
Expand Down Expand Up @@ -144,8 +141,7 @@ def test_deleting_alias_via_directory_appservice(self) -> None:

# Add an alias for the room, as the appservice
alias = RoomAlias(f"asns-{random_string(5)}", self.hs.hostname).to_string()
data = {"room_id": self.room_id}
request_data = json.dumps(data)
request_data = {"room_id": self.room_id}

channel = self.make_request(
"PUT",
Expand Down Expand Up @@ -193,8 +189,7 @@ def set_alias_via_state_event(
self.hs.hostname,
)

data = {"aliases": [self.random_alias(alias_length)]}
request_data = json.dumps(data)
request_data = {"aliases": [self.random_alias(alias_length)]}

channel = self.make_request(
"PUT", url, request_data, access_token=self.user_tok
Expand All @@ -206,8 +201,7 @@ def set_alias_via_directory(
) -> str:
alias = self.random_alias(alias_length)
url = "/_matrix/client/r0/directory/room/%s" % alias
data = {"room_id": self.room_id}
request_data = json.dumps(data)
request_data = {"room_id": self.room_id}

channel = self.make_request(
"PUT", url, request_data, access_token=self.user_tok
Expand Down
4 changes: 1 addition & 3 deletions tests/rest/client/test_identity.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
# See the License for the specific language governing permissions and
# limitations under the License.

import json
from http import HTTPStatus

from twisted.test.proto_helpers import MemoryReactor
Expand Down Expand Up @@ -51,12 +50,11 @@ def test_3pid_lookup_disabled(self) -> None:
self.assertEqual(channel.code, HTTPStatus.OK, channel.result)
room_id = channel.json_body["room_id"]

params = {
request_data = {
"id_server": "testis",
"medium": "email",
"address": "test@example.com",
}
request_data = json.dumps(params)
request_url = ("/rooms/%s/invite" % (room_id)).encode("ascii")
channel = self.make_request(
b"POST", request_url, request_data, access_token=tok
Expand Down
3 changes: 1 addition & 2 deletions tests/rest/client/test_login.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import json
import time
import urllib.parse
from http import HTTPStatus
Expand Down Expand Up @@ -400,7 +399,7 @@ def test_login_with_overly_long_device_id_fails(self) -> None:
channel = self.make_request(
"POST",
"/_matrix/client/v3/login",
json.dumps(body).encode("utf8"),
body,
custom_headers=None,
)

Expand Down
31 changes: 14 additions & 17 deletions tests/rest/client/test_password_policy.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
# See the License for the specific language governing permissions and
# limitations under the License.

import json
from http import HTTPStatus

from twisted.test.proto_helpers import MemoryReactor
Expand Down Expand Up @@ -89,7 +88,7 @@ def test_get_policy(self) -> None:
)

def test_password_too_short(self) -> None:
request_data = json.dumps({"username": "kermit", "password": "shorty"})
request_data = {"username": "kermit", "password": "shorty"}
channel = self.make_request("POST", self.register_url, request_data)

self.assertEqual(channel.code, HTTPStatus.BAD_REQUEST, channel.result)
Expand All @@ -100,7 +99,7 @@ def test_password_too_short(self) -> None:
)

def test_password_no_digit(self) -> None:
request_data = json.dumps({"username": "kermit", "password": "longerpassword"})
request_data = {"username": "kermit", "password": "longerpassword"}
channel = self.make_request("POST", self.register_url, request_data)

self.assertEqual(channel.code, HTTPStatus.BAD_REQUEST, channel.result)
Expand All @@ -111,7 +110,7 @@ def test_password_no_digit(self) -> None:
)

def test_password_no_symbol(self) -> None:
request_data = json.dumps({"username": "kermit", "password": "l0ngerpassword"})
request_data = {"username": "kermit", "password": "l0ngerpassword"}
channel = self.make_request("POST", self.register_url, request_data)

self.assertEqual(channel.code, HTTPStatus.BAD_REQUEST, channel.result)
Expand All @@ -122,7 +121,7 @@ def test_password_no_symbol(self) -> None:
)

def test_password_no_uppercase(self) -> None:
request_data = json.dumps({"username": "kermit", "password": "l0ngerpassword!"})
request_data = {"username": "kermit", "password": "l0ngerpassword!"}
channel = self.make_request("POST", self.register_url, request_data)

self.assertEqual(channel.code, HTTPStatus.BAD_REQUEST, channel.result)
Expand All @@ -133,7 +132,7 @@ def test_password_no_uppercase(self) -> None:
)

def test_password_no_lowercase(self) -> None:
request_data = json.dumps({"username": "kermit", "password": "L0NGERPASSWORD!"})
request_data = {"username": "kermit", "password": "L0NGERPASSWORD!"}
channel = self.make_request("POST", self.register_url, request_data)

self.assertEqual(channel.code, HTTPStatus.BAD_REQUEST, channel.result)
Expand All @@ -144,7 +143,7 @@ def test_password_no_lowercase(self) -> None:
)

def test_password_compliant(self) -> None:
request_data = json.dumps({"username": "kermit", "password": "L0ngerpassword!"})
request_data = {"username": "kermit", "password": "L0ngerpassword!"}
channel = self.make_request("POST", self.register_url, request_data)

# Getting a 401 here means the password has passed validation and the server has
Expand All @@ -161,16 +160,14 @@ def test_password_change(self) -> None:
user_id = self.register_user("kermit", compliant_password)
tok = self.login("kermit", compliant_password)

request_data = json.dumps(
{
"new_password": not_compliant_password,
"auth": {
"password": compliant_password,
"type": LoginType.PASSWORD,
"user": user_id,
},
}
)
request_data = {
"new_password": not_compliant_password,
"auth": {
"password": compliant_password,
"type": LoginType.PASSWORD,
"user": user_id,
},
}
channel = self.make_request(
"POST",
"/_matrix/client/r0/account/password",
Expand Down
Loading

0 comments on commit efee345

Please sign in to comment.