|
| 1 | +#! /usr/bin/python |
| 2 | +# -*- coding: UTF-8 -*- |
| 3 | + |
| 4 | +# Copyright 2011-2012 Olivier Renault, James Stock, TestLink-API-Python-client developers |
| 5 | +# |
| 6 | +# Licensed under ??? |
| 7 | +# see https://github.com/orenault/TestLink-API-Python-client/issues/4 |
| 8 | + |
| 9 | +# This example shows, how the API could be used to list all test cases, |
| 10 | +# which have been created during the last 7 days |
| 11 | + |
| 12 | + |
| 13 | +from testlink import TestlinkAPIClient, TestLinkHelper |
| 14 | +import time |
| 15 | + |
| 16 | + |
| 17 | +def iterTCasesfromTProject(api, TProjName, date1, date2): |
| 18 | + """ returns as iterator all test cases of project TPROJTNAME, which are |
| 19 | + created between DATE1 and DATE2 |
| 20 | + DATE1 and DATE2 must be of type time.struct_time """ |
| 21 | + TProjId = api.getTestProjectByName(TProjName)[0]['id'] |
| 22 | + for TSinfo in api.getFirstLevelTestSuitesForTestProject(TProjId): |
| 23 | + TSuiteId = TSinfo['id'] |
| 24 | + for TCid in api.getTestCasesForTestSuite(TSuiteId, deep=1,details='only_id'): |
| 25 | + TCdata = api.getTestCase(TCid)[0] #really only one TC? |
| 26 | + dateTC=time.strptime(TCdata['creation_ts'][:10], '%Y-%m-%d') |
| 27 | + if (date1 <= dateTC) and (dateTC <= date2): |
| 28 | + yield TCdata |
| 29 | + |
| 30 | + |
| 31 | +if __name__ == '__main__': |
| 32 | + tlapi = TestLinkHelper().connect(TestlinkAPIClient) |
| 33 | + projName = 'NEW_PROJECT_API' |
| 34 | + currentTime = time.localtime() |
| 35 | + oldTime = time.localtime(time.time() - 3600 * 24 * 7) |
| 36 | + |
| 37 | + print '%s test cases created between %s and %s' % \ |
| 38 | + (projName, time.strftime('%Y-%m-%d', oldTime), |
| 39 | + time.strftime('%Y-%m-%d', currentTime)) |
| 40 | + for TCdata in iterTCasesfromTProject(tlapi, projName, oldTime, currentTime): |
| 41 | + print ' %(name)s %(version)s %(creation_ts)s' % TCdata |
0 commit comments