示例#1
0
def test_if_response_not_204_raise_error():
    token = 'my-test-token-123'
    aut = Automator(token)
    droplet_id = 212611563

    full_url = 'https://api.digitalocean.com/v2/droplets/%s' % droplet_id

    responses.reset()
    error_404_response(full_url)

    with pytest.raises(DestroyDropletError):
        aut.destroy_droplet(droplet_id)
示例#2
0
def test_if_response_status_204_return_completed():
    token = 'my-test-token-123'
    aut = Automator(token)
    droplet_id = 212611563

    # response mock w/ 204 response
    responses.reset()
    destroy_droplet_success_response(droplet_id)

    result = aut.destroy_droplet(droplet_id)
    assert result == 'completed'
示例#3
0
def test_assert_requests_delete_is_called_once_with_args():
    token = 'my-test-token-123'
    aut = Automator(token)
    droplet_id = 212611563

    full_url = 'https://api.digitalocean.com/v2/droplets/%s' % droplet_id

    # stash to mock
    stashed2 = aut.requests.delete

    # mocks
    responses.reset()
    destroy_droplet_success_response(droplet_id)
    mocked_response = requests.delete(full_url)
    aut.requests.delete = MagicMock(return_value=mocked_response)

    # test
    aut.destroy_droplet(droplet_id)
    aut.requests.delete.assert_called_once_with(full_url)

    # pop stashed
    aut.requests.delete = stashed2
import ipdb
from pydoautomator import Automator
import os

digital_ocean_token = os.getenv("DO_TOKEN")

# requires ENV
name = os.getenv('DROPLET_HOST')
floating = os.getenv('FLOATING_IP')
snapshot = os.getenv('SNAPSHOT_ID')


aut = Automator(digital_ocean_token)

droplets = aut.get_all_droplets()

print('trying to turn off droplet named %s' % name )
for droplet in droplets:
    if droplet['name'] == name:
        droplet_id = droplet['id']
        print('turning off droplet id %s' % droplet_id)
        aut.turnoff_droplet(droplet_id)
        print('destroying droplet id %s' % droplet_id)
        aut.destroy_droplet(droplet_id)
import ipdb
from pydoautomator import Automator
import os

digital_ocean_token = os.getenv("DO_TOKEN")

# requires ENV
name = os.getenv('DROPLET_HOST')
floating = os.getenv('FLOATING_IP')
snapshot = os.getenv('SNAPSHOT_ID')

aut = Automator(digital_ocean_token)

droplets = aut.get_all_droplets()

for droplet in droplets:
    if droplet['name'] == name:
        aut.turnoff_droplet(droplet['id'])
        aut.destroy_droplet(droplet['id'])
def step_impl(context):
    aut = Automator(context.token)
    aut.destroy_droplet(context.droplet_id)