Beispiel #1
0
    def test_replace_configuration(self):
        client = Azion(token)
        recorder = betamax.Betamax(client.session)

        with recorder.use_cassette('Configuration_replace'):
            configuration = client.replace_configuration(
                1528252734,
                name='Dummy configuration',
                delivery_protocol='http,https')

        assert isinstance(configuration, Configuration)
        assert configuration.delivery_protocol == 'http,https'
Beispiel #2
0
    def test_purge_cache_key(self):
        mocked_session = create_mocked_session()
        client = Azion(session=mocked_session)

        # URLs to be purged
        urls = ['www.domain.com/', 'www.domain.com/test.js']
        client.purge_cache_key(urls, 'delete')
        mocked_session.post.assert_called_once_with(
            'https://api.azion.net/purge/cachekey',
            json={
                'urls': urls,
                'method': 'delete'
            })
Beispiel #3
0
    def test_purge_wildcard(self):
        mocked_session = create_mocked_session()
        client = Azion(session=mocked_session)

        # URL to be purged
        url = 'www.domain.com/photos/*'

        client.purge_wildcard(url, 'delete')
        mocked_session.post.assert_called_once_with(
            'https://api.azion.net/purge/wildcard',
            json={
                'urls': [url],
                'method': 'delete'
            })
Beispiel #4
0
 def test_create_configuration(self):
     mocked_session = create_mocked_session()
     client = Azion(session=mocked_session)
     client.create_configuration('Dummy configuration', 'www.example.com',
                                 'ww2.example.com')
     mocked_session.post.assert_called_once_with(
         'https://api.azion.net/content_delivery/configurations',
         json={
             'name': 'Dummy configuration',
             'origin_address': 'www.example.com',
             'origin_host_header': 'ww2.example.com',
             'cname_access_only': False,
             'delivery_protocol': 'http',
             'origin_protocol_policy': 'preserve',
             'browser_cache_settings': False,
             'browser_cache_settings_maximum_ttl': 0,
             'cdn_cache_settings': 'honor',
             'cdn_cache_settings_maximum_ttl': 0
         })
Beispiel #5
0
    def test_purge_url(self):
        client = Azion(token)
        recorder = betamax.Betamax(client.session)

        authorized_urls = [
            'www.maugzoide.com/foo.jgp', 'www.maugzoide.com/bar.jgp'
        ]
        forbidden_urls = ['www.notauthorize.com/mistaken.jgp']
        urls = authorized_urls + forbidden_urls

        with recorder.use_cassette('Purge_url'):
            purge = client.purge_url(urls)

        succeed_urls = itertools.chain(
            *[response['urls'] for response in purge.succeed().values()])
        assert sorted(authorized_urls) == sorted(list(succeed_urls))

        failed_urls = itertools.chain(
            *[response['urls'] for response in purge.failed().values()])
        assert sorted(forbidden_urls) == sorted(list(failed_urls))
Beispiel #6
0
    def test_purge_url(self, mock_handler):
        mocked_session = create_mocked_session()
        client = Azion(session=mocked_session)
        mock_handler.return_value = [{
            "status":
            "HTTP/1.1 201 CREATED",
            "urls":
            ["http://www.domain.com/", "http://www.domain.com/test.js"],
            "details":
            "Purge request successfully created"
        }]

        # URLs to be purged
        urls = ['www.domain.com/', 'www.domain.com/test.js']
        assert client.purge_url(urls, 'delete')
        mocked_session.post.assert_called_once_with(
            'https://api.azion.net/purge/url',
            json={
                'urls': urls,
                'method': 'delete'
            })
Beispiel #7
0
    def test_create_configuration(self):
        client = Azion(token)
        recorder = betamax.Betamax(client.session)

        with recorder.use_cassette('Configuration_create'):
            configuration = client.create_configuration(
                'Dummy configuration',
                'www.example.com',
                'ww2.example.com',
                cname=['www.example-cname.com'],
                delivery_protocol='http')

        assert isinstance(configuration, Configuration)
        assert configuration.active is True
        assert configuration.id
        assert configuration.cname == ['www.example-cname.com']
        assert configuration.digital_certificate is None
        assert configuration.rawlogs is False
        assert configuration.delivery_protocol == 'http'
        assert configuration.cname_access_only is False
        assert configuration.name == 'Dummy configuration'
        assert configuration.domain_name
Beispiel #8
0
    def test_create_origin(self):
        mocked_session = create_mocked_session()
        client = Azion(session=mocked_session)

        client.create_origin(configuration_id=1,
                             name='Dummy origin',
                             origin_type='single_origin',
                             method=None,
                             host_header='www.example.com',
                             origin_protocol_policy='http',
                             addresses=[{
                                 'address': 'www.myorigin.com',
                                 'weight': None,
                                 'server_role': 'primary',
                             }],
                             connection_timeout=60,
                             timeout_between_bytes=120)
        mocked_session.post.assert_called_once_with(
            'https://api.azion.net/content_delivery/configurations/1/origins',
            json={
                'name':
                'Dummy origin',
                'origin_type':
                'single_origin',
                'host_header':
                'www.example.com',
                'origin_protocol_policy':
                'http',
                'addresses': [{
                    'address': 'www.myorigin.com',
                    'weight': None,
                    'server_role': 'primary',
                }],
                'connection_timeout':
                60,
                'timeout_between_bytes':
                120
            })
Beispiel #9
0
def authorize(username, password):
    azion = Azion()
    return azion.authorize(username, password)
Beispiel #10
0
def login(token):
    azion = Azion(token)
    return azion
Beispiel #11
0
 def test_delete_configuration(self):
     mocked_session = create_mocked_session()
     client = Azion(session=mocked_session)
     client.delete_configuration(1)
     mocked_session.delete.assert_called_once_with(
         'https://api.azion.net/content_delivery/configurations/1')
Beispiel #12
0
 def test_list_configurations(self):
     mocked_session = create_mocked_session()
     client = Azion(session=mocked_session)
     client.list_configurations()
     mocked_session.get.assert_called_once_with(
         'https://api.azion.net/content_delivery/configurations')
Beispiel #13
0
 def test_authorize(self):
     mocked_session = create_mocked_session()
     client = Azion(session=mocked_session)
     client.authorize('foo', 'bar')
     mocked_session.post.assert_called_once_with(
         'https://api.azion.net/tokens', data={}, auth=('foo', 'bar'))
Beispiel #14
0
 def test_login_using_token(self):
     mocked_session = create_mocked_session()
     client = Azion(session=mocked_session)
     client.login(token='foobar')
     mocked_session.token_auth.assert_called_once_with(token='foobar')
Beispiel #15
0
    def test_delete_configuration(self):
        client = Azion(token)
        recorder = betamax.Betamax(client.session)

        with recorder.use_cassette('Configuration_delete'):
            assert client.delete_configuration(1528252734)