def test_cleanupAssociations(self):
        """Tests the NDBOpenIDStore._delete_expired() method."""

        number_of_valid = 5
        number_of_expired = 5

        # populate datastore with valid associations
        for i in range(number_of_valid):
            url = 'url-{}'.format(i)

            association = Association(handle='handle_{}'.format(i),
                                      secret='secret',
                                      issued=int(time.time()),
                                      lifetime=3600,
                                      assoc_type='HMAC-SHA1')

            NDBOpenIDStore.storeAssociation(url, association)

        # check whether the valid ones are there
        assert NDBOpenIDStore.query().count() == number_of_valid

        # populate datastore with expired associations
        for i in range(number_of_valid, number_of_expired + number_of_valid):
            url = 'url-{}'.format(i)

            # create association mock beyond expiration
            association = Association(handle='handle_{}'.format(i),
                                      secret='secret',
                                      issued=int(time.time()) - 3600,
                                      lifetime=1000,
                                      assoc_type='HMAC-SHA1')

            NDBOpenIDStore.storeAssociation(url, association)

        # check whether the expired ones were added
        assert NDBOpenIDStore.query().count(
        ) == number_of_expired + number_of_valid

        # call the tested method
        removed = NDBOpenIDStore.cleanupAssociations()

        # check whether the method returned the correct number of deleted
        assert removed == number_of_expired

        # get remaining
        remaining = NDBOpenIDStore.query().fetch()

        # check the number of remaining
        assert len(remaining) == number_of_valid

        # check whether all the remaining are valid
        for entity in remaining:
            assert entity.expiration_date >= datetime.datetime.now()

        # call the tested method again
        removed = NDBOpenIDStore.cleanupAssociations()

        # removed should now be 0
        assert removed == 0

        # valid should still be there
        assert NDBOpenIDStore.query().count() == number_of_valid
Exemple #2
0
 def test_cleanupAssociations(self):
     """Tests the NDBOpenIDStore._delete_expired() method."""
     
     number_of_valid = 5
     number_of_expired = 5
     
     # populate datastore with valid associations
     for i in range(number_of_valid):
         url = 'url-{}'.format(i)
         
         association = Association(handle='handle_{}'.format(i),
                                   secret='secret',
                                   issued=int(time.time()),
                                   lifetime=3600,
                                   assoc_type='HMAC-SHA1')
         
         NDBOpenIDStore.storeAssociation(url, association)
     
     # check whether the valid ones are there
     assert NDBOpenIDStore.query().count() == number_of_valid
     
     
     # populate datastore with expired associations
     for i in range(number_of_valid, number_of_expired + number_of_valid):
         url = 'url-{}'.format(i)
         
         # create association mock beyond expiration
         association = Association(handle='handle_{}'.format(i),
                                   secret='secret',
                                   issued=int(time.time()) - 3600,
                                   lifetime=1000,
                                   assoc_type='HMAC-SHA1')
         
         NDBOpenIDStore.storeAssociation(url, association)
     
     # check whether the expired ones were added
     assert NDBOpenIDStore.query().count() == number_of_expired + number_of_valid
     
     # call the tested method
     removed = NDBOpenIDStore.cleanupAssociations()
     
     # check whether the method returned the correct number of deleted
     assert removed == number_of_expired
     
     # get remaining
     remaining = NDBOpenIDStore.query().fetch()
     
     # check the number of remaining
     assert len(remaining) == number_of_valid
     
     # check whether all the remaining are valid
     for entity in remaining:
         assert entity.expiration_date >= datetime.datetime.now()
     
     # call the tested method again
     removed = NDBOpenIDStore.cleanupAssociations()
     
     # removed should now be 0
     assert removed == 0
     
     # valid should still be there
     assert NDBOpenIDStore.query().count() == number_of_valid