Ejemplo n.º 1
0
def prindex(mapp, new_prindex, targetindex, testapp):
    content1 = mapp.makepkg("pkg-1.0.tar.gz", b"content1", "pkg", "1.0")
    mapp.upload_file_pypi("pkg-1.0.tar.gz",
                          content1,
                          "pkg",
                          "1.0",
                          set_whitelist=False)
    testapp.patch_json(new_prindex.index,
                       ['states+=pending', 'messages+=Please approve'])
    return new_prindex
Ejemplo n.º 2
0
def test_submit_pr_index(mapp, new_prindex, targetindex, testapp):
    content1 = mapp.makepkg("pkg-1.0.tar.gz", b"content1", "pkg", "1.0")
    mapp.upload_file_pypi("pkg-1.0.tar.gz",
                          content1,
                          "pkg",
                          "1.0",
                          set_whitelist=False)
    r = testapp.patch_json(new_prindex.index,
                           ['states+=pending', 'messages+=Please approve'])
    r = testapp.get_json(new_prindex.index)
    result = r.json['result']
    assert result['type'] == 'pr'
    assert result['acl_upload'] == ['pruser']
    assert result['bases'] == [targetindex.stagename]
    assert result['messages'] == ['New pull request', 'Please approve']
    assert result['states'] == ['new', 'pending']
Ejemplo n.º 3
0
def test_approve_nonvolatile_conflict(mapp, prindex, targetindex, testapp):
    # make target index non volatile
    mapp.login(targetindex.stagename.split('/')[0], "123")
    testapp.patch_json(targetindex.index, ['volatile=False'])
    # the prindex has one project
    r = testapp.get_json(prindex.index)
    assert r.json['result']['projects'] == ['pkg']
    # the targetindex has no project yet
    r = testapp.get_json(targetindex.index)
    assert r.json['result']['projects'] == []
    # the targetindex is actually non volatile
    assert r.json['result']['volatile'] is False
    # we approve the pr index
    headers = {'X-Devpi-PR-Serial': '8'}
    r = testapp.patch_json(prindex.index,
                           ['states+=approved', 'messages+=Approve'],
                           headers=headers)
    # now the targetindex should have the project
    r = testapp.get_json(targetindex.index)
    assert r.json['result']['projects'] == ['pkg']
    # create another pr index with conflicting pkg
    mapp.login(prindex.stagename.split('/')[0], "123")
    otherprindex = mapp.create_index("other",
                                     indexconfig=dict(
                                         type="pr",
                                         states="new",
                                         messages="New pull request",
                                         bases=[targetindex.stagename]))
    content1 = mapp.makepkg("pkg-1.0.tar.gz", b"content1", "pkg", "1.0")
    mapp.upload_file_pypi("pkg-1.0.tar.gz",
                          content1,
                          "pkg",
                          "1.0",
                          set_whitelist=False)
    r = testapp.patch_json(otherprindex.index,
                           ['states+=pending', 'messages+=Please approve'])
    serial = r.headers['X-Devpi-Serial']
    headers = {'X-Devpi-PR-Serial': serial}
    mapp.login(targetindex.stagename.split('/')[0], "123")
    r = testapp.patch_json(otherprindex.index,
                           ['states+=approved', 'messages+=Approve'],
                           headers=headers,
                           expect_errors=True)
    assert r.status_code == 409
    assert r.json[
        'message'] == "pkg-1.0.tar.gz already exists in non-volatile index"
Ejemplo n.º 4
0
def test_pr_list_approved(mapp, new_prindex, targetindex, testapp):
    content1 = mapp.makepkg("pkg-1.0.tar.gz", b"content1", "pkg", "1.0")
    mapp.upload_file_pypi("pkg-1.0.tar.gz",
                          content1,
                          "pkg",
                          "1.0",
                          set_whitelist=False)
    r = testapp.patch_json(new_prindex.index,
                           ['states+=pending', 'messages+=Please approve'])
    r = testapp.get_json(targetindex.index + "/+pr-list")
    result = r.json['result']
    assert result == {
        'pending': {
            'pruser': [{
                'name': 'index',
                'base': 'targetuser/targetindex',
                'last_serial': 8,
                'by': ['pruser', 'pruser'],
                'states': ['new', 'pending'],
                'messages': ['New pull request', 'Please approve']
            }]
        }
    }
    r = testapp.get_json("/pruser/+pr-list")
    result = r.json['result']
    assert result == {
        'pending': {
            'pruser': [{
                'name': 'index',
                'base': 'targetuser/targetindex',
                'last_serial': 8,
                'by': ['pruser', 'pruser'],
                'states': ['new', 'pending'],
                'messages': ['New pull request', 'Please approve']
            }]
        }
    }
    # we approve the pr index
    mapp.login(targetindex.stagename.split('/')[0], "123")
    headers = {'X-Devpi-PR-Serial': '8'}
    r = testapp.patch_json(new_prindex.index,
                           ['states+=approved', 'messages+=Approve'],
                           headers=headers)
    r = testapp.get_json(targetindex.index + "/+pr-list")
    result = r.json['result']
    assert result == {
        'approved': {
            'pruser': [{
                'name':
                'index',
                'base':
                'targetuser/targetindex',
                'last_serial':
                9,
                'by': ['pruser', 'pruser', 'targetuser'],
                'states': ['new', 'pending', 'approved'],
                'messages': ['New pull request', 'Please approve', 'Approve']
            }]
        }
    }
    r = testapp.get_json("/pruser/+pr-list")
    result = r.json['result']
    assert result == {
        'approved': {
            'pruser': [{
                'name':
                'index',
                'base':
                'targetuser/targetindex',
                'last_serial':
                9,
                'by': ['pruser', 'pruser', 'targetuser'],
                'states': ['new', 'pending', 'approved'],
                'messages': ['New pull request', 'Please approve', 'Approve']
            }]
        }
    }
Ejemplo n.º 5
0
def test_pr_list_serial(mapp, new_prindex, targetindex, testapp):
    r = testapp.get_json(targetindex.index + "/+pr-list")
    result = r.json['result']
    assert result == {
        'new': {
            'pruser': [{
                'name': 'index',
                'base': 'targetuser/targetindex',
                'last_serial': 5,
                'by': ['pruser'],
                'states': ['new'],
                'messages': ['New pull request']
            }]
        }
    }
    content1 = mapp.makepkg("pkg-1.0.tar.gz", b"content1", "pkg", "1.0")
    mapp.upload_file_pypi("pkg-1.0.tar.gz",
                          content1,
                          "pkg",
                          "1.0",
                          set_whitelist=False)
    r = testapp.get_json(targetindex.index + "/+pr-list")
    result = r.json['result']
    # serial 6 is registration, serial 7 is the upload
    assert result == {
        'new': {
            'pruser': [{
                'name': 'index',
                'base': 'targetuser/targetindex',
                'last_serial': 7,
                'by': ['pruser'],
                'states': ['new'],
                'messages': ['New pull request']
            }]
        }
    }
    r = testapp.patch_json(new_prindex.index,
                           ['states+=pending', 'messages+=Please approve'])
    r = testapp.get_json(targetindex.index + "/+pr-list")
    result = r.json['result']
    # serial 8 is submit
    assert result == {
        'pending': {
            'pruser': [{
                'name': 'index',
                'base': 'targetuser/targetindex',
                'last_serial': 8,
                'by': ['pruser', 'pruser'],
                'states': ['new', 'pending'],
                'messages': ['New pull request', 'Please approve']
            }]
        }
    }
    content2 = mapp.makepkg("pkg-1.0.zip", b"content2", "pkg", "1.0")
    mapp.upload_file_pypi("pkg-1.0.zip",
                          content2,
                          "pkg",
                          "1.0",
                          set_whitelist=False)
    r = testapp.get_json(targetindex.index + "/+pr-list")
    result = r.json['result']
    # serial 9 is second upload
    assert result == {
        'pending': {
            'pruser': [{
                'name': 'index',
                'base': 'targetuser/targetindex',
                'last_serial': 9,
                'by': ['pruser', 'pruser'],
                'states': ['new', 'pending'],
                'messages': ['New pull request', 'Please approve']
            }]
        }
    }
    mapp.create_index("other",
                      indexconfig=dict(type="pr",
                                       states="new",
                                       messages="Different pull request",
                                       bases=[targetindex.stagename]))
    r = testapp.get_json(targetindex.index + "/+pr-list")
    result = r.json['result']
    # serial 10 is the new pr index, the old index should still be at 9
    assert result == {
        'pending': {
            'pruser': [{
                'name': 'index',
                'base': 'targetuser/targetindex',
                'last_serial': 9,
                'by': ['pruser', 'pruser'],
                'states': ['new', 'pending'],
                'messages': ['New pull request', 'Please approve']
            }]
        },
        'new': {
            'pruser': [{
                'name': 'other',
                'base': 'targetuser/targetindex',
                'last_serial': 10,
                'by': ['pruser'],
                'states': ['new'],
                'messages': ['Different pull request']
            }]
        }
    }
    # we register another project
    mapp.use("pruser/index")
    mapp.set_versiondata(dict(name="hello", version="1.0"),
                         set_whitelist=False)
    r = testapp.get_json(targetindex.index + "/+pr-list")
    result = r.json['result']
    # that should be serial 11
    assert result == {
        'pending': {
            'pruser': [{
                'name': 'index',
                'base': 'targetuser/targetindex',
                'last_serial': 11,
                'by': ['pruser', 'pruser'],
                'states': ['new', 'pending'],
                'messages': ['New pull request', 'Please approve']
            }]
        },
        'new': {
            'pruser': [{
                'name': 'other',
                'base': 'targetuser/targetindex',
                'last_serial': 10,
                'by': ['pruser'],
                'states': ['new'],
                'messages': ['Different pull request']
            }]
        }
    }
    # now we delete a project
    mapp.delete_project("pkg")
    r = testapp.get_json(targetindex.index + "/+pr-list")
    result = r.json['result']
    # the deletion should be 12
    assert result == {
        'pending': {
            'pruser': [{
                'name': 'index',
                'base': 'targetuser/targetindex',
                'last_serial': 12,
                'by': ['pruser', 'pruser'],
                'states': ['new', 'pending'],
                'messages': ['New pull request', 'Please approve']
            }]
        },
        'new': {
            'pruser': [{
                'name': 'other',
                'base': 'targetuser/targetindex',
                'last_serial': 10,
                'by': ['pruser'],
                'states': ['new'],
                'messages': ['Different pull request']
            }]
        }
    }
Ejemplo n.º 6
0
def test_pr_list(mapp, new_prindex, targetindex, testapp):
    r = testapp.get_json(targetindex.index + "/+pr-list")
    result = r.json['result']
    assert result == {
        'new': {
            'pruser': [{
                'name': 'index',
                'base': 'targetuser/targetindex',
                'last_serial': 5,
                'by': ['pruser'],
                'states': ['new'],
                'messages': ['New pull request']
            }]
        }
    }
    r = testapp.get_json(new_prindex.index + "/+pr-list")
    result = r.json['result']
    assert result == {
        'new': {
            'pruser': [{
                'name': 'index',
                'base': 'targetuser/targetindex',
                'last_serial': 5,
                'by': ['pruser'],
                'states': ['new'],
                'messages': ['New pull request']
            }]
        }
    }
    r = testapp.get_json("/pruser/+pr-list")
    result = r.json['result']
    assert result == {
        'new': {
            'pruser': [{
                'name': 'index',
                'base': 'targetuser/targetindex',
                'last_serial': 5,
                'by': ['pruser'],
                'states': ['new'],
                'messages': ['New pull request']
            }]
        }
    }
    content1 = mapp.makepkg("pkg-1.0.tar.gz", b"content1", "pkg", "1.0")
    mapp.upload_file_pypi("pkg-1.0.tar.gz",
                          content1,
                          "pkg",
                          "1.0",
                          set_whitelist=False)
    r = testapp.patch_json(new_prindex.index,
                           ['states+=pending', 'messages+=Please approve'])
    r = testapp.get_json(targetindex.index + "/+pr-list")
    result = r.json['result']
    assert result == {
        'pending': {
            'pruser': [{
                'name': 'index',
                'base': 'targetuser/targetindex',
                'last_serial': 8,
                'by': ['pruser', 'pruser'],
                'states': ['new', 'pending'],
                'messages': ['New pull request', 'Please approve']
            }]
        }
    }
    r = testapp.get_json("/pruser/+pr-list")
    result = r.json['result']
    assert result == {
        'pending': {
            'pruser': [{
                'name': 'index',
                'base': 'targetuser/targetindex',
                'last_serial': 8,
                'by': ['pruser', 'pruser'],
                'states': ['new', 'pending'],
                'messages': ['New pull request', 'Please approve']
            }]
        }
    }