Beispiel #1
0
 def test_access_token(self):
     access_token = AccessToken(token='abcdef',
                                expires_at=expires_at(hours=1))
     assert access_token.token == 'abcdef'
     assert access_token.expires_in > 0
     assert access_token.expires_in <= 3600
     assert access_token.is_expired() is False
     assert access_token.params['access_token'] == 'abcdef'
     assert 'expires_at' in access_token.params
Beispiel #2
0
    def create_access_token(self, valid_in_hours=1, data=None):
        """
        Creates an access token.

        TODO: check valid in hours
        TODO: maybe specify how often a token can be used
        """
        data = data or {}
        token = AccessToken(
            token=self.generate(),
            expires_at=expires_at(hours=valid_in_hours),
            data=data)
        return token
Beispiel #3
0
    def setUp(self):
        self.access_token = AccessToken(token="cdefg",
                                        expires_at=expires_at(hours=1))

        self.tokenstore = MemoryTokenStore()
        self.tokenstore.save_token(self.access_token)
        self.empty_tokenstore = MemoryTokenStore()

        self.service = Service(url='http://nowhere/wps',
                               name='test_wps',
                               public=False)
        self.servicestore = MemoryServiceStore()
        self.servicestore.save_service(self.service)

        self.security = OWSSecurity(tokenstore=self.tokenstore,
                                    servicestore=self.servicestore)
Beispiel #4
0
 def test_access_token_with_data(self):
     access_token = AccessToken(token='12345',
                                expires_at=expires_at(hours=1),
                                data={'esgf_token': 'bfghk'})
     assert access_token.data == {'esgf_token': 'bfghk'}
Beispiel #5
0
 def test_invalid_access_token(self):
     access_token = AccessToken(token='abcdef',
                                expires_at=expires_at(hours=-1))
     assert access_token.expires_in == 0
     assert access_token.is_expired() is True
Beispiel #6
0
 def test_missing_token(self):
     with pytest.raises(TypeError):
         AccessToken()
Beispiel #7
0
 def setUp(self):
     self.access_token = AccessToken(token="abcdef", expires_at=expires_at(hours=1))
Beispiel #8
0
 def fetch_by_token(self, token):
     token = self.collection.find_one({'token': token})
     if not token:
         raise AccessTokenNotFound
     return AccessToken(token)