Example #1
0
    def test_get_bucket_name_and_location(self):
        class _User(object):
            def __init__(self, email):
                self.email = email

        # no exceptions set
        result = get_bucket_name_and_location(_User('*****@*****.**'))
        eq_(result, (settings.SYMBOLS_BUCKET_DEFAULT_NAME,
                     settings.SYMBOLS_BUCKET_DEFAULT_LOCATION))

        exceptions = {'*****@*****.**': 'my-bucket'}
        with self.settings(SYMBOLS_BUCKET_EXCEPTIONS=exceptions):
            # a good regular match
            result = get_bucket_name_and_location(_User('*****@*****.**'))
            eq_(result[0], 'my-bucket')

            # a failing match
            result = get_bucket_name_and_location(
                _User('*****@*****.**'))
            eq_(result[0], settings.SYMBOLS_BUCKET_DEFAULT_NAME)

            # a case insensitive match
            result = get_bucket_name_and_location(_User('*****@*****.**'))
            eq_(result[0], 'my-bucket')

        # now with wildcards
        exceptions = {'*@example.com': 'my-bucket'}
        with self.settings(SYMBOLS_BUCKET_EXCEPTIONS=exceptions):
            # a good match
            result = get_bucket_name_and_location(_User('*****@*****.**'))
            eq_(result[0], 'my-bucket')

            # a failing match
            result = get_bucket_name_and_location(_User('*****@*****.**'))
            eq_(result[0], settings.SYMBOLS_BUCKET_DEFAULT_NAME)

            # a case insensitive match
            result = get_bucket_name_and_location(_User('*****@*****.**'))
            eq_(result[0], 'my-bucket')

        # now with wildcards inside the email
        exceptions = {'start*@example.com': 'my-bucket'}
        with self.settings(SYMBOLS_BUCKET_EXCEPTIONS=exceptions):
            # a failing match
            result = get_bucket_name_and_location(_User('*****@*****.**'))
            eq_(result[0], settings.SYMBOLS_BUCKET_DEFAULT_NAME)

            # a failing match containing 'start'
            result = get_bucket_name_and_location(
                _User('*****@*****.**'))
            eq_(result[0], settings.SYMBOLS_BUCKET_DEFAULT_NAME)

            # a good match and case insensitive
            result = get_bucket_name_and_location(_User('*****@*****.**'))
            eq_(result[0], 'my-bucket')
Example #2
0
    def test_get_bucket_name_and_location(self):

        class _User(object):
            def __init__(self, email):
                self.email = email

        # no exceptions set
        result = get_bucket_name_and_location(
            _User('*****@*****.**')
        )
        eq_(
            result,
            (
                settings.SYMBOLS_BUCKET_DEFAULT_NAME,
                settings.SYMBOLS_BUCKET_DEFAULT_LOCATION
            )
        )

        exceptions = {'*****@*****.**': 'my-bucket'}
        with self.settings(SYMBOLS_BUCKET_EXCEPTIONS=exceptions):
            # a good regular match
            result = get_bucket_name_and_location(
                _User('*****@*****.**')
            )
            eq_(result[0], 'my-bucket')

            # a failing match
            result = get_bucket_name_and_location(
                _User('*****@*****.**')
            )
            eq_(result[0], settings.SYMBOLS_BUCKET_DEFAULT_NAME)

            # a case insensitive match
            result = get_bucket_name_and_location(
                _User('*****@*****.**')
            )
            eq_(result[0], 'my-bucket')

        # now with wildcards
        exceptions = {'*@example.com': 'my-bucket'}
        with self.settings(SYMBOLS_BUCKET_EXCEPTIONS=exceptions):
            # a good match
            result = get_bucket_name_and_location(
                _User('*****@*****.**')
            )
            eq_(result[0], 'my-bucket')

            # a failing match
            result = get_bucket_name_and_location(
                _User('*****@*****.**')
            )
            eq_(result[0], settings.SYMBOLS_BUCKET_DEFAULT_NAME)

            # a case insensitive match
            result = get_bucket_name_and_location(
                _User('*****@*****.**')
            )
            eq_(result[0], 'my-bucket')