diff options
author | Richard Purdie <richard.purdie@linuxfoundation.org> | 2016-08-01 09:38:23 +0100 |
---|---|---|
committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2016-08-01 09:38:35 +0100 |
commit | aa2d94542336f359a1205520e844c1bcff53712b (patch) | |
tree | 0e09d8049ec4e2e486026764173d6ea6ee4ccfac /bitbake | |
parent | 5b61fa04a335a4fdefd435dc25d4bac41ee21e39 (diff) | |
download | poky-aa2d94542336f359a1205520e844c1bcff53712b.tar.gz |
bitbake: lib/toaster: Fix missing new files from previous commits
(Bitbake rev: f77e6f21a2cc57a3fcb5970437e55cfae39849a3)
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'bitbake')
4 files changed, 415 insertions, 0 deletions
diff --git a/bitbake/lib/toaster/orm/migrations/0010_delete_layer_source_references.py b/bitbake/lib/toaster/orm/migrations/0010_delete_layer_source_references.py new file mode 100644 index 0000000000..f67388e990 --- /dev/null +++ b/bitbake/lib/toaster/orm/migrations/0010_delete_layer_source_references.py | |||
@@ -0,0 +1,118 @@ | |||
1 | # -*- coding: utf-8 -*- | ||
2 | from __future__ import unicode_literals | ||
3 | |||
4 | from django.db import migrations, models | ||
5 | import django.utils.timezone | ||
6 | |||
7 | |||
8 | class Migration(migrations.Migration): | ||
9 | |||
10 | dependencies = [ | ||
11 | ('orm', '0009_target_package_manifest_path'), | ||
12 | ] | ||
13 | |||
14 | operations = [ | ||
15 | migrations.AlterUniqueTogether( | ||
16 | name='releaselayersourcepriority', | ||
17 | unique_together=set([]), | ||
18 | ), | ||
19 | migrations.RemoveField( | ||
20 | model_name='releaselayersourcepriority', | ||
21 | name='layer_source', | ||
22 | ), | ||
23 | migrations.RemoveField( | ||
24 | model_name='releaselayersourcepriority', | ||
25 | name='release', | ||
26 | ), | ||
27 | migrations.DeleteModel( | ||
28 | name='ImportedLayerSource', | ||
29 | ), | ||
30 | migrations.DeleteModel( | ||
31 | name='LayerIndexLayerSource', | ||
32 | ), | ||
33 | migrations.DeleteModel( | ||
34 | name='LocalLayerSource', | ||
35 | ), | ||
36 | migrations.RemoveField( | ||
37 | model_name='recipe', | ||
38 | name='layer_source', | ||
39 | ), | ||
40 | migrations.RemoveField( | ||
41 | model_name='recipe', | ||
42 | name='up_id', | ||
43 | ), | ||
44 | migrations.AlterField( | ||
45 | model_name='layer', | ||
46 | name='up_date', | ||
47 | field=models.DateTimeField(default=django.utils.timezone.now, null=True), | ||
48 | ), | ||
49 | migrations.AlterField( | ||
50 | model_name='layer_version', | ||
51 | name='layer_source', | ||
52 | field=models.IntegerField(default=0, choices=[(0, 'local'), (1, 'layerindex'), (2, 'imported'), (3, 'build')]), | ||
53 | ), | ||
54 | migrations.AlterField( | ||
55 | model_name='layer_version', | ||
56 | name='up_date', | ||
57 | field=models.DateTimeField(default=django.utils.timezone.now, null=True), | ||
58 | ), | ||
59 | migrations.AlterUniqueTogether( | ||
60 | name='branch', | ||
61 | unique_together=set([]), | ||
62 | ), | ||
63 | migrations.AlterUniqueTogether( | ||
64 | name='layer', | ||
65 | unique_together=set([]), | ||
66 | ), | ||
67 | migrations.AlterUniqueTogether( | ||
68 | name='layer_version', | ||
69 | unique_together=set([]), | ||
70 | ), | ||
71 | migrations.AlterUniqueTogether( | ||
72 | name='layerversiondependency', | ||
73 | unique_together=set([]), | ||
74 | ), | ||
75 | migrations.AlterUniqueTogether( | ||
76 | name='machine', | ||
77 | unique_together=set([]), | ||
78 | ), | ||
79 | migrations.DeleteModel( | ||
80 | name='ReleaseLayerSourcePriority', | ||
81 | ), | ||
82 | migrations.RemoveField( | ||
83 | model_name='branch', | ||
84 | name='layer_source', | ||
85 | ), | ||
86 | migrations.RemoveField( | ||
87 | model_name='branch', | ||
88 | name='up_id', | ||
89 | ), | ||
90 | migrations.RemoveField( | ||
91 | model_name='layer', | ||
92 | name='layer_source', | ||
93 | ), | ||
94 | migrations.RemoveField( | ||
95 | model_name='layer', | ||
96 | name='up_id', | ||
97 | ), | ||
98 | migrations.RemoveField( | ||
99 | model_name='layer_version', | ||
100 | name='up_id', | ||
101 | ), | ||
102 | migrations.RemoveField( | ||
103 | model_name='layerversiondependency', | ||
104 | name='layer_source', | ||
105 | ), | ||
106 | migrations.RemoveField( | ||
107 | model_name='layerversiondependency', | ||
108 | name='up_id', | ||
109 | ), | ||
110 | migrations.RemoveField( | ||
111 | model_name='machine', | ||
112 | name='layer_source', | ||
113 | ), | ||
114 | migrations.RemoveField( | ||
115 | model_name='machine', | ||
116 | name='up_id', | ||
117 | ), | ||
118 | ] | ||
diff --git a/bitbake/lib/toaster/orm/migrations/0011_delete_layersource.py b/bitbake/lib/toaster/orm/migrations/0011_delete_layersource.py new file mode 100644 index 0000000000..75506961a9 --- /dev/null +++ b/bitbake/lib/toaster/orm/migrations/0011_delete_layersource.py | |||
@@ -0,0 +1,17 @@ | |||
1 | # -*- coding: utf-8 -*- | ||
2 | from __future__ import unicode_literals | ||
3 | |||
4 | from django.db import migrations, models | ||
5 | |||
6 | |||
7 | class Migration(migrations.Migration): | ||
8 | |||
9 | dependencies = [ | ||
10 | ('orm', '0010_delete_layer_source_references'), | ||
11 | ] | ||
12 | |||
13 | operations = [ | ||
14 | migrations.DeleteModel( | ||
15 | name='LayerSource', | ||
16 | ), | ||
17 | ] | ||
diff --git a/bitbake/lib/toaster/orm/migrations/0012_use_release_instead_of_up_branch.py b/bitbake/lib/toaster/orm/migrations/0012_use_release_instead_of_up_branch.py new file mode 100644 index 0000000000..0e6bb83311 --- /dev/null +++ b/bitbake/lib/toaster/orm/migrations/0012_use_release_instead_of_up_branch.py | |||
@@ -0,0 +1,62 @@ | |||
1 | # -*- coding: utf-8 -*- | ||
2 | from __future__ import unicode_literals | ||
3 | |||
4 | from django.db import migrations, models | ||
5 | from django.db.models import Q | ||
6 | |||
7 | |||
8 | def branch_to_release(apps, schema_editor): | ||
9 | Layer_Version = apps.get_model('orm', 'Layer_Version') | ||
10 | Release = apps.get_model('orm', 'Release') | ||
11 | |||
12 | print("Converting all layer version up_branches to releases") | ||
13 | # Find all the layer versions which have an upbranch and convert them to | ||
14 | # the release that they're for. | ||
15 | for layer_version in Layer_Version.objects.filter( | ||
16 | Q(release=None) & ~Q(up_branch=None)): | ||
17 | try: | ||
18 | # HEAD and local are equivalent | ||
19 | if "HEAD" in layer_version.up_branch.name: | ||
20 | release = Release.objects.get(name="local") | ||
21 | layer_version.commit = "HEAD" | ||
22 | layer_version.branch = "HEAD" | ||
23 | else: | ||
24 | release = Release.objects.get( | ||
25 | name=layer_version.up_branch.name) | ||
26 | |||
27 | layer_version.release = release | ||
28 | layer_version.save() | ||
29 | except Exception as e: | ||
30 | print("Couldn't work out an appropriate release for %s " | ||
31 | "the up_branch was %s " | ||
32 | "user the django admin interface to correct it" % | ||
33 | (layer_version.layer.name, layer_version.up_branch.name)) | ||
34 | print(e) | ||
35 | |||
36 | continue | ||
37 | |||
38 | |||
39 | class Migration(migrations.Migration): | ||
40 | |||
41 | dependencies = [ | ||
42 | ('orm', '0011_delete_layersource'), | ||
43 | ] | ||
44 | |||
45 | operations = [ | ||
46 | migrations.AddField( | ||
47 | model_name='layer_version', | ||
48 | name='release', | ||
49 | field=models.ForeignKey(to='orm.Release', default=None, null=True), | ||
50 | ), | ||
51 | migrations.RunPython(branch_to_release, | ||
52 | reverse_code=migrations.RunPython.noop), | ||
53 | |||
54 | migrations.RemoveField( | ||
55 | model_name='layer_version', | ||
56 | name='up_branch', | ||
57 | ), | ||
58 | |||
59 | migrations.DeleteModel( | ||
60 | name='Branch', | ||
61 | ), | ||
62 | ] | ||
diff --git a/bitbake/lib/toaster/tests/browser/selenium_helpers_base.py b/bitbake/lib/toaster/tests/browser/selenium_helpers_base.py new file mode 100644 index 0000000000..14e9c15648 --- /dev/null +++ b/bitbake/lib/toaster/tests/browser/selenium_helpers_base.py | |||
@@ -0,0 +1,218 @@ | |||
1 | #! /usr/bin/env python | ||
2 | # ex:ts=4:sw=4:sts=4:et | ||
3 | # -*- tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- | ||
4 | # | ||
5 | # BitBake Toaster Implementation | ||
6 | # | ||
7 | # Copyright (C) 2013-2016 Intel Corporation | ||
8 | # | ||
9 | # This program is free software; you can redistribute it and/or modify | ||
10 | # it under the terms of the GNU General Public License version 2 as | ||
11 | # published by the Free Software Foundation. | ||
12 | # | ||
13 | # This program is distributed in the hope that it will be useful, | ||
14 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
15 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
16 | # GNU General Public License for more details. | ||
17 | # | ||
18 | # You should have received a copy of the GNU General Public License along | ||
19 | # with this program; if not, write to the Free Software Foundation, Inc., | ||
20 | # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | ||
21 | # | ||
22 | # The Wait class and some of SeleniumDriverHelper and SeleniumTestCase are | ||
23 | # modified from Patchwork, released under the same licence terms as Toaster: | ||
24 | # https://github.com/dlespiau/patchwork/blob/master/patchwork/tests.browser.py | ||
25 | |||
26 | """ | ||
27 | Helper methods for creating Toaster Selenium tests which run within | ||
28 | the context of Django unit tests. | ||
29 | """ | ||
30 | |||
31 | import os | ||
32 | import time | ||
33 | import unittest | ||
34 | |||
35 | from django.contrib.staticfiles.testing import StaticLiveServerTestCase | ||
36 | from selenium import webdriver | ||
37 | from selenium.webdriver.support.ui import WebDriverWait | ||
38 | from selenium.webdriver.common.desired_capabilities import DesiredCapabilities | ||
39 | from selenium.common.exceptions import NoSuchElementException, \ | ||
40 | StaleElementReferenceException, TimeoutException | ||
41 | |||
42 | def create_selenium_driver(browser='chrome'): | ||
43 | # set default browser string based on env (if available) | ||
44 | env_browser = os.environ.get('TOASTER_TESTS_BROWSER') | ||
45 | if env_browser: | ||
46 | browser = env_browser | ||
47 | |||
48 | if browser == 'chrome': | ||
49 | return webdriver.Chrome( | ||
50 | service_args=["--verbose", "--log-path=selenium.log"] | ||
51 | ) | ||
52 | elif browser == 'firefox': | ||
53 | return webdriver.Firefox() | ||
54 | elif browser == 'marionette': | ||
55 | capabilities = DesiredCapabilities.FIREFOX | ||
56 | capabilities['marionette'] = True | ||
57 | return webdriver.Firefox(capabilities=capabilities) | ||
58 | elif browser == 'ie': | ||
59 | return webdriver.Ie() | ||
60 | elif browser == 'phantomjs': | ||
61 | return webdriver.PhantomJS() | ||
62 | else: | ||
63 | msg = 'Selenium driver for browser %s is not available' % browser | ||
64 | raise RuntimeError(msg) | ||
65 | |||
66 | class Wait(WebDriverWait): | ||
67 | """ | ||
68 | Subclass of WebDriverWait with predetermined timeout and poll | ||
69 | frequency. Also deals with a wider variety of exceptions. | ||
70 | """ | ||
71 | _TIMEOUT = 10 | ||
72 | _POLL_FREQUENCY = 0.5 | ||
73 | |||
74 | def __init__(self, driver): | ||
75 | super(Wait, self).__init__(driver, self._TIMEOUT, self._POLL_FREQUENCY) | ||
76 | |||
77 | def until(self, method, message=''): | ||
78 | """ | ||
79 | Calls the method provided with the driver as an argument until the | ||
80 | return value is not False. | ||
81 | """ | ||
82 | |||
83 | end_time = time.time() + self._timeout | ||
84 | while True: | ||
85 | try: | ||
86 | value = method(self._driver) | ||
87 | if value: | ||
88 | return value | ||
89 | except NoSuchElementException: | ||
90 | pass | ||
91 | except StaleElementReferenceException: | ||
92 | pass | ||
93 | |||
94 | time.sleep(self._poll) | ||
95 | if time.time() > end_time: | ||
96 | break | ||
97 | |||
98 | raise TimeoutException(message) | ||
99 | |||
100 | def until_not(self, method, message=''): | ||
101 | """ | ||
102 | Calls the method provided with the driver as an argument until the | ||
103 | return value is False. | ||
104 | """ | ||
105 | |||
106 | end_time = time.time() + self._timeout | ||
107 | while True: | ||
108 | try: | ||
109 | value = method(self._driver) | ||
110 | if not value: | ||
111 | return value | ||
112 | except NoSuchElementException: | ||
113 | return True | ||
114 | except StaleElementReferenceException: | ||
115 | pass | ||
116 | |||
117 | time.sleep(self._poll) | ||
118 | if time.time() > end_time: | ||
119 | break | ||
120 | |||
121 | raise TimeoutException(message) | ||
122 | |||
123 | class SeleniumTestCaseBase(unittest.TestCase): | ||
124 | """ | ||
125 | NB StaticLiveServerTestCase is used as the base test case so that | ||
126 | static files are served correctly in a Selenium test run context; see | ||
127 | https://docs.djangoproject.com/en/1.9/ref/contrib/staticfiles/#specialized-test-case-to-support-live-testing | ||
128 | """ | ||
129 | |||
130 | @classmethod | ||
131 | def setUpClass(cls): | ||
132 | """ Create a webdriver driver at the class level """ | ||
133 | |||
134 | super(SeleniumTestCaseBase, cls).setUpClass() | ||
135 | |||
136 | # instantiate the Selenium webdriver once for all the test methods | ||
137 | # in this test case | ||
138 | cls.driver = create_selenium_driver() | ||
139 | cls.driver.maximize_window() | ||
140 | |||
141 | @classmethod | ||
142 | def tearDownClass(cls): | ||
143 | """ Clean up webdriver driver """ | ||
144 | |||
145 | cls.driver.quit() | ||
146 | super(SeleniumTestCaseBase, cls).tearDownClass() | ||
147 | |||
148 | def get(self, url): | ||
149 | """ | ||
150 | Selenium requires absolute URLs, so convert Django URLs returned | ||
151 | by resolve() or similar to absolute ones and get using the | ||
152 | webdriver instance. | ||
153 | |||
154 | url: a relative URL | ||
155 | """ | ||
156 | abs_url = '%s%s' % (self.live_server_url, url) | ||
157 | self.driver.get(abs_url) | ||
158 | |||
159 | def find(self, selector): | ||
160 | """ Find single element by CSS selector """ | ||
161 | return self.driver.find_element_by_css_selector(selector) | ||
162 | |||
163 | def find_all(self, selector): | ||
164 | """ Find all elements matching CSS selector """ | ||
165 | return self.driver.find_elements_by_css_selector(selector) | ||
166 | |||
167 | def element_exists(self, selector): | ||
168 | """ | ||
169 | Return True if one element matching selector exists, | ||
170 | False otherwise | ||
171 | """ | ||
172 | return len(self.find_all(selector)) == 1 | ||
173 | |||
174 | def focused_element(self): | ||
175 | """ Return the element which currently has focus on the page """ | ||
176 | return self.driver.switch_to.active_element | ||
177 | |||
178 | def wait_until_present(self, selector): | ||
179 | """ Wait until element matching CSS selector is on the page """ | ||
180 | is_present = lambda driver: self.find(selector) | ||
181 | msg = 'An element matching "%s" should be on the page' % selector | ||
182 | element = Wait(self.driver).until(is_present, msg) | ||
183 | return element | ||
184 | |||
185 | def wait_until_visible(self, selector): | ||
186 | """ Wait until element matching CSS selector is visible on the page """ | ||
187 | is_visible = lambda driver: self.find(selector).is_displayed() | ||
188 | msg = 'An element matching "%s" should be visible' % selector | ||
189 | Wait(self.driver).until(is_visible, msg) | ||
190 | return self.find(selector) | ||
191 | |||
192 | def wait_until_focused(self, selector): | ||
193 | """ Wait until element matching CSS selector has focus """ | ||
194 | is_focused = \ | ||
195 | lambda driver: self.find(selector) == self.focused_element() | ||
196 | msg = 'An element matching "%s" should be focused' % selector | ||
197 | Wait(self.driver).until(is_focused, msg) | ||
198 | return self.find(selector) | ||
199 | |||
200 | def enter_text(self, selector, value): | ||
201 | """ Insert text into element matching selector """ | ||
202 | # note that keyup events don't occur until the element is clicked | ||
203 | # (in the case of <input type="text"...>, for example), so simulate | ||
204 | # user clicking the element before inserting text into it | ||
205 | field = self.click(selector) | ||
206 | |||
207 | field.send_keys(value) | ||
208 | return field | ||
209 | |||
210 | def click(self, selector): | ||
211 | """ Click on element which matches CSS selector """ | ||
212 | element = self.wait_until_visible(selector) | ||
213 | element.click() | ||
214 | return element | ||
215 | |||
216 | def get_page_source(self): | ||
217 | """ Get raw HTML for the current page """ | ||
218 | return self.driver.page_source | ||