Exemplo n.º 1
0
    def test_retrieve_rejected(self):
        # let's create two invites first
        user_three = User(username='******', email='*****@*****.**')
        user_three.put()

        invite_one = Invite(to_player=self.user_one.key,
                            to_player_name=self.user_one.username,
                            from_player=self.user_two.key,
                            from_player_name=self.user_two.username)
        invite_two = Invite(to_player=self.user_one.key,
                            to_player_name=self.user_one.username,
                            from_player=user_three.key,
                            from_player_name=user_three.username,
                            rejected=True)

        invite_one.put()
        invite_two.put()

        # created. Let's retrieve the invites
        resp = self.testapp.post(
            '/_ah/spi/RetrieveInviteHandler.retrieve_invite',
            params=json.dumps({"jwt_token": self.jwt_token_player_one}),
            content_type='application/json')
        self.assertEqual(
            len(json.loads(resp.body)), 1,
            'One invite was not retrieved after creating two and cancelling one'
        )
Exemplo n.º 2
0
    def execute(self):
        """
            1 - Will create the invite in database
            2 - Will insert the sender as attendee1
            3 - If is anonymous will send the invite for confirmation to the organizer
            4 - Else will post the invite to Voiceflows
        """

        invite = Invite()
        copy_over(self, invite)
        invite.put()
        index_invite(invite)

        addOrganizerCommand = self._get_organizer_attendee(invite)
        addOrganizerCommand.execute()

        if not self.user_object:
            '''is anonymous'''
            command = SendConfirmationInviteToOrganizerCommand(invite, self.host)
            command.execute()
            return invite.unique_id

        command = PostInviteToVoiceflowsCommand(invite)
        command.execute()

        return invite.unique_id
Exemplo n.º 3
0
    def test_retrieve_invite(self):
        # let's create two invites first
        user_three = User(username='******', email='*****@*****.**')
        user_three.put()

        invite_one = Invite(to_player=self.user_one.key,
                            to_player_name=self.user_one.username,
                            from_player=self.user_two.key,
                            from_player_name=self.user_two.username)
        invite_two = Invite(to_player=self.user_one.key,
                            to_player_name=self.user_one.username,
                            from_player=user_three.key,
                            from_player_name=user_three.username)

        invite_one.put()
        invite_two.put()

        # created. Let's retrieve the invites
        resp = self.testapp.post(
            '/_ah/spi/RetrieveInviteHandler.retrieve_invite',
            params=json.dumps({"jwt_token": self.jwt_token_player_one}),
            content_type='application/json')
        resp = json.loads(resp.body)
        self.assertEqual(len(resp['invites']), 2,
                         'Two invites were not retrieved after being created')
Exemplo n.º 4
0
 def post(self):
     title_invite = self.request.get('title')
     try:
         count_invite = int(self.request.get('count'))
     except ValueError:
         count_invite = 5
     url_invite = hashlib.md5(u'%s-%s' % (datetime.now(), count_invite)).hexdigest()
     invite = Invite(title=title_invite,
                     url=url_invite,
                     count=count_invite)
     invite.put()
     self.redirect('/invite_view')
Exemplo n.º 5
0
 def post(self):
     name = self.request.get('name')
     email = self.request.get('email')
     invite_code = uuid.uuid4().hex[:invite_code_len].upper()
     while(Invite.query(Invite.code==invite_code).get()):
         invite_code = uuid.uuid4().hex[:invite_code_len].upper()
     invite = Invite(code=invite_code, name=name, email=email)
     invite.put()
     context = {
         'invite': invite,
         'invite_url': webapp2.uri_for('invite', invite_code=invite.code)
     }
     path = os.path.join(os.path.dirname(__file__), './templates/admin/index.html')
     self.response.out.write(template.render(path, context))
Exemplo n.º 6
0
    def test_accept_invite(self):
        # let's create invite first
        invite_one = Invite(to_player=self.user_one.key,
                            to_player_name=self.user_one.username,
                            from_player=self.user_two.key,
                            from_player_name=self.user_two.username)

        invite_one.put()

        resp = self.testapp.post_json(
            '/_ah/spi/CreateInviteHandler.create_invite', {
                "jwt_token": self.jwt_token_player_one,
                "player_two_key": self.user_two.key.urlsafe()
            })
        self.assertIn('200', resp.status)
Exemplo n.º 7
0
    def test_send_invite_already_exists(self):
        # try to send an invite to a user that already has an invite pending please
        # start by creating the invite
        invite = Invite(to_player=self.user_one.key,
                        to_player_name=self.user_one.username,
                        from_player=self.user_two.key,
                        from_player_name=self.user_two.username)
        invite.put()

        # invite created, so let's have user_two try to send an invite to user_one
        resp = self.testapp.post('/_ah/spi/CreateInviteHandler.create_invite',
                                 params=json.dumps({
                                     "jwt_token":
                                     self.jwt_token_player_two,
                                     "player_two_key":
                                     self.user_one.key.urlsafe()
                                 }),
                                 content_type='application/json',
                                 expect_errors=True)
        self.assertIn('400', str(resp))
Exemplo n.º 8
0
    def create_invite(self, request):
        """
        JWT required. Provided the user does not have an active game with the provided player two, creates
        an invite for player two. If player two has already invited the user to play a game, accepts the
        invite and creates a game for them.

        If a game is created, the user will be able to retrieve it from game endpoint and begin playing.
        """
        player_two_key = request.player_two_key
        payload = token.decode_jwt(request.jwt_token)

        try:
            user = Key(urlsafe=payload.get('user_key')).get()
            # grab player two please
            player_two = Key(urlsafe=player_two_key).get()
        except TypeError:
            raise endpoints.BadRequestException('key was unable to be retrieved')
        except ProtocolBufferDecodeError:
            raise endpoints.BadRequestException('key was unable to be retrieved')
        except Exception as e:
            raise endpoints.InternalServerErrorException('An error occurred when attempting to take the turn')

        if player_two is None:
            raise endpoints.BadRequestException('Player does not exist')

        # awesome we have player one and two
        game = Game.query(
            Game.player_one == user.key,
            Game.player_two == player_two.key,
            Game.player_one_completed == False,
            Game.player_two_completed == False).get()

        if game is None:
            game = Game.query(Game.player_one == player_two.key,
                              Game.player_two == user.key,
                              Game.player_one_completed == False,
                              Game.player_two_completed == False).get()

        # if a game exists between these users, they need to finish it first please
        if game is not None:
            # not entirely certain what to set here, as the request wasn't necessarily wrong, but the
            # user already has a game with player_two
            raise endpoints.BadRequestException("An existing game must be finished before starting another one")

        # let's check for an existing invite between these players
        invite = Invite.query(
            Invite.from_player == user.key,
            Invite.to_player == player_two.key,
            Invite.accepted == False,
            Invite.rejected == False
        ).get()

        if invite is not None:
            raise endpoints.BadRequestException(
                "A pending invite must be accepted or declined before creating another one")

        invite = Invite.query(
            Invite.from_player == player_two.key,
            Invite.to_player == user.key,
            Invite.accepted == False,
            Invite.rejected == False
        ).get()

        if invite is not None:
            # awesome! the inviter already has an invitation from the invitee.
            # start a game, and create the turncards for each player
            try:
                game = Game(
                    player_one=player_two.key,
                    player_one_name=player_two.username,
                    player_two=user.key,
                    player_two_name=user.username
                )
                game.put()
                player_one_turncard = TurnCard(
                    owner=player_two.key,
                    game=game.key
                )
                player_two_turncard = TurnCard(
                    owner=user.key,
                    game=game.key
                )
                player_one_turncard.put()
                player_two_turncard.put()

                return CreateInviteResponseForm(
                    game_key=game.key.urlsafe(),
                    game=game.to_form()
                )

            except Exception as e:
                # print e.message
                raise endpoints.InternalServerErrorException('An error occurred while attempting to create a game')

        # alright there are no invites between these players yet so let's make one
        try:
            invite = Invite(
                from_player=user.key,
                from_player_name=user.username,
                to_player=player_two.key,
                to_player_name=player_two.username
            )
            invite.put()
            return CreateInviteResponseForm()
        except:
            raise endpoints.InternalServerErrorException('An error occurred while attempting to create an invite')
Exemplo n.º 9
0
def create_invite(code, org_name):
    org = Organization.query(Organization.name == org_name).get()
    i = Invite(org=org.key, code=code)
    i.put()
Exemplo n.º 10
0
def create_invite(code, org_name):
    org = Organization.query(Organization.name == org_name).get()
    i = Invite(org=org.key, code=code)
    i.put()