def test_party_member_joined(self): test_channel = 'test-channel' Group(PartyConsumer.LOBBY_GROUP.format(self.party.pk)).add(test_channel) PartyConsumer.party_member_joined(party_member=self.party_member) result = self.get_next_message(test_channel, require=True) self.assertEqual( json.loads(result.content['text']), { 'party_member': model_to_dict(self.party_member), 'action': PartyConsumer.PARTY_MEMBER_JOINED, } )
def stop(self): """ Stops the party and send a notification to the party members :return: :rtype: """ for thread in threading.enumerate(): if str(thread.ident) == str(self.gamethread_ident): thread.stop() self.started = False self.save() PartyConsumer.party_stopped(self.id)
def start(self): """ Start the party and send a notification to the party members :return: :rtype: """ gamethread = GameThread(self) gamethread.start() self.started = True self.gamethread_ident = gamethread.ident self.save() PartyConsumer.party_started(self.id)
def run(self): while self.running: sleep(1) self.tick += 1 print('Party: {} is running...'.format(self.party)) if self.tick == 7: selected_party_members = self.random_party_members() selected_teams = self.random_teams(selected_party_members) PartyConsumer.game_starts( self.party, selected_party_members, selected_teams, self.random_game(), )
def delete(self, *args, **kwargs): PartyConsumer.party_member_leaved(self) super().delete(*args, **kwargs)
def save(self, *args, **kwargs): if not self.pk: super().save(*args, **kwargs) PartyConsumer.party_member_joined(self) else: super().save(*args, **kwargs)
from async.consumers.party_consumer import PartyConsumer channel_routing = [ PartyConsumer.as_route(path=r'^/party/(?P<party_id>[^/]+)/$'), ]