-
Notifications
You must be signed in to change notification settings - Fork 116
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
66 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
class PresenceStateContainer: | ||
channel_states: dict | ||
|
||
def __init__(self): | ||
self.channel_states = {} | ||
|
||
def register_state(self, state: dict, channels: list): | ||
for channel in channels: | ||
self.channel_states[channel] = state | ||
|
||
def get_state(self, channels: list): | ||
return {**self.get_channels_states(channels)} | ||
|
||
def get_channels_states(self, channels: list): | ||
return {channel: self.channel_states[channel] for channel in channels if channel in self.channel_states} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
from pubnub.event_engine.containers import PresenceStateContainer | ||
|
||
|
||
def test_set_state(): | ||
container = PresenceStateContainer() | ||
container.register_state(state={'state': 'active'}, channels=['c1', 'c2']) | ||
assert container.get_channels_states(['c1', 'c2']) == {'c1': {'state': 'active'}, 'c2': {'state': 'active'}} | ||
assert container.get_state(['c1']) == {'c1': {'state': 'active'}} | ||
|
||
|
||
def test_set_state_with_overwrite(): | ||
container = PresenceStateContainer() | ||
container.register_state(state={'state': 'active'}, channels=['c1']) | ||
container.register_state(state={'state': 'inactive'}, channels=['c1']) | ||
assert container.get_channels_states(['c1']) == {'c1': {'state': 'inactive'}} | ||
assert container.get_state(['c1', 'c2']) == {'c1': {'state': 'inactive'}} |