Debian Codegraph @

dbaccess/qa/uitest/query/insert_relation.py

raw symbols SCIP
1 # -*- tab-width: 4; indent-tabs-mode: nil; py-indent-offset: 4 -*-
2 #
3 # This file is part of the LibreOffice project.
4 #
5 # This Source Code Form is subject to the terms of the Mozilla Public
6 # License, v. 2.0. If a copy of the MPL was not distributed with this
7 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 #
9 from uitest.framework import UITestCase
10 from uitest.uihelper.common import get_state_as_dict, select_by_text
11 from uitest.test import DEFAULT_SLEEP
12 from libreoffice.uno.propertyvalue import mkPropertyValues
13 from libreoffice.uno.eventlistener import EventListener
14
15 import time
16
17 class InsertRelation(UITestCase):
18 # Previously the Insert Relation dialog wouldn’t let you select a table in one box if the other
19 # box already has it selected. This test checks the new behaviour where you can select any of
20 # the three tables and the other table changes itself so that it’s not the same.
21 def test_choose_between_three_tables(self):
22 with self.ui_test.create_db_in_start_center() as xDocument:
23 # Create three tables using the design view
24 for table_num in range(3):
25 with self.ui_test.open_subcomponent_through_command(
26 ".uno:DBNewTable", close_win=False) as xTableFrame:
27
28 # Press TAB in the table editor and then type in a field name
29 xTableWindow = self.xUITest.getWindow(xTableFrame.getContainerWindow())
30 xTableEditor = xTableWindow.getChild("DBTableEditor")
31 xTableEditor.executeAction("TYPE", mkPropertyValues({"KEYCODE": "TAB"}))
32 self.xUITest.getFocusWindow().executeAction(
33 "SET", mkPropertyValues({"TEXT": f"field{table_num + 1}"}))
34
35 # Close the window. This will open a dialog asking if we want to save
36 with self.ui_test.execute_blocking_action(
37 self.xUITest.executeCommandForProvider,
38 args=(".uno:CloseWin", xTableFrame),
39 close_button=None) as xSaveDialog:
40 # Choose yes. This will open another dialog asking us to name the table
41 with self.ui_test.execute_blocking_action(
42 xSaveDialog.getChild("yes").executeAction,
43 args=("CLICK", tuple()),
44 close_button=None) as xNameDialog:
45 xNameDialog.getChild("title").executeAction(
46 "SET", mkPropertyValues({"TEXT": f"table{table_num + 1}"}))
47 # Clicking OK will open a third dialog
48 # asking if we want to add a primary key
49 with self.ui_test.execute_blocking_action(
50 xNameDialog.getChild("ok").executeAction,
51 args=("CLICK", tuple()),
52 close_button="yes"):
53 pass
54
55 # Create a new query with the design view. This will open a new frame for the query as
56 # well as a modeless dialog to add the tables
57 with EventListener(self.xContext, "DialogExecute") as event:
58 with self.ui_test.open_subcomponent_through_command(
59 ".uno:DBNewQuery") as xQueryFrame:
60 while not event.executed:
61 time.sleep(DEFAULT_SLEEP)
62 try:
63 xAddTablesDialog = self.xUITest.getTopFocusWindow()
64 xTableList = xAddTablesDialog.getChild("tablelist")
65 xAdd = xAddTablesDialog.getChild("add")
66 # Select and add all of the tables in turn
67 for i in range(3):
68 xTableList.getChild(str(i)).executeAction("SELECT", tuple())
69 xAdd.executeAction("CLICK", tuple())
70 finally:
71 self.ui_test.close_dialog_through_button(
72 xAddTablesDialog.getChild("close"), xAddTablesDialog)
73
74 xQueryController = xQueryFrame.getController()
75
76 with self.ui_test.execute_blocking_action(
77 self.xUITest.executeCommandForProvider,
78 args=(".uno:DBAddRelation", xQueryController),
79 close_button="cancel") as xDialog:
80 xTable1 = xDialog.getChild("table1")
81 xTable2 = xDialog.getChild("table2")
82
83 table2_value = get_state_as_dict(xTable2)["SelectEntryText"]
84
85 # Try setting table1 to the same value as table2
86 select_by_text(xTable1, table2_value)
87 # Make sure that it worked
88 self.assertEqual(get_state_as_dict(xTable1)["SelectEntryText"],
89 table2_value)
90 self.assertTrue(get_state_as_dict(xTable2)["SelectEntryText"] !=
91 table2_value)
92
93 # Try choosing all 3 tables for table1
94 for i in range(3):
95 table_name = f"table{i + 1}"
96 select_by_text(xTable1, table_name)
97 self.assertEqual(get_state_as_dict(xTable1)["SelectEntryText"],
98 table_name)
99 self.assertTrue(get_state_as_dict(xTable2)["SelectEntryText"] !=
100 table_name)
101
102 # vim: set shiftwidth=4 softtabstop=4 expandtab: