1 #============================================================================ |
|
2 #Name : test_buildmodel.py |
|
3 #Part of : Helium |
|
4 |
|
5 #Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
6 #All rights reserved. |
|
7 #This component and the accompanying materials are made available |
|
8 #under the terms of the License "Eclipse Public License v1.0" |
|
9 #which accompanies this distribution, and is available |
|
10 #at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
11 # |
|
12 #Initial Contributors: |
|
13 #Nokia Corporation - initial contribution. |
|
14 # |
|
15 #Contributors: |
|
16 # |
|
17 #Description: |
|
18 #=============================================================================== |
|
19 |
|
20 """ Test build.model module. """ |
|
21 |
|
22 import os |
|
23 import sys |
|
24 import unittest |
|
25 |
|
26 import build.model |
|
27 import configuration |
|
28 import ccm |
|
29 import amara |
|
30 |
|
31 database = "to1tobet" |
|
32 |
|
33 class BOMMockFolder: |
|
34 def __init__(self, name, instance, description, tasks): |
|
35 self.name = name |
|
36 self.instance = instance |
|
37 self.description = description |
|
38 self.tasks = tasks |
|
39 |
|
40 class BOMMockProject: |
|
41 def __init__(self, name): |
|
42 self.name = name |
|
43 |
|
44 def __str__(self): |
|
45 return self.name |
|
46 |
|
47 @property |
|
48 def tasks(self): |
|
49 return [] |
|
50 |
|
51 @property |
|
52 def folders(self): |
|
53 return [BOMMockFolder('5856', 'tr1s60', "all completed tasks for release ABS_domain/abs.mcl for collaborative projects", [])] |
|
54 |
|
55 class BOMMock: |
|
56 |
|
57 def __init__(self): |
|
58 self.config = {} |
|
59 self.config['build.id'] = "mock" |
|
60 |
|
61 @property |
|
62 def projects(self): |
|
63 return [BOMMockProject('ABS_domain-abs.mcl_200843:project:tr1s60#1')] |
|
64 |
|
65 def all_baselines(self): |
|
66 return [] |
|
67 |
|
68 # Refactor required: See http://delivery.nmp.nokia.com/trac/helium/ticket/1517 |
|
69 class BOMTest(unittest.TestCase): |
|
70 """ Test BOM and related classes. """ |
|
71 |
|
72 # TODO - removed until non-Synergy dependent tests can be provided. |
|
73 |
|
74 # def test_bom_output(self): |
|
75 # """ Test basic BOM execution. Only new spec format will be covered!""" |
|
76 # try: |
|
77 # session = ccm.open_session(database=database) |
|
78 # except ccm.CCMException: |
|
79 # print "Skipping BOMTest test cases." |
|
80 # return |
|
81 # |
|
82 # project = session.create('helium-helium_0.1:project:vc1s60p1#1') |
|
83 # config_dict = {'delivery': 'tests/data/test_delivery.xml', |
|
84 # 'prep.xml': 'tests/data/test_prep.xml', |
|
85 # 'build.id': "test_0.0", |
|
86 # 'ccm.database': session.database()} |
|
87 # config = configuration.Configuration(config_dict) |
|
88 # bom = build.model.BOM_new_spec_config(config, project) |
|
89 # writer = build.model.BOMHTMLWriter(bom) |
|
90 # writer.write("bom2.html") |
|
91 # session.close() |
|
92 # os.remove("bom2.html") |
|
93 # os.remove("bom2.html.xml") |
|
94 |
|
95 def test_bom_delta(self): |
|
96 """ Testing BOM delta creation... """ |
|
97 delta = build.model.BOMDeltaXMLWriter(BOMMock(), os.path.join(os.environ['HELIUM_HOME'], 'tests/data/bom/build_model_bom.xml')) |
|
98 delta.write(os.path.join(os.environ['HELIUM_HOME'], 'build','delta.xml')) |
|
99 xml = amara.parse(open(os.path.join(os.environ['HELIUM_HOME'], 'build','delta.xml'), 'r')) |
|
100 assert xml.bomDelta[0].buildFrom[0] == "ido_raptor_mcl_abs_MCL.52.57" |
|
101 assert xml.bomDelta[0].buildTo[0] == "mock" |
|
102 |
|
103 print "baselines: ", len(xml.bomDelta.content.baseline) |
|
104 print "folders: ", len(xml.bomDelta.content.folder) |
|
105 print "tasks: ", len(xml.bomDelta.content.task) |
|
106 print "baseline[@overridden='false']:", len(xml.bomDelta.content.xml_xpath("baseline[@overridden='false']")) |
|
107 print "baseline[@overridden='true']: ", len(xml.bomDelta.content.xml_xpath("baseline[@overridden='true']")) |
|
108 print "folder[@status='deleted']: ", len(xml.bomDelta.content.xml_xpath("folder[@status='deleted']")) |
|
109 print "task[@status='deleted']: ", len(xml.bomDelta.content.xml_xpath("task[@status='deleted']")) |
|
110 |
|
111 assert len(xml.bomDelta.content.baseline) == 156 |
|
112 assert len(xml.bomDelta.content.folder) == 1 |
|
113 assert len(xml.bomDelta.content.task) == 1 |
|
114 assert len(xml.bomDelta.content.xml_xpath("baseline[@overridden='false']")) == 155 |
|
115 assert len(xml.bomDelta.content.xml_xpath("baseline[@overridden='true']")) == 1 |
|
116 |
|
117 assert len(xml.bomDelta.content.xml_xpath("folder[@status='deleted']")) == 1 |
|
118 |
|
119 assert len(xml.bomDelta.content.xml_xpath("task[@status='deleted']")) == 1 |
|
120 |
|
121 def test_validate_bom_delta(self): |
|
122 """ Testing BOM delta validation... """ |
|
123 bom_delta_validate = build.model.BOMDeltaXMLWriter((os.path.join(os.environ['HELIUM_HOME'], 'tests/data/bom/bom_validate_102_bom.xml')), (os.path.join(os.environ['HELIUM_HOME'], 'tests/data/bom/bom_validate_101_bom.xml'))) |
|
124 delta_bom_content_validity = bom_delta_validate.validate_delta_bom_contents(os.path.join(os.environ['HELIUM_HOME'], 'tests/data/bom/bom_validate_102_bom_delta.xml'), os.path.join(os.environ['HELIUM_HOME'], 'tests/data/bom/bom_validate_102_bom.xml'), os.path.join(os.environ['HELIUM_HOME'], 'tests/data/bom/bom_validate_101_bom.xml')) |
|
125 self.assertEqual(True, delta_bom_content_validity) |
|
126 delta_bom_content_validity = bom_delta_validate.validate_delta_bom_contents(os.path.join(os.environ['HELIUM_HOME'], 'tests/data/bom/bom_validate_104_bom_delta.xml'), os.path.join(os.environ['HELIUM_HOME'], 'tests/data/bom/bom_validate_102_bom.xml'), os.path.join(os.environ['HELIUM_HOME'], 'tests/data/bom/bom_validate_101_bom.xml')) |
|
127 self.assertEqual(False, delta_bom_content_validity) |
|
128 delta_bom_content_validity = bom_delta_validate.validate_delta_bom_contents(os.path.join(os.environ['HELIUM_HOME'], 'tests/data/bom/bom_validate_103_bom_delta.xml'), os.path.join(os.environ['HELIUM_HOME'], 'tests/data/bom/bom_validate_103_bom.xml'), os.path.join(os.environ['HELIUM_HOME'], 'tests/data/bom/bom_validate_102_bom.xml')) |
|
129 self.assertEqual(None, delta_bom_content_validity) |
|