Phase 1 of migrating APPR-specific tables to tables with the Appr
prefix
Fixes https://jira.coreos.com/browse/QUAY-950
This commit is contained in:
parent
6622f27c93
commit
113bb96f29
28 changed files with 699 additions and 176 deletions
|
@ -6,13 +6,13 @@ from cnr.tests.conftest import *
|
|||
from cnr.tests.test_apiserver import BaseTestServer
|
||||
from cnr.tests.test_models import CnrTestModels
|
||||
|
||||
import data.appr_model.blob as oci_blob
|
||||
import data.appr_model.blob as appr_blob
|
||||
|
||||
from data.database import User
|
||||
from data.model import organization, user
|
||||
from endpoints.appr import registry # Needed to register the endpoint
|
||||
from endpoints.appr.cnr_backend import Channel, Package, QuayDB
|
||||
from endpoints.appr.models_cnr import model as oci_app_model
|
||||
from endpoints.appr.models_cnr import model as appr_app_model
|
||||
|
||||
from test.fixtures import *
|
||||
|
||||
|
@ -28,7 +28,7 @@ class ChannelTest(Channel):
|
|||
@classmethod
|
||||
def dump_all(cls, package_class=None):
|
||||
result = []
|
||||
for repo in oci_app_model.list_applications(with_channels=True):
|
||||
for repo in appr_app_model.list_applications(with_channels=True):
|
||||
for chan in repo.channels:
|
||||
result.append({'name': chan.name, 'current': chan.current, 'package': repo.name})
|
||||
return result
|
||||
|
@ -51,17 +51,17 @@ class PackageTest(Package):
|
|||
@classmethod
|
||||
def dump_all(cls, blob_cls):
|
||||
result = []
|
||||
for repo in oci_app_model.list_applications(with_channels=True):
|
||||
for repo in appr_app_model.list_applications(with_channels=True):
|
||||
package_name = repo.name
|
||||
for release in repo.releases:
|
||||
for mtype in cls.manifests(package_name, release):
|
||||
package = oci_app_model.fetch_release(package_name, release, mtype)
|
||||
package = appr_app_model.fetch_release(package_name, release, mtype)
|
||||
blob = blob_cls.get(package_name, package.manifest.content.digest)
|
||||
app_data = cls._apptuple_to_dict(package)
|
||||
app_data.pop('digest')
|
||||
app_data['channels'] = [
|
||||
x.name
|
||||
for x in oci_app_model.list_release_channels(package_name, package.release, False)
|
||||
for x in appr_app_model.list_release_channels(package_name, package.release, False)
|
||||
]
|
||||
app_data['blob'] = blob.b64blob
|
||||
result.append(app_data)
|
||||
|
@ -141,11 +141,11 @@ class TestQuayModels(CnrTestModels):
|
|||
assert p.release == "2.0.1"
|
||||
assert p.digest == "d3b54b7912fe770a61b59ab612a442eac52a8a5d8d05dbe92bf8f212d68aaa80"
|
||||
blob = db_with_data1.Blob.get("titi/rocketchat", p.digest)
|
||||
bdb = oci_blob.get_blob(p.digest)
|
||||
bdb = appr_blob.get_blob(p.digest, appr_app_model.models_ref)
|
||||
newblob = db_with_data1.Blob("titi/app2", blob.b64blob)
|
||||
p2 = db_with_data1.Package("titi/app2", "1.0.0", "helm", newblob)
|
||||
p2.save()
|
||||
b2db = oci_blob.get_blob(p2.digest)
|
||||
b2db = appr_blob.get_blob(p2.digest, appr_app_model.models_ref)
|
||||
assert b2db.id == bdb.id
|
||||
|
||||
def test_force_push_different_blob(self, db_with_data1):
|
||||
|
|
|
@ -1,14 +1,18 @@
|
|||
import base64
|
||||
import json
|
||||
|
||||
from flask import url_for
|
||||
from mock import patch
|
||||
|
||||
import pytest
|
||||
|
||||
from flask import url_for
|
||||
|
||||
from data import model
|
||||
from endpoints.appr.registry import appr_bp
|
||||
|
||||
from test.fixtures import *
|
||||
|
||||
|
||||
@pytest.mark.parametrize('login_data, expected_code', [
|
||||
({
|
||||
"username": "devtable",
|
||||
|
@ -62,3 +66,27 @@ def test_invalid_release_name(release_name, app, client):
|
|||
|
||||
rv = client.open(url, method='POST', data=json.dumps(data), headers=headers)
|
||||
assert rv.status_code == 422
|
||||
|
||||
|
||||
@pytest.mark.parametrize('readonly, expected_status', [
|
||||
(True, 405),
|
||||
(False, 422),
|
||||
])
|
||||
def test_readonly(readonly, expected_status, app, client):
|
||||
params = {
|
||||
'namespace': 'devtable',
|
||||
'package_name': 'someapprepo',
|
||||
}
|
||||
|
||||
url = url_for('appr.push', **params)
|
||||
auth = base64.b64encode('devtable:password')
|
||||
headers = {'Content-Type': 'application/json', 'Authorization': 'Basic ' + auth}
|
||||
data = {
|
||||
'release': '1.0',
|
||||
'media_type': 'application/vnd.cnr.manifest.v0+json',
|
||||
'blob': 'H4sIAFQwWVoAA+3PMQrCQBAF0Bxlb+Bk143nETGIIEoSC29vMMFOu3TvNb/5DH/Ot8f02jWbiohDremT3ZKR90uuUlty7nKJNmqKtkQuTarbzlo8x+k4zFOu4+lyH4afvbnW93/urH98EwAAAAAAAAAAADb0BsdwExIAKAAA',
|
||||
}
|
||||
|
||||
with patch('endpoints.appr.models_cnr.model.is_readonly', readonly):
|
||||
rv = client.open(url, method='POST', data=json.dumps(data), headers=headers)
|
||||
assert rv.status_code == expected_status
|
||||
|
|
Reference in a new issue