Coverage for /media/ldata/code/tendril/tendril/testing/db/controller.py: 0%

# Coverage for /media/ldata/code/tendril/tendril/testing/db/controller.py : 0%

## 72 statements 0 run 72 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 | #!/usr/bin/env python # encoding: utf-8 # Copyright (C) 2015 Chintalagiri Shashank # # This file is part of tendril. # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU Affero General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU Affero General Public License for more details. # # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see <http://www.gnu.org/licenses/>. """ Docstring for controller.py """ from tendril.utils.db import with_db from model import TestResult from model import TestSuiteResult from tendril.entityhub import serialnos from tendril.entityhub.db.model import SerialNumber from sqlalchemy import desc @with_db def create_test_model_obj(testobj=None, suite=None, session=None): if testobj.passed is True: passed = True else: passed = False tro = TestResult(test_class=repr(testobj.__class__), passed=passed, result=testobj.render(), desc=testobj.desc, title=testobj.title) tro.testsuite = suite if testobj.ts is not None: tro.created_at = testobj.ts session.add(tro) return tro @with_db def commit_test_suite(suiteobj=None, session=None): sno = serialnos.get_serialno_object(sno=suiteobj.serialno, session=session) passed = suiteobj.passed sro = TestSuiteResult(suite_class=repr(suiteobj.__class__), passed=passed, desc=suiteobj.desc, title=suiteobj.title) sro.serialno = sno if suiteobj.ts is not None: sro.created_at = suiteobj.ts session.add(sro) for test in suiteobj.tests: sro.tests.append( create_test_model_obj(testobj=test, suite=sro, session=session) ) @with_db def get_test_suites(serialno=None, session=None): if serialno is None: raise AttributeError("serialno cannot be None") if not isinstance(serialno, SerialNumber): serialno = serialnos.get_serialno_object(sno=serialno, session=session) return session.query( TestSuiteResult).filter_by(serialno=serialno).order_by( desc(TestSuiteResult.created_at)).all() @with_db def get_latest_test_result(serialno=None, test_class=None, session=None): if serialno is None: raise AttributeError("serialno cannot be None") if test_class is None: raise AttributeError("testclass cannot be None") if not isinstance(serialno, SerialNumber): serialno = serialnos.get_serialno_object(sno=serialno, session=session) if not isinstance(test_class, str): test_class = repr(test_class.__class__) return session.query(TestResult).filter_by( test_class=test_class).join( TestSuiteResult).filter( TestSuiteResult.serialno == serialno).order_by( desc(TestResult.created_at)).first() @with_db def get_latest_test_suite(serialno=None, suite_class=None, descr=None, session=None): if serialno is None: raise AttributeError("serialno cannot be None") if not isinstance(serialno, SerialNumber): serialno = serialnos.get_serialno_object(sno=serialno, session=session) q = session.query(TestSuiteResult).filter_by( serialno=serialno, suite_class=suite_class ) if descr is not None: q = q.filter_by(desc=descr) q = q.order_by(desc(TestSuiteResult.created_at)) return q.first() @with_db def get_test_suite_names(serialno=None, session=None): if serialno is None: raise AttributeError("serialno cannot be None") if not isinstance(serialno, SerialNumber): serialno = serialnos.get_serialno_object(sno=serialno, session=session) return [x[0] for x in session.query( TestSuiteResult.suite_class).filter_by( serialno=serialno).distinct().all() ] @with_db def get_test_suite_descs(serialno=None, session=None): if serialno is None: raise AttributeError("serialno cannot be None") if not isinstance(serialno, SerialNumber): serialno = serialnos.get_serialno_object(sno=serialno, session=session) return session.query( TestSuiteResult.desc, TestSuiteResult.suite_class).filter_by( serialno=serialno).distinct().all()