Reorganize tests into unit and functional tests

This commit breaks up the tests into 2 subdirectories, unit and functional.
Functional tests use the network in some way and may require either a
queries file or a functional config. Unit tests do not have these
requirements. In addition the default tox job is changed to only run the
unit tests. The functional tests are give a separate tox job.

Change-Id: I4bdc7f1098bfb7fa16dd869b2e54b3154848c3e1
This commit is contained in:
Matthew Treinish
2013-10-02 11:42:24 -04:00
parent 2f3f3ecd39
commit ac8a3feacd
7 changed files with 5 additions and 2 deletions

View File

@@ -0,0 +1,42 @@
# All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
import testtools
from elastic_recheck import elasticRecheck
class TestClassifier(testtools.TestCase):
def setUp(self):
super(TestClassifier, self).setUp()
self.classifier = elasticRecheck.Classifier('queries.yaml')
def test_read_qeuries_file(self):
self.assertNotEqual(self.classifier.queries, None)
def test_elasticSearch(self):
query = self.classifier._apply_template(self.classifier.targeted_template,
('@tags:"console.html" AND @message:"Finished: FAILURE"', '34825', '3'))
results = self.classifier.es.search(query, size='10')
self.assertTrue(int(results['hits']['total']) > 0, ("unable to find hit"))
def test_ready(self):
self.assertTrue(self.classifier._is_ready('49282', '3',
'BLAH http://logs.openstack.org/82/49282/3/gate/gate-tempest-devstack-vm-postgres-full/ffc0540'))
def test_classify(self):
bug_numbers = self.classifier.classify('47463', '3',
' blah http://logs.openstack.org/63/47463/3/gate/gate-tempest-devstack-vm-postgres-full/99bb8f6')
self.assertEqual(bug_numbers, [1218391])

View File

@@ -0,0 +1,65 @@
# All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
import ConfigParser
import gerritlib
import testtools
from elastic_recheck import elasticRecheck
class TestGerritComment(testtools.TestCase):
def setUp(self):
super(TestGerritComment, self).setUp()
config = ConfigParser.ConfigParser({'server_password': None})
config.read('elasticRecheck.conf')
self.user = config.get('gerrit', 'user')
key = config.get('gerrit', 'key')
host = 'review-dev.openstack.org'
self.stream = elasticRecheck.Stream(self.user, host, key, thread=False)
port = 29418
self.gerrit = gerritlib.gerrit.Gerrit(host, self.user, port)
def test_bug_found(self):
bug_numbers = ['1223158']
project = 'gtest-org/test'
commit_id = '434,1'
commit = '434'
self.stream.leave_comment(project, commit_id, bug_numbers)
result = self.gerrit.query(commit, comments=True)
comments = result.get('comments')
comment = comments[-1]
self.assertIn("I noticed tempest failed, I think you hit bug https://bugs.launchpad.net/bugs/1223158", comment.get('message'))
def test_bugs_found(self):
bug_numbers = ['1223158', '424242']
project = 'gtest-org/test'
commit_id = '434,1'
commit = '434'
self.stream.leave_comment(project, commit_id, bug_numbers)
result = self.gerrit.query(commit, comments=True)
comments = result.get('comments')
comment = comments[-1]
self.assertIn("I noticed tempest failed, I think you hit bug https://bugs.launchpad.net/bugs/1223158 and https://bugs.launchpad.net/bugs/424242 and", comment.get('message'))
def test_bug_not_found(self):
project = 'gtest-org/test'
commit_id = '434,1'
commit = '434'
self.stream.leave_comment(project, commit_id)
result = self.gerrit.query(commit, comments=True)
comments = result.get('comments')
comment = comments[-1]
self.assertIn("https://wiki.openstack.org/wiki/GerritJenkinsGithub#Test_Failures", comment.get('message'))

View File

@@ -0,0 +1,61 @@
# All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
import os
import ConfigParser
from launchpadlib import launchpad
import yaml
from elastic_recheck import elasticRecheck
from elastic_recheck import tests
LPCACHEDIR = os.path.expanduser('~/.launchpadlib/cache')
class TestQueries(tests.TestCase):
def setUp(self):
super(TestQueries, self).setUp()
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:
print "Looking for bug: https://bugs.launchpad.net/bugs/%s" % x['bug']
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 = yaml.load(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),
"bug %s is closed in launchpad" % bug)
# Check that all bug_tasks are targetted to OpenStack Projects
for project in projects:
self.assertIn(project, openstack_projects)