Add bug verifcation to test_queries

This commit adds verification of the bugs listed in the queries.json
listed in the config file.
This commit is contained in:
Matthew 2013-09-19 20:52:09 -04:00
parent a641bb30af
commit b4311294d0
2 changed files with 33 additions and 4 deletions

View File

@ -11,9 +11,7 @@ Eventually this can be tied into the rechecker tool and launchpad
Future Work
------------
- Pull in list of queries from a more flexible source, so a commit isn't needed to update each time
- Make unit tests robust and not need internet
- Write tests to validate queries.json
- Use cookiecutter to clean this repo up
Dependencies

View File

@ -12,14 +12,25 @@
# License for the specific language governing permissions and limitations
# under the License.
import elasticRecheck
import os
import ConfigParser
import json
from launchpadlib import launchpad
import testtools
import elasticRecheck
LPCACHEDIR = os.path.expanduser('~/.launchpadlib/cache')
class TestQueries(testtools.TestCase):
def setUp(self):
super(TestQueries, self).setUp()
self.classifier = elasticRecheck.Classifier('queries.json')
config = ConfigParser.ConfigParser({'server_password': None})
config.read('elasticRecheck.conf')
self.queries = config.get('gerrit', 'query_file')
self.classifier = elasticRecheck.Classifier(self.queries)
def test_queries(self):
for x in self.classifier.queries:
@ -27,3 +38,23 @@ class TestQueries(testtools.TestCase):
query = self.classifier._apply_template(self.classifier.general_template, x['query'])
results = self.classifier.es.search(query, size='10')
self.assertTrue(int(results['hits']['total']) > 0, ("unable to find hits for bug %s" % x['bug']))
def test_valid_bugs(self):
lp = launchpad.Launchpad.login_anonymously('grabbing bugs',
'production',
LPCACHEDIR)
query_dict = json.loads(open(self.queries).read())
bugs = map(lambda x: x['bug'], query_dict)
openstack_group = lp.project_groups['openstack']
openstack_projects = map(lambda project: project.name,
openstack_group.projects)
for bug in bugs:
lp_bug = lp.bugs[bug]
bug_tasks = lp_bug.bug_tasks
bug_complete = map(lambda bug_task: bug_task.is_complete, bug_tasks)
projects = map(lambda bug_task: bug_task.bug_target_name, bug_tasks)
# Check if all open bug tasks are closed if is_complete is true for all tasks.
self.assertNotEquals(len(bug_complete), bug_complete.count(True))
# Check that all bug_tasks are targetted to OpenStack Projects
for project in projects:
self.assertIn(project, openstack_projects)