Ejemplo n.º 1
0
    def test_create_origin(self):
        client = Azion(token)
        recorder = betamax.Betamax(client.session)

        with recorder.use_cassette('Origin_create'):
            origin = client.create_origin(
                configuration_id=1501191440,
                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)

        assert isinstance(origin, Origin)
        assert origin.name == 'Dummy origin'
        assert origin.origin_type == 'single_origin'
        assert origin.method == ''
        assert origin.host_header == 'www.example.com'
        assert origin.origin_protocol_policy == 'http'
        assert origin.addresses[0].address == 'www.myorigin.com'
        assert origin.addresses[0].weight is None
        assert origin.addresses[0].server_role == 'primary'
        assert origin.addresses[0].is_active is True
        assert origin.connection_timeout == 60
        assert origin.timeout_between_bytes == 120
Ejemplo n.º 2
0
    def test_list_origins(self):
        mocked_session = create_mocked_session()
        client = Azion(session=mocked_session)

        client.list_origins(1)
        mocked_session.get.assert_called_once_with(
            'https://api.azion.net/content_delivery/configurations/1/origins')
Ejemplo n.º 3
0
    def test_get_configuration(self):
        client = Azion(token)
        recorder = betamax.Betamax(client.session)

        with recorder.use_cassette('Configuration_get'):
            configuration = client.get_configuration(1528252734)

        assert isinstance(configuration, Configuration)
Ejemplo n.º 4
0
    def test_purge_wildcard(self):
        client = Azion(token)
        recorder = betamax.Betamax(client.session)

        url = 'www.maugzoide.com/static/img/*'

        with recorder.use_cassette('Purge_wildcard'):
            assert client.purge_wildcard(url)
Ejemplo n.º 5
0
    def test_update_configuration(self):
        client = Azion(token)
        recorder = betamax.Betamax(client.session)

        with recorder.use_cassette('Configuration_partial_update'):
            configuration = client.partial_update_configuration(
                1528252734, delivery_protocol='http,https')

        assert isinstance(configuration, Configuration)
        assert configuration.delivery_protocol == 'http,https'
Ejemplo n.º 6
0
    def test_list_origins(self):
        client = Azion(token)
        recorder = betamax.Betamax(client.session)

        with recorder.use_cassette('Origin_list'):
            origins = client.list_origins(1501191440)

        assert origins
        assert isinstance(origins, list)
        assert all(isinstance(origin, Origin) for origin in origins)
Ejemplo n.º 7
0
    def test_purge_cache_key(self):
        client = Azion(token)
        recorder = betamax.Betamax(client.session)

        urls = [
            'www.maugzoide.com/@@cookie_name=foobar',
            'www.maugzoide.com/profile.jpg@@'
        ]

        with recorder.use_cassette('Purge_cachekey'):
            assert client.purge_cache_key(urls)
Ejemplo n.º 8
0
 def test_replace_configuration(self):
     mocked_session = create_mocked_session()
     client = Azion(session=mocked_session)
     client.replace_configuration(1,
                                  name='My cool configuration',
                                  active=False)
     mocked_session.put.assert_called_once_with(
         'https://api.azion.net/content_delivery/configurations/1',
         json={
             'name': 'My cool configuration',
             'active': False
         })
Ejemplo n.º 9
0
    def test_list_configurations(self):
        client = Azion(token)
        recorder = betamax.Betamax(client.session)

        with recorder.use_cassette('Configuration_list'):
            configurations = client.list_configurations()

        assert configurations
        assert isinstance(configurations, list)
        assert all(
            isinstance(configuration, Configuration)
            for configuration in configurations)
Ejemplo n.º 10
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'
Ejemplo n.º 11
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'
            })
Ejemplo n.º 12
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'
            })
Ejemplo n.º 13
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
         })
Ejemplo n.º 14
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))
Ejemplo n.º 15
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'
            })
Ejemplo n.º 16
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
Ejemplo n.º 17
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
            })
Ejemplo n.º 18
0
def authorize(username, password):
    azion = Azion()
    return azion.authorize(username, password)
Ejemplo n.º 19
0
def login(token):
    azion = Azion(token)
    return azion
Ejemplo n.º 20
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)
Ejemplo n.º 21
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')
Ejemplo n.º 22
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'))
Ejemplo n.º 23
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')