mirror of
https://github.com/bookwyrm-social/bookwyrm.git
synced 2024-11-22 09:31:08 +00:00
check alias with new user data
Instead of breaking a bunch of existing tests...
This commit is contained in:
parent
ed55e052f6
commit
1a93ba0cac
4 changed files with 55 additions and 22 deletions
|
@ -46,11 +46,16 @@ class BaseActivity(TestCase):
|
||||||
# don't try to load the user icon
|
# don't try to load the user icon
|
||||||
del self.userdata["icon"]
|
del self.userdata["icon"]
|
||||||
|
|
||||||
|
remote_datafile = pathlib.Path(__file__).parent.joinpath(
|
||||||
|
"../data/ap_user_external.json"
|
||||||
|
)
|
||||||
|
self.remote_userdata = json.loads(remote_datafile.read_bytes())
|
||||||
|
del self.remote_userdata["icon"]
|
||||||
|
|
||||||
alias_datafile = pathlib.Path(__file__).parent.joinpath(
|
alias_datafile = pathlib.Path(__file__).parent.joinpath(
|
||||||
"../data/ap_user_aliased.json"
|
"../data/ap_user_aliased.json"
|
||||||
)
|
)
|
||||||
self.alias_userdata = json.loads(alias_datafile.read_bytes())
|
self.alias_userdata = json.loads(alias_datafile.read_bytes())
|
||||||
# don't try to load the user icon
|
|
||||||
del self.alias_userdata["icon"]
|
del self.alias_userdata["icon"]
|
||||||
|
|
||||||
image_path = pathlib.Path(__file__).parent.joinpath(
|
image_path = pathlib.Path(__file__).parent.joinpath(
|
||||||
|
@ -117,13 +122,6 @@ class BaseActivity(TestCase):
|
||||||
status=200,
|
status=200,
|
||||||
)
|
)
|
||||||
|
|
||||||
responses.add(
|
|
||||||
responses.GET,
|
|
||||||
"https://example.com/user/moose",
|
|
||||||
json=self.alias_userdata,
|
|
||||||
status=200,
|
|
||||||
)
|
|
||||||
|
|
||||||
with patch("bookwyrm.models.user.set_remote_server.delay"):
|
with patch("bookwyrm.models.user.set_remote_server.delay"):
|
||||||
result = resolve_remote_id(
|
result = resolve_remote_id(
|
||||||
"https://example.com/user/mouse", model=models.User
|
"https://example.com/user/mouse", model=models.User
|
||||||
|
@ -148,25 +146,21 @@ class BaseActivity(TestCase):
|
||||||
|
|
||||||
responses.add(
|
responses.add(
|
||||||
responses.GET,
|
responses.GET,
|
||||||
"https://example.com/user/mouse",
|
"https://example.com/user/ali",
|
||||||
json=self.userdata,
|
json=self.remote_userdata,
|
||||||
status=200,
|
status=200,
|
||||||
)
|
)
|
||||||
|
|
||||||
with patch("bookwyrm.models.user.set_remote_server.delay"):
|
with patch("bookwyrm.models.user.set_remote_server.delay"):
|
||||||
result = resolve_remote_id(
|
result = resolve_remote_id(
|
||||||
"https://example.com/user/mouse", model=models.User
|
"https://example.com/user/moose", model=models.User
|
||||||
)
|
)
|
||||||
self.assertIsInstance(result, models.User)
|
self.assertIsInstance(result, models.User)
|
||||||
self.assertEqual(result.name, "MOUSE?? MOUSE!!")
|
self.assertEqual(result.name, "moose?? moose!!")
|
||||||
self.assertEqual(
|
self.assertEqual(models.User.objects.count(), 3) # created moose plus the alias
|
||||||
models.User.objects.count(), 3
|
alias = models.User.objects.last()
|
||||||
) # created a new mouse plus the alias
|
self.assertEqual(alias.name, "Ali As")
|
||||||
alias = models.User.objects.last() # moose
|
self.assertEqual(result.also_known_as.first(), alias) # Ali is alias of Moose
|
||||||
self.assertEqual(alias.name, "moose?? moose!!") # check it's moose
|
|
||||||
self.assertEqual(
|
|
||||||
result.also_known_as.first(), alias
|
|
||||||
) # moose is alias of new mouse
|
|
||||||
|
|
||||||
def test_to_model_invalid_model(self, *_):
|
def test_to_model_invalid_model(self, *_):
|
||||||
"""catch mismatch between activity type and model type"""
|
"""catch mismatch between activity type and model type"""
|
||||||
|
|
|
@ -28,7 +28,6 @@
|
||||||
},
|
},
|
||||||
"bookwyrmUser": true,
|
"bookwyrmUser": true,
|
||||||
"manuallyApprovesFollowers": false,
|
"manuallyApprovesFollowers": false,
|
||||||
"alsoKnownAs": ["https://example.com/user/moose"],
|
|
||||||
"discoverable": false,
|
"discoverable": false,
|
||||||
"devices": "https://friend.camp/users/tripofmice/collections/devices",
|
"devices": "https://friend.camp/users/tripofmice/collections/devices",
|
||||||
"tag": [],
|
"tag": [],
|
||||||
|
|
|
@ -29,7 +29,7 @@
|
||||||
"bookwyrmUser": true,
|
"bookwyrmUser": true,
|
||||||
"manuallyApprovesFollowers": false,
|
"manuallyApprovesFollowers": false,
|
||||||
"discoverable": false,
|
"discoverable": false,
|
||||||
"alsoKnownAs": ["http://example.com/a/b"],
|
"alsoKnownAs": ["https://example.com/user/ali"],
|
||||||
"devices": "",
|
"devices": "",
|
||||||
"tag": [],
|
"tag": [],
|
||||||
"icon": {
|
"icon": {
|
||||||
|
|
40
bookwyrm/tests/data/ap_user_external.json
Normal file
40
bookwyrm/tests/data/ap_user_external.json
Normal file
|
@ -0,0 +1,40 @@
|
||||||
|
{
|
||||||
|
"@context": [
|
||||||
|
"https://www.w3.org/ns/activitystreams",
|
||||||
|
"https://w3id.org/security/v1",
|
||||||
|
{
|
||||||
|
"manuallyApprovesFollowers": "as:manuallyApprovesFollowers",
|
||||||
|
"schema": "http://schema.org#",
|
||||||
|
"PropertyValue": "schema:PropertyValue",
|
||||||
|
"value": "schema:value"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"id": "https://example.com/user/ali",
|
||||||
|
"type": "Person",
|
||||||
|
"preferredUsername": "alias",
|
||||||
|
"name": "Ali As",
|
||||||
|
"inbox": "https://example.com/user/ali/inbox",
|
||||||
|
"outbox": "https://example.com/user/ali/outbox",
|
||||||
|
"followers": "https://example.com/user/ali/followers",
|
||||||
|
"following": "https://example.com/user/ali/following",
|
||||||
|
"summary": "",
|
||||||
|
"publicKey": {
|
||||||
|
"id": "https://example.com/user/ali/#main-key",
|
||||||
|
"owner": "https://example.com/user/ali",
|
||||||
|
"publicKeyPem": "-----BEGIN PUBLIC KEY-----\nMIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQC6QisDrjOQvkRo/MqNmSYPwqtt\nCxg/8rCW+9jKbFUKvqjTeKVotEE85122v/DCvobCCdfQuYIFdVMk+dB1xJ0iPGPg\nyU79QHY22NdV9mFKA2qtXVVxb5cxpA4PlwOHM6PM/k8B+H09OUrop2aPUAYwy+vg\n+MXyz8bAXrIS1kq6fQIDAQAB\n-----END PUBLIC KEY-----"
|
||||||
|
},
|
||||||
|
"endpoints": {
|
||||||
|
"sharedInbox": "https://example.com/inbox"
|
||||||
|
},
|
||||||
|
"bookwyrmUser": true,
|
||||||
|
"manuallyApprovesFollowers": false,
|
||||||
|
"alsoKnownAs": [],
|
||||||
|
"discoverable": false,
|
||||||
|
"devices": "",
|
||||||
|
"tag": [],
|
||||||
|
"icon": {
|
||||||
|
"type": "Image",
|
||||||
|
"mediaType": "image/png",
|
||||||
|
"url": "https://example.com/images/avatars/ALIAS-2-crop-50.png"
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue