16
16
import os
17
17
import filecmp
18
18
19
- from qgis .core import (QgsVectorLayer ,
19
+ from qgis .core import (QgsApplication ,
20
+ QgsVectorLayer ,
20
21
QgsReadWriteContext ,
21
- QgsEditFormConfig )
22
+ QgsEditFormConfig ,
23
+ QgsFetchedContent )
22
24
from qgis .gui import QgsGui
23
25
24
26
from qgis .testing import start_app , unittest
25
27
from qgis .PyQt .QtXml import QDomDocument , QDomElement
26
28
from utilities import unitTestDataPath
29
+ import socketserver
30
+ import threading
31
+ import http .server
27
32
28
- TEST_DATA_DIR = unitTestDataPath ()
29
- start_app ()
33
+ app = start_app ()
30
34
31
35
32
36
class TestQgsEditFormConfig (unittest .TestCase ):
@@ -35,6 +39,17 @@ class TestQgsEditFormConfig(unittest.TestCase):
35
39
def setUpClass (cls ):
36
40
QgsGui .editorWidgetRegistry ().initEditors ()
37
41
42
+ # Bring up a simple HTTP server
43
+ os .chdir (unitTestDataPath () + '' )
44
+ handler = http .server .SimpleHTTPRequestHandler
45
+
46
+ cls .httpd = socketserver .TCPServer (('localhost' , 0 ), handler )
47
+ cls .port = cls .httpd .server_address [1 ]
48
+
49
+ cls .httpd_thread = threading .Thread (target = cls .httpd .serve_forever )
50
+ cls .httpd_thread .setDaemon (True )
51
+ cls .httpd_thread .start ()
52
+
38
53
def createLayer (self ):
39
54
self .layer = QgsVectorLayer ("Point?field=fldtxt:string&field=fldint:integer" ,
40
55
"addfeat" , "memory" )
@@ -66,28 +81,26 @@ def testFormUi(self):
66
81
layer = self .createLayer ()
67
82
config = layer .editFormConfig ()
68
83
69
- uiLocal = os .path .join (TEST_DATA_DIR , 'layer_attribute_form.ui' )
70
- (ok , _ ) = config .setUiForm (uiLocal )
71
- self .assertTrue (ok )
72
- self .assertEqual (config .layout (), QgsEditFormConfig .UiFileLayout )
73
- self .assertEqual (config .uiForm (QgsEditFormConfig .Original ), uiLocal )
74
- self .assertEqual (config .uiForm (QgsEditFormConfig .LocalCopy ), uiLocal )
84
+ config .setLayout (QgsEditFormConfig .GeneratedLayout )
85
+ self .assertEqual (config .layout (), QgsEditFormConfig .GeneratedLayout )
75
86
76
- uiUrl = 'https://raw.githubusercontent.com/3nids/QGIS/7ac09b1f9b1921e7f95ab077d97dcf0dfd57be4a/tests/testdata/layer_attribute_form.ui'
77
- (ok , _ ) = config .setUiForm (uiUrl )
78
- self .assertTrue (ok )
87
+ uiLocal = os .path .join (unitTestDataPath (), '/qgis_local_server/layer_attribute_form.ui' )
88
+ config .setUiForm (uiLocal )
79
89
self .assertEqual (config .layout (), QgsEditFormConfig .UiFileLayout )
80
- self .assertEqual (config .uiForm (QgsEditFormConfig .Original ), uiUrl )
81
- localCopy = config .uiForm (QgsEditFormConfig .LocalCopy )
82
- self .assertNotEqual (localCopy , uiUrl )
83
- filecmp .cmp (localCopy , uiLocal )
84
-
85
- uiBadUrl = 'http://www.qwertzuiopasdfghjklyxcvbnm.qwer/xxx.ui'
86
- (ok , _ ) = config .setUiForm (uiBadUrl )
87
- self .assertFalse (ok )
90
+
91
+ config .setLayout (QgsEditFormConfig .GeneratedLayout )
88
92
self .assertEqual (config .layout (), QgsEditFormConfig .GeneratedLayout )
89
- self .assertEqual (config .uiForm (QgsEditFormConfig .Original ), uiBadUrl )
90
- self .assertEqual (config .uiForm (QgsEditFormConfig .LocalCopy ), '' )
93
+
94
+ uiUrl = 'http://localhost:' + str (self .port ) + '/qgis_local_server/layer_attribute_form.ui'
95
+ config .setUiForm (uiUrl )
96
+ self .assertEqual (config .layout (), QgsEditFormConfig .UiFileLayout )
97
+ content = QgsApplication .networkContentFetcherRegistry ().fetch (uiUrl )
98
+ self .assertTrue (content is not None )
99
+ while True :
100
+ if content .status () in (QgsFetchedContent .Finished , QgsFetchedContent .Failed ):
101
+ break
102
+ app .processEvents ()
103
+ self .assertEqual (content .status (), QgsFetchedContent .Finished )
91
104
92
105
def testReadOnly (self ):
93
106
layer = self .createLayer ()
0 commit comments