mirror of
https://git.anonymousland.org/anonymousland/synapse.git
synced 2024-10-01 11:49:51 -04:00
Perform PresenceInvitesTestCase against real SQLiteMemoryDbPool
This commit is contained in:
parent
493b1e6d3c
commit
fb93a4a9e3
@ -209,29 +209,19 @@ class PresenceStateTestCase(unittest.TestCase):
|
|||||||
class PresenceInvitesTestCase(unittest.TestCase):
|
class PresenceInvitesTestCase(unittest.TestCase):
|
||||||
""" Tests presence management. """
|
""" Tests presence management. """
|
||||||
|
|
||||||
|
@defer.inlineCallbacks
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
self.mock_http_client = Mock(spec=[])
|
self.mock_http_client = Mock(spec=[])
|
||||||
self.mock_http_client.put_json = DeferredMockCallable()
|
self.mock_http_client.put_json = DeferredMockCallable()
|
||||||
|
|
||||||
self.mock_federation_resource = MockHttpResource()
|
self.mock_federation_resource = MockHttpResource()
|
||||||
|
|
||||||
|
db_pool = SQLiteMemoryDbPool()
|
||||||
|
yield db_pool.prepare()
|
||||||
|
|
||||||
hs = HomeServer("test",
|
hs = HomeServer("test",
|
||||||
clock=MockClock(),
|
clock=MockClock(),
|
||||||
db_pool=None,
|
db_pool=db_pool,
|
||||||
datastore=Mock(spec=[
|
|
||||||
"has_presence_state",
|
|
||||||
"allow_presence_visible",
|
|
||||||
"add_presence_list_pending",
|
|
||||||
"set_presence_list_accepted",
|
|
||||||
"get_presence_list",
|
|
||||||
"del_presence_list",
|
|
||||||
|
|
||||||
# Bits that Federation needs
|
|
||||||
"prep_send_transaction",
|
|
||||||
"delivered_txn",
|
|
||||||
"get_received_txn_response",
|
|
||||||
"set_received_txn_response",
|
|
||||||
]),
|
|
||||||
handlers=None,
|
handlers=None,
|
||||||
resource_for_client=Mock(),
|
resource_for_client=Mock(),
|
||||||
resource_for_federation=self.mock_federation_resource,
|
resource_for_federation=self.mock_federation_resource,
|
||||||
@ -239,20 +229,14 @@ class PresenceInvitesTestCase(unittest.TestCase):
|
|||||||
)
|
)
|
||||||
hs.handlers = JustPresenceHandlers(hs)
|
hs.handlers = JustPresenceHandlers(hs)
|
||||||
|
|
||||||
self.datastore = hs.get_datastore()
|
self.store = hs.get_datastore()
|
||||||
|
|
||||||
def has_presence_state(user_localpart):
|
|
||||||
return defer.succeed(
|
|
||||||
user_localpart in ("apple", "banana"))
|
|
||||||
self.datastore.has_presence_state = has_presence_state
|
|
||||||
|
|
||||||
def get_received_txn_response(*args):
|
|
||||||
return defer.succeed(None)
|
|
||||||
self.datastore.get_received_txn_response = get_received_txn_response
|
|
||||||
|
|
||||||
# Some local users to test with
|
# Some local users to test with
|
||||||
self.u_apple = hs.parse_userid("@apple:test")
|
self.u_apple = hs.parse_userid("@apple:test")
|
||||||
self.u_banana = hs.parse_userid("@banana:test")
|
self.u_banana = hs.parse_userid("@banana:test")
|
||||||
|
yield self.store.create_presence(self.u_apple.localpart)
|
||||||
|
yield self.store.create_presence(self.u_banana.localpart)
|
||||||
|
|
||||||
# ID of a local user that does not exist
|
# ID of a local user that does not exist
|
||||||
self.u_durian = hs.parse_userid("@durian:test")
|
self.u_durian = hs.parse_userid("@durian:test")
|
||||||
|
|
||||||
@ -275,12 +259,16 @@ class PresenceInvitesTestCase(unittest.TestCase):
|
|||||||
yield self.handler.send_invite(
|
yield self.handler.send_invite(
|
||||||
observer_user=self.u_apple, observed_user=self.u_banana)
|
observer_user=self.u_apple, observed_user=self.u_banana)
|
||||||
|
|
||||||
self.datastore.add_presence_list_pending.assert_called_with(
|
self.assertEquals(
|
||||||
"apple", "@banana:test")
|
[{"observed_user_id": "@banana:test", "accepted": 1}],
|
||||||
self.datastore.allow_presence_visible.assert_called_with(
|
(yield self.store.get_presence_list(self.u_apple.localpart))
|
||||||
"banana", "@apple:test")
|
)
|
||||||
self.datastore.set_presence_list_accepted.assert_called_with(
|
self.assertTrue(
|
||||||
"apple", "@banana:test")
|
(yield self.store.is_presence_visible(
|
||||||
|
observed_localpart=self.u_banana.localpart,
|
||||||
|
observer_userid=self.u_apple.to_string(),
|
||||||
|
))
|
||||||
|
)
|
||||||
|
|
||||||
self.mock_start.assert_called_with(
|
self.mock_start.assert_called_with(
|
||||||
self.u_apple, target_user=self.u_banana)
|
self.u_apple, target_user=self.u_banana)
|
||||||
@ -290,10 +278,10 @@ class PresenceInvitesTestCase(unittest.TestCase):
|
|||||||
yield self.handler.send_invite(
|
yield self.handler.send_invite(
|
||||||
observer_user=self.u_apple, observed_user=self.u_durian)
|
observer_user=self.u_apple, observed_user=self.u_durian)
|
||||||
|
|
||||||
self.datastore.add_presence_list_pending.assert_called_with(
|
self.assertEquals(
|
||||||
"apple", "@durian:test")
|
[],
|
||||||
self.datastore.del_presence_list.assert_called_with(
|
(yield self.store.get_presence_list(self.u_apple.localpart))
|
||||||
"apple", "@durian:test")
|
)
|
||||||
|
|
||||||
@defer.inlineCallbacks
|
@defer.inlineCallbacks
|
||||||
def test_invite_remote(self):
|
def test_invite_remote(self):
|
||||||
@ -314,8 +302,10 @@ class PresenceInvitesTestCase(unittest.TestCase):
|
|||||||
yield self.handler.send_invite(
|
yield self.handler.send_invite(
|
||||||
observer_user=self.u_apple, observed_user=self.u_cabbage)
|
observer_user=self.u_apple, observed_user=self.u_cabbage)
|
||||||
|
|
||||||
self.datastore.add_presence_list_pending.assert_called_with(
|
self.assertEquals(
|
||||||
"apple", "@cabbage:elsewhere")
|
[{"observed_user_id": "@cabbage:elsewhere", "accepted": 0}],
|
||||||
|
(yield self.store.get_presence_list(self.u_apple.localpart))
|
||||||
|
)
|
||||||
|
|
||||||
yield put_json.await_calls()
|
yield put_json.await_calls()
|
||||||
|
|
||||||
@ -347,8 +337,12 @@ class PresenceInvitesTestCase(unittest.TestCase):
|
|||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
self.datastore.allow_presence_visible.assert_called_with(
|
self.assertTrue(
|
||||||
"apple", "@cabbage:elsewhere")
|
(yield self.store.is_presence_visible(
|
||||||
|
observed_localpart=self.u_apple.localpart,
|
||||||
|
observer_userid=self.u_cabbage.to_string(),
|
||||||
|
))
|
||||||
|
)
|
||||||
|
|
||||||
yield put_json.await_calls()
|
yield put_json.await_calls()
|
||||||
|
|
||||||
@ -382,6 +376,11 @@ class PresenceInvitesTestCase(unittest.TestCase):
|
|||||||
|
|
||||||
@defer.inlineCallbacks
|
@defer.inlineCallbacks
|
||||||
def test_accepted_remote(self):
|
def test_accepted_remote(self):
|
||||||
|
yield self.store.add_presence_list_pending(
|
||||||
|
observer_localpart=self.u_apple.localpart,
|
||||||
|
observed_userid=self.u_cabbage.to_string(),
|
||||||
|
)
|
||||||
|
|
||||||
yield self.mock_federation_resource.trigger("PUT",
|
yield self.mock_federation_resource.trigger("PUT",
|
||||||
"/_matrix/federation/v1/send/1000000/",
|
"/_matrix/federation/v1/send/1000000/",
|
||||||
_make_edu_json("elsewhere", "m.presence_accept",
|
_make_edu_json("elsewhere", "m.presence_accept",
|
||||||
@ -392,14 +391,21 @@ class PresenceInvitesTestCase(unittest.TestCase):
|
|||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
self.datastore.set_presence_list_accepted.assert_called_with(
|
self.assertEquals(
|
||||||
"apple", "@cabbage:elsewhere")
|
[{"observed_user_id": "@cabbage:elsewhere", "accepted": 1}],
|
||||||
|
(yield self.store.get_presence_list(self.u_apple.localpart))
|
||||||
|
)
|
||||||
|
|
||||||
self.mock_start.assert_called_with(
|
self.mock_start.assert_called_with(
|
||||||
self.u_apple, target_user=self.u_cabbage)
|
self.u_apple, target_user=self.u_cabbage)
|
||||||
|
|
||||||
@defer.inlineCallbacks
|
@defer.inlineCallbacks
|
||||||
def test_denied_remote(self):
|
def test_denied_remote(self):
|
||||||
|
yield self.store.add_presence_list_pending(
|
||||||
|
observer_localpart=self.u_apple.localpart,
|
||||||
|
observed_userid="@eggplant:elsewhere",
|
||||||
|
)
|
||||||
|
|
||||||
yield self.mock_federation_resource.trigger("PUT",
|
yield self.mock_federation_resource.trigger("PUT",
|
||||||
"/_matrix/federation/v1/send/1000000/",
|
"/_matrix/federation/v1/send/1000000/",
|
||||||
_make_edu_json("elsewhere", "m.presence_deny",
|
_make_edu_json("elsewhere", "m.presence_deny",
|
||||||
@ -410,32 +416,65 @@ class PresenceInvitesTestCase(unittest.TestCase):
|
|||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
self.datastore.del_presence_list.assert_called_with(
|
self.assertEquals(
|
||||||
"apple", "@eggplant:elsewhere")
|
[],
|
||||||
|
(yield self.store.get_presence_list(self.u_apple.localpart))
|
||||||
|
)
|
||||||
|
|
||||||
@defer.inlineCallbacks
|
@defer.inlineCallbacks
|
||||||
def test_drop_local(self):
|
def test_drop_local(self):
|
||||||
yield self.handler.drop(
|
yield self.store.add_presence_list_pending(
|
||||||
observer_user=self.u_apple, observed_user=self.u_banana)
|
observer_localpart=self.u_apple.localpart,
|
||||||
|
observed_userid=self.u_banana.to_string(),
|
||||||
|
)
|
||||||
|
yield self.store.set_presence_list_accepted(
|
||||||
|
observer_localpart=self.u_apple.localpart,
|
||||||
|
observed_userid=self.u_banana.to_string(),
|
||||||
|
)
|
||||||
|
|
||||||
self.datastore.del_presence_list.assert_called_with(
|
yield self.handler.drop(
|
||||||
"apple", "@banana:test")
|
observer_user=self.u_apple,
|
||||||
|
observed_user=self.u_banana,
|
||||||
|
)
|
||||||
|
|
||||||
|
self.assertEquals(
|
||||||
|
[],
|
||||||
|
(yield self.store.get_presence_list(self.u_apple.localpart))
|
||||||
|
)
|
||||||
|
|
||||||
self.mock_stop.assert_called_with(
|
self.mock_stop.assert_called_with(
|
||||||
self.u_apple, target_user=self.u_banana)
|
self.u_apple, target_user=self.u_banana)
|
||||||
|
|
||||||
@defer.inlineCallbacks
|
@defer.inlineCallbacks
|
||||||
def test_drop_remote(self):
|
def test_drop_remote(self):
|
||||||
yield self.handler.drop(
|
yield self.store.add_presence_list_pending(
|
||||||
observer_user=self.u_apple, observed_user=self.u_cabbage)
|
observer_localpart=self.u_apple.localpart,
|
||||||
|
observed_userid=self.u_cabbage.to_string(),
|
||||||
|
)
|
||||||
|
yield self.store.set_presence_list_accepted(
|
||||||
|
observer_localpart=self.u_apple.localpart,
|
||||||
|
observed_userid=self.u_cabbage.to_string(),
|
||||||
|
)
|
||||||
|
|
||||||
self.datastore.del_presence_list.assert_called_with(
|
yield self.handler.drop(
|
||||||
"apple", "@cabbage:elsewhere")
|
observer_user=self.u_apple,
|
||||||
|
observed_user=self.u_cabbage,
|
||||||
|
)
|
||||||
|
|
||||||
|
self.assertEquals(
|
||||||
|
[],
|
||||||
|
(yield self.store.get_presence_list(self.u_apple.localpart))
|
||||||
|
)
|
||||||
|
|
||||||
@defer.inlineCallbacks
|
@defer.inlineCallbacks
|
||||||
def test_get_presence_list(self):
|
def test_get_presence_list(self):
|
||||||
self.datastore.get_presence_list.return_value = defer.succeed(
|
yield self.store.add_presence_list_pending(
|
||||||
[{"observed_user_id": "@banana:test"}]
|
observer_localpart=self.u_apple.localpart,
|
||||||
|
observed_userid=self.u_banana.to_string(),
|
||||||
|
)
|
||||||
|
yield self.store.set_presence_list_accepted(
|
||||||
|
observer_localpart=self.u_apple.localpart,
|
||||||
|
observed_userid=self.u_banana.to_string(),
|
||||||
)
|
)
|
||||||
|
|
||||||
presence = yield self.handler.get_presence_list(
|
presence = yield self.handler.get_presence_list(
|
||||||
@ -443,29 +482,10 @@ class PresenceInvitesTestCase(unittest.TestCase):
|
|||||||
|
|
||||||
self.assertEquals([
|
self.assertEquals([
|
||||||
{"observed_user": self.u_banana,
|
{"observed_user": self.u_banana,
|
||||||
"presence": OFFLINE},
|
"presence": OFFLINE,
|
||||||
|
"accepted": 1},
|
||||||
], presence)
|
], presence)
|
||||||
|
|
||||||
self.datastore.get_presence_list.assert_called_with("apple",
|
|
||||||
accepted=None
|
|
||||||
)
|
|
||||||
|
|
||||||
self.datastore.get_presence_list.return_value = defer.succeed(
|
|
||||||
[{"observed_user_id": "@banana:test"}]
|
|
||||||
)
|
|
||||||
|
|
||||||
presence = yield self.handler.get_presence_list(
|
|
||||||
observer_user=self.u_apple, accepted=True
|
|
||||||
)
|
|
||||||
|
|
||||||
self.assertEquals([
|
|
||||||
{"observed_user": self.u_banana,
|
|
||||||
"presence": OFFLINE},
|
|
||||||
], presence)
|
|
||||||
|
|
||||||
self.datastore.get_presence_list.assert_called_with("apple",
|
|
||||||
accepted=True)
|
|
||||||
|
|
||||||
|
|
||||||
class PresencePushTestCase(unittest.TestCase):
|
class PresencePushTestCase(unittest.TestCase):
|
||||||
""" Tests steady-state presence status updates.
|
""" Tests steady-state presence status updates.
|
||||||
|
Loading…
Reference in New Issue
Block a user