Exemple #1
0
 def test_customN(self):
     """
     The element at the specified index of a sequence is used.
     """
     self.assertThat(
         one(identity, n=1)([1, 2]),
         Equals(2))
     self.assertThat(
         one(identity, n=3)((1, 2)),
         Is(None))
Exemple #2
0
        def POST():
            ourUser = self.db.users.get(self.steamID)
            if not ourUser.superuser:
                returnValue(ForbiddenResource())

            r = q.parse(
                { 'superuser': q.one(q.Boolean)
                }, request.args)
            superuser = r['superuser']

            url = request.content.read().strip()
            steamID = yield getSteamIDFromURL(url, self.steamAPI)
            if not steamID: returnValue(InvalidCommunityURL())

            response = yield self.steamAPI['ISteamUser'].GetPlayerSummaries(
                (steamID,))['response']
            if not len(response['players']):
                returnValue(
                    APIError(http.BAD_REQUEST, 'Steam user does not exist.'))

            try:
                user = self.db.users.add(steamID=steamID, superuser=superuser,
                                         adderSteamID=self.steamID)
            except ValueError:
                returnValue(APIError(http.BAD_REQUEST, 'User already exists.'))

            returnValue(user.toDict())
Exemple #3
0
 def GET():
     args = q.parse({'steamids': q.one(q.Text)}, request.args)
     steamids = args['steamids'].split(',')
     def _tx():
         raw = self.steamAPI['ISteamUser'].GetPlayerSummaries(steamids)
         result = {}
         for player in raw['response']['players']:
             if player.get('gameid'):
                 status = 'in-game'
             else:
                 if player['personastate'] > 0:
                     status = 'online'
                 else:
                     status = 'offline'
             result[player['steamid']] = {
                 'status': status,
                 'personaname': player['personaname'],
                 'avatar': {
                     'small': player['avatar'],
                     'medium': player['avatarmedium'],
                     'large': player['avatarfull']
                 }
             }
         return result
     return deferToThread(_tx)
Exemple #4
0
 def test_sequence(self):
     """
     The first element of a sequence is used.
     """
     self.assertThat(
         one(identity)([1, 2]),
         Equals(1))
     self.assertThat(
         one(identity)((1, 2)),
         Equals(1))
     self.assertThat(
         one(Integer)((b'1', 2)),
         Equals(1))
     self.assertThat(
         one(Integer)([b'1', '2']),
         Equals(1))
Exemple #5
0
 def test_nonSequence(self):
     """
     A non-sequence, or empty sequence, is parsed as ``None``.
     """
     self.assertThat(
         one(identity)(None),
         Is(None))
     self.assertThat(
         one(identity)(42),
         Is(None))
     self.assertThat(
         one(identity)(b'hello'),
         Is(None))
     self.assertThat(
         one(identity)([]),
         Is(None))
Exemple #6
0
 def test_nonexistentArgument(self):
     """
     If a query argument is expected but not found it appears as ``None`` in
     the result.
     """
     self.assertThat(
         parse({b'foo': one(Text)}, {}),
         Equals({b'foo': None}))
Exemple #7
0
    def test_parse(self):
        """
        Parse a query string.
        """
        query = {
            b'foo': [b'1', b'2'],
            b'bar': [],
            b'baz': [b'yes', b'1', b'False', b'huh'],
            b'quux': [b'hello', b'world']}

        self.assertThat(
            parse({b'foo': one(Integer),
                   b'bar': many(Integer),
                   b'baz': many(Boolean),
                   b'quux': many(Text),
                   b'notathing': many(Integer),
                   b'alsonotathing': one(Text)}, query),
            Equals({b'foo': 1,
                    b'bar': [],
                    b'baz': [True, True, False, None],
                    b'quux': [u'hello', u'world'],
                    b'notathing': [],
                    b'alsonotathing': None}))