Coverage for appr/tests/conftest.py: 43%

# Coverage for appr/tests/conftest.py : 43%

## 101 statements 43 run 58 missing 0 excluded

Hot-keys on this page

r m x p toggle line displays

j k next/prev highlighted chunk

0 (zero) top of page

1 (one) first highlighted chunk

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 | from __future__ import absolute_import, division, print_function import json import os import pytest from appr.utils import symbol_by_name LOCAL_DIR = os.path.dirname(__file__) @pytest.fixture() def data_dir(): return LOCAL_DIR + "/data" @pytest.fixture def discovery_html(): return """<html lang="en"> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta name="appr-package" content="appr.sh/{name} https://api.kubespray.io/api/v1/packages/{name}/pull"> </head> <body> <a href=https://github.com/coreos/appr>coreos/appr</a> </body> </html>""" @pytest.fixture def app(db_class): create_app = symbol_by_name(os.getenv("APPR_FLASK_APP", "appr.api.app:create_app")) app = create_app() return app @pytest.fixture() def api_prefix(): return os.getenv("APPR_API_PREFIX", "") @pytest.fixture() def fake_home(monkeypatch, tmpdir): home = tmpdir.mkdir('home') monkeypatch.setenv("HOME", home) return home def get_response(name, kind): f = open(LOCAL_DIR + "/data/responses/%s-%s.json" % (name, kind)) r = f.read() f.close() return r @pytest.fixture(scope="module") def kubeui_package(): import base64 import appr.pack with open(LOCAL_DIR + "/data/kube-ui.tar.gz", "rb") as f: package = appr.pack.ApprPackage(base64.b64encode(f.read())) return package @pytest.fixture(scope='module') def package_b64blob(): return """\ H4sICF8BsVcC/3RpdF9yb2NrZXRjaGF0XzEuMTAuMGt1Yi50YXIA7Zddb9MwFIZ7nV9hlYve0DRpmgZFgJjGhCat2zQGNwhNXup1Vu04st\ 1IVZX/znGTtMnYWAWj08DPRT6Ofezjr/ckF0cHHydHLp92/h4eMB6PzN2PQq95L4lGHX84HkfjcBz4YPeDKPA6yOvsgYXSWCLUwYzMJE4fn\ IfHyquhbO4vBEeKZE50cou1826L47xCxylMDWOOM884ouULalR3OpYXD8cpvSFKu0vM2fOcf98LAjj/URgE/ggK4PyHPpjs+d8D/X7fyXAy\ xzMSOwilmJMYdTXVg+1J70IBXuhbIWN0kGpBU4JOytlAb4faxaXtw4xjytxE8PfgkBOpqEhj5Lu+53pgmRKVSJrptbWhIwgxmpBUQceT40v\ HybGk+JoRZQKSJINSrKAdeKPcxNlwrqJ0zXPMsIadXI1CwajInX5MfFcLyWKkuM7iwQBsCYMdQGBk1YPLRIKZqSzSmZhel/WrF3CpntzVat\ NLUbgqT8BSNVEU8TCCLT5oiqUkSixkUo6qj24oa0XXNy0suem4XoVW6AjpZQZGqObc34DcyV+C+xTmVCzLOMqqoPCuuh3AQgZ+PUIr7/8Dm\ vBsfW4GP22lvel/4Jnvv8gLQ89cQP+jyB9a/d+X/uOMfq3VOvedOU2nMboohdeo9aFItRSMEelwovEUa7zNFW0hx9eEgVavevM3qo+zrBej\ 3rZG7zXqVXnBFOR+r2irdUtUHZWRpJ0DVqv6uTCeijCSaJOWHurQ1Kq3eLyWweYIDL8VMnRdxWZIYH4wJECpakv/fgk27JjCSlpJo4ZRTnX\ LAiFkC8iQnsdbVk64kMsYBZ43oZsSkuZN5zrWydnpp7OrLxcnrSZyzBbrhWmkw6K4z/3g+OQX3lXmbbhmQsIo0LdVL5NCi0QwM8GXh+dmyj\ dTeg61eusReGA2Xd1d4e82UT21/lffIk+q/6OH//9Hw9D8/0ejcBSGQ7AP4Z9gbPX/OfS/m/vdKgN0PxOZw5d5909VfyeR31HL1x+xp2JKj\ DA4j6gIrOyM6EclBKzZto4VFIvFYrFYLBaLxWKxWCwWi8Xyb/ADcPSUWQAoAAA=""" @pytest.fixture(scope="module") def kubeui_blob(): with open(LOCAL_DIR + "/data/kube-ui.tar.gz", "rb") as f: package = f.read() return package @pytest.fixture() def package_dir(monkeypatch): monkeypatch.chdir(LOCAL_DIR + "/data/kube-ui") @pytest.fixture() def bad_package_dir(monkeypatch): monkeypatch.chdir(LOCAL_DIR + "/data/bad_manifest") @pytest.fixture() def empty_package_dir(monkeypatch): monkeypatch.chdir(LOCAL_DIR + "/data") @pytest.fixture() def pack_tar(package_dir, tmpdir): from appr.pack import pack_kub kub = os.path.join(str(tmpdir.mkdir("tars")), "kube-ui.tar.gz") pack_kub(kub) return kub @pytest.fixture(scope="module") def deploy_json(): f = open(LOCAL_DIR + "/data/kube-ui_release.json", 'r') r = f.read() f.close() return r @pytest.fixture(scope="module") def deploy(deploy_json): return json.loads(deploy_json) @pytest.fixture(scope="module") def ns_resource(deploy): kubeui = deploy["deploy"][0] return kubeui['resources'][0] @pytest.fixture(scope="module") def rc_resource(deploy): kubeui = deploy["deploy"][0] return kubeui['resources'][1] @pytest.fixture(scope="module") def svc_resource(deploy): kubeui = deploy["deploy"][0] return kubeui['resources'][2] @pytest.fixture(scope="session") def db_names(): return os.getenv("APPR_TEST_DB", "filesystem,redis,etcd").replace(r" ", "").split(",") def get_db_classes(): class_names = os.getenv("APPR_DB_CLASSES", "appr.models.kv.etcd.db:EtcdDB,\ appr.models.kv.filesystem.db:FilesystemDB,\ appr.models.kv.redis.db:RedisDB").replace(r" ", "").split(",") return [symbol_by_name(symbol) for symbol in class_names] DB_CLASSES = get_db_classes() PACKAGE_CLASSES = [dbc.Package for dbc in DB_CLASSES] CHANNEL_CLASSES = [dbc.Channel for dbc in DB_CLASSES] def class_name(obj): return "%s:%s" % (obj.__module__, obj.__name__) @pytest.fixture() def kv_prefix(monkeypatch): monkeypatch.setattr('appr.models.kv.APPR_KV_PREFIX', "appr-tests/packages/") monkeypatch.setenv("APPR_KV_PREFIX", "appr-tests/packages/") @pytest.fixture() def db(): from appr.models.db_base import ApprDB return ApprDB @pytest.fixture(scope='session') def dbdata1(): with open(LOCAL_DIR + "/data/backup1.json", "rb") as f: data = json.loads(f.read()) return data @pytest.fixture() def db_class(db, monkeypatch, kv_prefix): monkeypatch.setenv("APPR_DB_CLASS", class_name(db)) monkeypatch.setattr('appr.models.ApprDB', db) monkeypatch.setattr('appr.models.Package', db.Package) monkeypatch.setattr('appr.models.Channel', db.Channel) monkeypatch.setattr('appr.models.Blob', db.Blob) monkeypatch.setattr('appr.api.registry.Package', db.Package) monkeypatch.setattr('appr.api.registry.Channel', db.Channel) monkeypatch.setattr('appr.api.registry.Blob', db.Blob) return db @pytest.fixture() def newdb(kv_prefix, db_class): db_class.reset_db(True) yield db_class db_class.reset_db(True) @pytest.fixture() def db_with_data1(newdb, dbdata1): newdb.restore_backup(dbdata1) return newdb