mirror of
https://git.anonymousland.org/anonymousland/synapse.git
synced 2025-05-05 00:24:56 -04:00
Add more missing type hints to tests. (#15028)
This commit is contained in:
parent
4eed7b2ede
commit
30509a1010
14 changed files with 124 additions and 111 deletions
|
@ -12,29 +12,33 @@
|
|||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
from typing import List
|
||||
from typing import List, Optional
|
||||
from unittest.mock import Mock, patch
|
||||
|
||||
from synapse._scripts.register_new_matrix_user import request_registration
|
||||
from synapse.types import JsonDict
|
||||
|
||||
from tests.unittest import TestCase
|
||||
|
||||
|
||||
class RegisterTestCase(TestCase):
|
||||
def test_success(self):
|
||||
def test_success(self) -> None:
|
||||
"""
|
||||
The script will fetch a nonce, and then generate a MAC with it, and then
|
||||
post that MAC.
|
||||
"""
|
||||
|
||||
def get(url, verify=None):
|
||||
def get(url: str, verify: Optional[bool] = None) -> Mock:
|
||||
r = Mock()
|
||||
r.status_code = 200
|
||||
r.json = lambda: {"nonce": "a"}
|
||||
return r
|
||||
|
||||
def post(url, json=None, verify=None):
|
||||
def post(
|
||||
url: str, json: Optional[JsonDict] = None, verify: Optional[bool] = None
|
||||
) -> Mock:
|
||||
# Make sure we are sent the correct info
|
||||
assert json is not None
|
||||
self.assertEqual(json["username"], "user")
|
||||
self.assertEqual(json["password"], "pass")
|
||||
self.assertEqual(json["nonce"], "a")
|
||||
|
@ -70,12 +74,12 @@ class RegisterTestCase(TestCase):
|
|||
# sys.exit shouldn't have been called.
|
||||
self.assertEqual(err_code, [])
|
||||
|
||||
def test_failure_nonce(self):
|
||||
def test_failure_nonce(self) -> None:
|
||||
"""
|
||||
If the script fails to fetch a nonce, it throws an error and quits.
|
||||
"""
|
||||
|
||||
def get(url, verify=None):
|
||||
def get(url: str, verify: Optional[bool] = None) -> Mock:
|
||||
r = Mock()
|
||||
r.status_code = 404
|
||||
r.reason = "Not Found"
|
||||
|
@ -107,20 +111,23 @@ class RegisterTestCase(TestCase):
|
|||
self.assertIn("ERROR! Received 404 Not Found", out)
|
||||
self.assertNotIn("Success!", out)
|
||||
|
||||
def test_failure_post(self):
|
||||
def test_failure_post(self) -> None:
|
||||
"""
|
||||
The script will fetch a nonce, and then if the final POST fails, will
|
||||
report an error and quit.
|
||||
"""
|
||||
|
||||
def get(url, verify=None):
|
||||
def get(url: str, verify: Optional[bool] = None) -> Mock:
|
||||
r = Mock()
|
||||
r.status_code = 200
|
||||
r.json = lambda: {"nonce": "a"}
|
||||
return r
|
||||
|
||||
def post(url, json=None, verify=None):
|
||||
def post(
|
||||
url: str, json: Optional[JsonDict] = None, verify: Optional[bool] = None
|
||||
) -> Mock:
|
||||
# Make sure we are sent the correct info
|
||||
assert json is not None
|
||||
self.assertEqual(json["username"], "user")
|
||||
self.assertEqual(json["password"], "pass")
|
||||
self.assertEqual(json["nonce"], "a")
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue