summaryrefslogtreecommitdiffstats
path: root/bitbake/lib/toaster/orm/tests.py
blob: b0c01db2167e508db0ee6a72925abd13eb0f2c49 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
from django.test import TestCase, TransactionTestCase
from orm.models import LocalLayerSource, LayerIndexLayerSource, ImportedLayerSource, LayerSource
from orm.models import Branch

from orm.models import Project, Build, Layer, Layer_Version, Branch, ProjectLayer
from orm.models import Release, ReleaseLayerSourcePriority, BitbakeVersion

from django.utils import timezone
from django.db import IntegrityError

import os

# set TTS_LAYER_INDEX to the base url to use a different instance of the layer index

class LayerSourceVerifyInheritanceSaveLoad(TestCase):
    """
    Tests to verify inheritance for the LayerSource proxy-inheritance classes.
    """
    def test_object_creation(self):
        """Test LayerSource object creation."""
        for name, sourcetype in [("a1", LayerSource.TYPE_LOCAL),
                                 ("a2", LayerSource.TYPE_LAYERINDEX),
                                 ("a3", LayerSource.TYPE_IMPORTED)]:
            LayerSource.objects.create(name=name, sourcetype=sourcetype)

        objects = LayerSource.objects.all()
        self.assertTrue(isinstance(objects[0], LocalLayerSource))
        self.assertTrue(isinstance(objects[1], LayerIndexLayerSource))
        self.assertTrue(isinstance(objects[2], ImportedLayerSource))

    def test_duplicate_error(self):
        """Test creation of duplicate LayerSource objects."""
        stype = LayerSource.TYPE_LOCAL
        LayerSource.objects.create(name="a1", sourcetype=stype)
        with self.assertRaises(IntegrityError):
            LayerSource.objects.create(name="a1", sourcetype=stype)


class LILSUpdateTestCase(TransactionTestCase):
    def setUp(self):
        # create release
        bbv = BitbakeVersion.objects.create(name="master", giturl="git://git.openembedded.org/bitbake")
        release = Release.objects.create(name="default-release", bitbake_version = bbv, branch_name = "master")

    def test_update(self):
        layer_index_url = os.getenv("TTS_LAYER_INDEX")
        if layer_index_url == None:
            layer_index_url = "http://layers.openembedded.org/"

        lils = LayerSource.objects.create(name = "b1", sourcetype = LayerSource.TYPE_LAYERINDEX, apiurl = layer_index_url + "layerindex/api/")
        lils.update()

        # run asserts
        self.assertTrue(lils.branch_set.all().count() > 0, "update() needs to fetch some branches")



# tests to verify layer_version priority selection
class LayerVersionEquivalenceTestCase(TestCase):
    def setUp(self):
        # create layer sources
        ls = LayerSource.objects.create(name = "dummy-layersource", sourcetype = LayerSource.TYPE_LOCAL)

        # create bitbake version
        bbv = BitbakeVersion.objects.create(name="master", giturl="git://git.openembedded.org/bitbake")
        # create release
        release = Release.objects.create(name="default-release", bitbake_version = bbv, branch_name = "master")
        # attach layer source to release
        ReleaseLayerSourcePriority.objects.create(release = release, layer_source = ls, priority = 1)


        # create layer attach
        self.layer = Layer.objects.create(name="meta-testlayer", layer_source = ls)
        # create branch
        self.branch = Branch.objects.create(name="master", layer_source = ls)

        # set a layer version for the layer on the specified branch
        self.layerversion = Layer_Version.objects.create(layer = self.layer, layer_source = ls, up_branch = self.branch)

        # create spoof layer that should not appear in the search results
        Layer_Version.objects.create(layer = Layer.objects.create(name="meta-notvalid", layer_source = ls), layer_source = ls, up_branch = self.branch)


        # create a project ...
        self.project = Project.objects.create_project(name="test-project", release = release)
        # ... and set it up with a single layer version
        ProjectLayer.objects.create(project=  self.project, layercommit = self.layerversion)

    def test_single_layersource(self):
        # when we have a single layer version, get_equivalents_wpriority() should return a list with just this layer_version
        equivalent_list = self.layerversion.get_equivalents_wpriority(self.project)
        self.assertTrue(len(equivalent_list) == 1)
        self.assertTrue(equivalent_list[0] == self.layerversion)

    def test_dual_layersource(self):
        # if we have two layers with the same name, from different layer sources, we expect both layers in, in increasing priority of the layer source
        ls2 = LayerSource.objects.create(name = "dummy-layersource2", sourcetype = LayerSource.TYPE_LOCAL, apiurl="test")

        # assign a lower priority for the second layer source
        Release.objects.get(name="default-release").releaselayersourcepriority_set.create(layer_source = ls2, priority = 2)

        # create a new layer_version for a layer with the same name coming from the second layer source
        self.layer2 = Layer.objects.create(name="meta-testlayer", layer_source = ls2)
        self.layerversion2 = Layer_Version.objects.create(layer = self.layer2, layer_source = ls2, up_branch = self.branch)

        # expect two layer versions, in the priority order
        equivalent_list = self.layerversion.get_equivalents_wpriority(self.project)
        self.assertTrue(len(equivalent_list) == 2)
        self.assertTrue(equivalent_list[0] == self.layerversion2)
        self.assertTrue(equivalent_list[1] == self.layerversion)

    def test_build_layerversion(self):
        # any layer version coming from the build should show up before any layer version coming from upstream
        build = Build.objects.create(project = self.project, started_on = timezone.now(), completed_on = timezone.now())
        self.layerversion_build = Layer_Version.objects.create(layer = self.layer, build = build, commit = "deadbeef")

        # a build layerversion must be in the equivalence list for the original layerversion
        equivalent_list = self.layerversion.get_equivalents_wpriority(self.project)
        self.assertTrue(len(equivalent_list) == 2)
        self.assertTrue(equivalent_list[0] == self.layerversion)
        self.assertTrue(equivalent_list[1] == self.layerversion_build)

        # getting the build layerversion equivalent list must return the same list as the original layer
        build_equivalent_list = self.layerversion_build.get_equivalents_wpriority(self.project)

        self.assertEqual(list(equivalent_list), list(build_equivalent_list))

class ProjectLVSelectionTestCase(TestCase):
    def setUp(self):
        # create layer sources
        ls = LayerSource.objects.create(name = "dummy-layersource", sourcetype = LayerSource.TYPE_LOCAL)

        # create bitbake version
        bbv = BitbakeVersion.objects.create(name="master", giturl="git://git.openembedded.org/bitbake")
        # create release
        release = Release.objects.create(name="default-release", bitbake_version = bbv, branch_name="master")
        # attach layer source to release
        ReleaseLayerSourcePriority.objects.create(release = release, layer_source = ls, priority = 1)

        # create layer attach
        self.layer = Layer.objects.create(name="meta-testlayer", layer_source = ls)
        # create branch
        self.branch = Branch.objects.create(name="master", layer_source = ls)

        # set a layer version for the layer on the specified branch
        self.layerversion = Layer_Version.objects.create(layer = self.layer, layer_source = ls, up_branch = self.branch)


        # create a project ...
        self.project = Project.objects.create_project(name="test-project", release = release)
        # ... and set it up with a single layer version
        ProjectLayer.objects.create(project=  self.project, layercommit = self.layerversion)

    def test_single_layersource(self):
        compatible_layerversions = self.project.compatible_layerversions()
        self.assertTrue(len(compatible_layerversions) == 1)
        self.assertTrue(compatible_layerversions[0] == self.layerversion)


    def test_dual_layersource(self):
         # if we have two layers with the same name, from different layer sources, we expect both layers in, in increasing priority of the layer source
        ls2 = LayerSource.objects.create(name = "dummy-layersource2", sourcetype = LayerSource.TYPE_LOCAL, apiurl="testing")

        # assign a lower priority for the second layer source
        Release.objects.get(name="default-release").releaselayersourcepriority_set.create(layer_source = ls2, priority = 2)

        # create a new layer_version for a layer with the same name coming from the second layer source
        self.layer2 = Layer.objects.create(name="meta-testlayer", layer_source = ls2)
        self.layerversion2 = Layer_Version.objects.create(layer = self.layer2, layer_source = ls2, up_branch = self.branch)

         # expect two layer versions, in the priority order
        equivalent_list = self.project.compatible_layerversions()
        self.assertTrue(len(equivalent_list) == 2)
        self.assertTrue(equivalent_list[0] == self.layerversion2)
        self.assertTrue(equivalent_list[1] == self.layerversion)