• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/usr/bin/python
2# pylint: disable=missing-docstring
3
4import unittest
5
6import common
7from autotest_lib.frontend import setup_django_environment
8from autotest_lib.frontend import setup_test_environment
9from autotest_lib.frontend.tko import models
10
11
12class TKOTestTest(unittest.TestCase):
13
14    def setUp(self):
15        setup_test_environment.set_up()
16        self.machine1 = models.Machine.objects.create(hostname='myhost')
17        self.good_status = models.Status.objects.create(word='GOOD')
18        kernel_name = 'mykernel1'
19        self.kernel1 = models.Kernel.objects.create(kernel_hash=kernel_name,
20                                               base=kernel_name,
21                                               printable=kernel_name)
22        self.job1 = models.Job.objects.create(
23                tag='1-myjobtag1', label='myjob1',
24                username='myuser', machine=self.machine1,
25                afe_job_id=1)
26        self.job1_test1 = models.Test.objects.create(
27                job=self.job1, test='mytest1',
28                kernel=self.kernel1,
29                status=self.good_status,
30                machine=self.machine1)
31
32
33    def tearDown(self):
34        setup_test_environment.tear_down()
35
36
37    def _get_attributes(self, test):
38        models.Test.objects.populate_relationships(
39                [test], models.TestAttribute, 'attribute_list')
40        return dict((attribute.attribute, attribute.value)
41                    for attribute in test.attribute_list)
42
43    def test_delete_attribute(self):
44        test1 = self.job1_test1
45        test1.set_attribute('test_attribute1', 'test_value1')
46
47        attributes = self._get_attributes(test1)
48        self.assertEquals(attributes['test_attribute1'], 'test_value1')
49
50        test1.set_or_delete_attribute('test_attribute1', None)
51        attributes = self._get_attributes(test1)
52        self.assertNotIn('test_attribute1', attributes.keys())
53
54
55    def test_set_attribute(self):
56        # Verify adding static attribute in model_logic doesn't break TKO Test.
57        test1 = self.job1_test1
58        test1.set_attribute('test_attribute1', 'test_value1')
59        test1.set_or_delete_attribute('test_attribute1', 'test_value2')
60        attributes = self._get_attributes(test1)
61        self.assertEquals(attributes['test_attribute1'], 'test_value2')
62