blob: 1b2784fdad0f9470470a1cb2bc1b259368cc1f38 [file] [log] [blame]
# Copyright (c) 2013 The Chromium OS Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
import datetime, subprocess, unittest
import mox
import common
# This must come before the import of complete_failures in order to use the
# in-memory database.
from autotest_lib.frontend import setup_django_readonly_environment
from autotest_lib.frontend import setup_test_environment
from import passing_experimental
from autotest_lib.frontend.afe import models as afe_models
from autotest_lib.frontend.tko import models as tko_models
from autotest_lib.server.cros.dynamic_suite import reporting
from django import test
# During the tests there is a point where Django does a type check on
# datetime.datetime. Unfortunately this means when datetime is mocked out,
# horrible failures happen when Django tries to do this check. The solution
# chosen is to create a pure Python class that inheirits from datetime.datetime
# so that the today class method can be directly mocked out. It is necesarry
# to mock out datetime.datetime completely as it a C class and so cannot have
# parts of itself mocked out.
class MockDatetime(datetime.datetime):
"""Used to mock out parts of datetime.datetime."""
class PassingExperimentalFunctionalTests(mox.MoxTestBase, test.TestCase):
Does a functional test of the script.
It uses an in-memory database, mocks out the saving and loading of the
storage object and mocks out the sending of the bugs. Everything else
is a full run.
def setUp(self):
super(PassingExperimentalFunctionalTests, self).setUp()
# All of our tests will involve mocking out the class
# method.
self.mox.StubOutWithMock(MockDatetime, 'today')
self.datetime = datetime.datetime
datetime.datetime = MockDatetime
# We really do not want a script that modifies the DB to run during
# testing. So we will mock this out even though we will mock out the
# function that calls it in case of refactoring.
self.mox.StubOutWithMock(subprocess, 'call')
# We need to mock out this function so bugs are not filed.
self.mox.StubOutClassWithMocks(reporting, 'Bug')
self.mox.StubOutClassWithMocks(reporting, 'Reporter')
self._orig_since_failure = passing_experimental._MIN_DAYS_SINCE_FAILURE
self._orig_since_pass = passing_experimental._MAX_DAYS_SINCE_LAST_PASS
def tearDown(self):
passing_experimental._MAX_DAYS_SINCE_LAST_PASS = self._orig_since_pass
passing_experimental._MIN_DAYS_SINCE_FAILURE = self._orig_since_failure
datetime.datetime = self.datetime
super(PassingExperimentalFunctionalTests, self).tearDown()
def test(self):
"""Does a basic test of as much of the system as possible."""
afe_models.Test(name='test1', test_type=0, path='test1',
afe_models.Test(name='test2', test_type=0, path='test2',
tko_models.Status(status_idx=6, word='GOOD').save()
job = tko_models.Job(job_idx=1)
kernel = tko_models.Kernel(kernel_idx=1)
machine = tko_models.Machine(machine_idx=1)
success_status = tko_models.Status(status_idx=GOOD_STATUS_IDX)
fail_status = tko_models.Status(status_idx=FAIL_STATUS_IDX)
tko_test1 = tko_models.Test(job=job, status=success_status,
kernel=kernel, machine=machine,
started_time=self.datetime(2012, 1, 20))
tko_test2 = tko_models.Test(job=job, status=success_status,
kernel=kernel, machine=machine,
started_time=self.datetime(2012, 1, 20))
passing_experimental._MAX_DAYS_SINCE_LAST_PASS = 10
passing_experimental._MIN_DAYS_SINCE_FAILURE = 10, 1, 21)), 1, 21))
reporter1 = reporting.Reporter()
bug1 = reporting.Bug(
title=u'test1 should be promoted to non-experimental.',
search_marker=u'PassingExperimental(test1)'), 1))
reporter2 = reporting.Reporter()
bug2 = reporting.Bug(
title=u'test2 should be promoted to non-experimental.',
search_marker=u'PassingExperimental(test2)'), 1))
if __name__ == '__main__':