예제 #1
0
def test_update_image(authenticated_client):
    with patch('tasks.build_and_push.AsyncResult', mock_async_result1):
        rv = authenticated_client.post('/image',
                                       data={
                                           'dockerfile': update_file,
                                           'name': 'some_name'
                                       })
        assert rv.status_code == 200
        build_id = json.loads(rv.data.decode('utf-8'))['build_id']
        build_data = poll_for_image_id(authenticated_client, build_id)
    image_id = build_data['id']

    new_name = 'some_new_name'
    with patch('tasks.build_and_push.AsyncResult', mock_async_result2):
        rv = authenticated_client.put('/image/%s' % image_id,
                                      data={
                                          'dockerfile': sample_dockerfile,
                                          'name': new_name
                                      })
        build_data = poll_for_image_id(authenticated_client, build_id,
                                       image_id)
    img = Image.query.filter_by(id=image_id).first()
    assert img.name == new_name
    assert img.dockerfile == sample_dockerfile

    with patch('tasks.build_and_push.AsyncResult', mock_async_result):
        rv = authenticated_client.put('/image/999',
                                      data={
                                          'dockerfile': sample_dockerfile,
                                          'name': new_name
                                      })
    data = json.loads(rv.data.decode('utf-8'))
    assert data.get('error', None)
예제 #2
0
def test_create_job_with_attachment(authenticated_client):
    with patch('docker.Client', MockClient):
        rv = authenticated_client.post('/image',
                                       data={'dockerfile': sample_dockerfile,
                                             'name': 'hellozeworld'})
    assert rv.status_code == 200
    build_id = json.loads(rv.data.decode('utf-8'))['build_id']
    build_data = poll_for_image_id(authenticated_client, build_id)
    image_id = build_data['id']

    rv = authenticated_client.post('/pipeline',
                                   data={'name': 'my not so first pipeline'})
    assert rv.status_code == 200
    pipeline_id = json.loads(rv.data.decode('utf-8'))['id']

    attachments = [(open(os.path.join(ROOT_DIR, "data", "file1.txt"), "rb"),
                    'test1.txt'),
                   (open(os.path.join(ROOT_DIR, "data", "file2.txt"), "rb"),
                    'test2.txt')]
    rv = authenticated_client.post('/pipeline/%s/job' % pipeline_id,
                                   data={'image_id': str(image_id),
                                         'command': 'echo hello world',
                                         'attachments': attachments})
    assert rv.status_code == 200
    job_id = json.loads(rv.data.decode('utf-8'))['id']
    attachments_path = Job.query.filter_by(id=job_id).one().attachments_path
    assert os.path.exists(attachments_path)
    assert len(os.listdir(attachments_path)) == 2
예제 #3
0
def test_create_job(authenticated_client):
    with patch('docker.Client', MockClient):
        rv = authenticated_client.post('/image',
                                       data={'dockerfile': sample_dockerfile,
                                             'name': 'hellozeworld'})
    assert rv.status_code == 200
    build_id = json.loads(rv.data.decode('utf-8'))['build_id']
    build_data = poll_for_image_id(authenticated_client, build_id)
    image_id = build_data['id']

    rv = authenticated_client.post('/pipeline',
                                   data={'name': 'my first pipeline'})
    assert rv.status_code == 200
    pipeline_id = json.loads(rv.data.decode('utf-8'))['id']

    authenticated_client.post('/pipeline/%s/job' % pipeline_id,
                              data={'image_id': image_id,
                                    'command': 'echo hello world'})
    assert rv.status_code == 200
    json.loads(rv.data.decode('utf-8'))['id']

    rv = authenticated_client.post('/pipeline/%s/job' % pipeline_id,
                                   data={'image_id': 999,
                                         'command': 'echo hello world'})
    data = json.loads(rv.data.decode('utf-8'))
    assert data.get('error', None)
    assert data['error'] == "Image not found"

    rv = authenticated_client.post('/pipeline/%s/job' % 999,
                                   data={'image_id': 999,
                                         'command': 'echo hello world'})
    data = json.loads(rv.data.decode('utf-8'))
    assert data.get('error', None)
    assert data['error'] == "Pipeline not found"
예제 #4
0
def test_get_job_details(authenticated_client):
    client = authenticated_client
    data = {'command': 'echo hello world'}
    with patch('docker.Client', MockClient):
        rv = client.post('/image',
                         data={'dockerfile': sample_dockerfile,
                               'name': 'hellozeworld'})
        build_id = json.loads(rv.data.decode('utf-8'))['build_id']
        build_data = poll_for_image_id(authenticated_client, build_id)
        image_id = build_data['id']

        rv = client.post('/pipeline',
                         data={'name': 'my first pipeline'})
        pipeline_id1 = json.loads(rv.data.decode('utf-8'))['id']
        rv = client.post('/pipeline',
                         data={'name': 'my first pipeline'})
        pipeline_id2 = json.loads(rv.data.decode('utf-8'))['id']

        data['image_id'] = str(image_id)
        client.post('/pipeline/%s/job' % pipeline_id2,
                    data=data)
        rv = client.post('/pipeline/%s/job' % pipeline_id1,
                         data=data)
        client.post('/pipeline/%s/job' % pipeline_id1,
                    data=data)

        jid2 = json.loads(rv.data.decode('utf-8'))['id']

        rv = client.get("/pipeline/%s/job" % (pipeline_id1))
        keys = list(json.loads(rv.data.decode('utf-8')).keys())
        assert len(keys) == 2

        rv = client.get("/pipeline/%s/job/%s" % (pipeline_id1, jid2))
        keys = list(json.loads(rv.data.decode('utf-8')).keys())
        assert str(jid2) in keys
예제 #5
0
 def create_image(name, client):
     rv = client.post('/image',
                      data={
                          'dockerfile': sample_dockerfile,
                          'name': name
                      })
     build_id = json.loads(rv.data.decode('utf-8'))['build_id']
     build_data = poll_for_image_id(client, build_id)
     image_id = build_data['id']
     return str(image_id), name
예제 #6
0
def test_create_image(authenticated_client):
    rv = authenticated_client.post('/image',
                                   data={
                                       'dockerfile': sample_dockerfile,
                                       'name': 'hellozeworld'
                                   })
    assert rv.status_code == 200
    build_id = json.loads(rv.data.decode('utf-8'))['build_id']
    build_data = poll_for_image_id(authenticated_client, build_id)
    image_id = build_data['id']
    assert image_id is not None

    with patch('tasks.build_and_push.AsyncResult', mock_broken_async_result):
        rv = authenticated_client.post('/image',
                                       data={
                                           'dockerfile': sample_dockerfile,
                                           'name': 'hellozeworld'
                                       })
        assert rv.status_code == 200
        build_id = json.loads(rv.data.decode('utf-8'))['build_id']
        data = poll_for_image_id(authenticated_client, build_id)
        assert data.get("error")
        assert data["output"] == [
            "some output saying your "
            "build is unsuccessful"
        ]

    url = os.path.join(ROOT_DIR, "data", "repo")
    rm_hg(url)
    repo = hgapi.hgapi.Repo(url)
    repo.hg_init()
    repo.hg_add()
    repo.hg_commit("init", user='******')
    data = {"repo_url": url, "name": "some_image"}
    rv = authenticated_client.post('/image', data=data)
    assert rv.status_code == 200
    build_id = json.loads(rv.data.decode('utf-8'))['build_id']
    build_data = poll_for_image_id(authenticated_client, build_id)
    image_id = build_data['id']
    assert image_id is not None
    rm_hg(url)
예제 #7
0
def test_delete_image(authenticated_client):
    rv = authenticated_client.post('/image',
                                   data={
                                       'dockerfile': sample_dockerfile,
                                       'name': 'hellozeworld'
                                   })
    assert rv.status_code == 200
    build_id = json.loads(rv.data.decode('utf-8'))['build_id']
    build_data = poll_for_image_id(authenticated_client, build_id)
    image_id = build_data['id']

    authenticated_client.delete('/image/%s' % image_id)
    assert not Image.query.filter_by(id=image_id).first()

    rv = authenticated_client.delete('/image/999')
    data = json.loads(rv.data.decode('utf-8'))
    assert data.get('error', None)