Skip to content

Commit a96d59a

Browse files
committed
Create unit test for QgsMetadataBase
1 parent 5cf2656 commit a96d59a

File tree

3 files changed

+516
-218
lines changed

3 files changed

+516
-218
lines changed

tests/src/python/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ ADD_PYTHON_TEST(PyQgsMapRendererCache test_qgsmaprenderercache.py)
109109
ADD_PYTHON_TEST(PyQgsMapThemeCollection test_qgsmapthemecollection.py)
110110
ADD_PYTHON_TEST(PyQgsMapUnitScale test_qgsmapunitscale.py)
111111
ADD_PYTHON_TEST(PyQgsMargins test_qgsmargins.py)
112+
ADD_PYTHON_TEST(PyQgsMetadataBase test_qgsmetadatabase.py)
112113
ADD_PYTHON_TEST(PyQgsMemoryProvider test_provider_memory.py)
113114
ADD_PYTHON_TEST(PyQgsMultiEditToolButton test_qgsmultiedittoolbutton.py)
114115
ADD_PYTHON_TEST(PyQgsNetworkContentFetcher test_qgsnetworkcontentfetcher.py)

tests/src/python/test_qgslayermetadata.py

Lines changed: 0 additions & 218 deletions
Original file line numberDiff line numberDiff line change
@@ -142,105 +142,6 @@ def testEquality(self):
142142
self.assertNotEqual(constraint, QgsLayerMetadata.Constraint('c2', 'type1'))
143143
self.assertNotEqual(constraint, QgsLayerMetadata.Constraint('c', 'type2'))
144144

145-
a = QgsLayerMetadata.Address()
146-
a.type = 'postal'
147-
a.address = '13 north rd'
148-
a.city = 'huxleys haven'
149-
a.administrativeArea = 'land of the queens'
150-
a.postalCode = '4123'
151-
a.country = 'straya!'
152-
a2 = QgsLayerMetadata.Address(a)
153-
self.assertEqual(a, a2)
154-
a2.type = 'postal2'
155-
self.assertNotEqual(a, a2)
156-
a2 = QgsLayerMetadata.Address(a)
157-
a2.address = 'address2'
158-
self.assertNotEqual(a, a2)
159-
a2 = QgsLayerMetadata.Address(a)
160-
a2.city = 'city'
161-
self.assertNotEqual(a, a2)
162-
a2 = QgsLayerMetadata.Address(a)
163-
a2.administrativeArea = 'area2'
164-
self.assertNotEqual(a, a2)
165-
a2 = QgsLayerMetadata.Address(a)
166-
a2.postalCode = 'postal2'
167-
self.assertNotEqual(a, a2)
168-
a2 = QgsLayerMetadata.Address(a)
169-
a2.country = 'country2'
170-
self.assertNotEqual(a, a2)
171-
172-
c = QgsLayerMetadata.Contact()
173-
c.name = 'name'
174-
c.organization = 'org'
175-
c.position = 'pos'
176-
c.voice = '1500 515 555'
177-
c.fax = 'fax'
178-
c.email = 'email'
179-
c.role = 'role'
180-
a = QgsLayerMetadata.Address()
181-
a.type = 'postal'
182-
a2 = QgsLayerMetadata.Address()
183-
a2.type = 'street'
184-
c.addresses = [a, a2]
185-
c2 = QgsLayerMetadata.Contact(c)
186-
self.assertEqual(c, c2)
187-
c2.name = 'name2'
188-
self.assertNotEqual(c, c2)
189-
c2 = QgsLayerMetadata.Contact(c)
190-
c2.organization = 'org2'
191-
self.assertNotEqual(c, c2)
192-
c2 = QgsLayerMetadata.Contact(c)
193-
c2.position = 'pos2'
194-
self.assertNotEqual(c, c2)
195-
c2 = QgsLayerMetadata.Contact(c)
196-
c2.voice = 'voice2'
197-
self.assertNotEqual(c, c2)
198-
c2 = QgsLayerMetadata.Contact(c)
199-
c2.fax = 'fax2'
200-
self.assertNotEqual(c, c2)
201-
c2 = QgsLayerMetadata.Contact(c)
202-
c2.email = 'email2'
203-
self.assertNotEqual(c, c2)
204-
c2 = QgsLayerMetadata.Contact(c)
205-
c2.role = 'role2'
206-
self.assertNotEqual(c, c2)
207-
c2 = QgsLayerMetadata.Contact(c)
208-
c2.addresses = [a2]
209-
self.assertNotEqual(c, c2)
210-
211-
# link
212-
l = QgsLayerMetadata.Link()
213-
l.name = 'name'
214-
l.type = 'type'
215-
l.description = 'desc'
216-
l.url = 'url'
217-
l.format = 'format'
218-
l.mimeType = 'mime'
219-
l.size = '112'
220-
l2 = QgsLayerMetadata.Link(l)
221-
self.assertEqual(l, l2)
222-
l2 = QgsLayerMetadata.Link(l)
223-
l2.name = 'name2'
224-
self.assertNotEqual(l, l2)
225-
l2 = QgsLayerMetadata.Link(l)
226-
l2.type = 'type2'
227-
self.assertNotEqual(l, l2)
228-
l2 = QgsLayerMetadata.Link(l)
229-
l2.description = 'desc2'
230-
self.assertNotEqual(l, l2)
231-
l2 = QgsLayerMetadata.Link(l)
232-
l2.url = 'url2'
233-
self.assertNotEqual(l, l2)
234-
l2 = QgsLayerMetadata.Link(l)
235-
l2.format = 'format2'
236-
self.assertNotEqual(l, l2)
237-
l2 = QgsLayerMetadata.Link(l)
238-
l2.mimeType = 'mime2'
239-
self.assertNotEqual(l, l2)
240-
l2 = QgsLayerMetadata.Link(l)
241-
l2.size = '113'
242-
self.assertNotEqual(l, l2)
243-
244145
def testExtent(self):
245146
e = QgsLayerMetadata.Extent()
246147
se = QgsLayerMetadata.SpatialExtent()
@@ -263,123 +164,6 @@ def testExtent(self):
263164
self.assertEqual(m.extent().temporalExtents()[0].begin(), QDateTime(QDate(2017, 1, 3), QTime(11, 34, 56)))
264165
self.assertEqual(m.extent().temporalExtents()[0].end(), QDateTime(QDate(2018, 1, 3), QTime(12, 35, 57)))
265166

266-
def testKeywords(self):
267-
m = QgsLayerMetadata()
268-
269-
m.setKeywords({'gmd:topicCategory': ['natural']})
270-
self.assertEqual(m.keywords(), {'gmd:topicCategory': ['natural']})
271-
self.assertEqual(m.categories(), ['natural'])
272-
self.assertTrue(m.removeKeywords('gmd:topicCategory'))
273-
274-
m.setKeywords({'vocab a': ['keyword a', 'other a'],
275-
'vocab b': ['keyword b', 'other b']})
276-
self.assertEqual(m.keywords(), {'vocab a': ['keyword a', 'other a'],
277-
'vocab b': ['keyword b', 'other b']})
278-
self.assertEqual(m.keywordVocabularies(), ['vocab a', 'vocab b'])
279-
self.assertEqual(m.keywords('vocab a'), ['keyword a', 'other a'])
280-
self.assertEqual(m.keywords('vocab b'), ['keyword b', 'other b'])
281-
self.assertEqual(m.keywords('not valid'), [])
282-
283-
m.addKeywords('vocab c', ['keyword c'])
284-
self.assertEqual(m.keywords(), {'vocab a': ['keyword a', 'other a'],
285-
'vocab b': ['keyword b', 'other b'],
286-
'vocab c': ['keyword c']})
287-
# replace existing using addKeywords
288-
m.addKeywords('vocab c', ['c'])
289-
self.assertEqual(m.keywords(), {'vocab a': ['keyword a', 'other a'],
290-
'vocab b': ['keyword b', 'other b'],
291-
'vocab c': ['c']})
292-
# replace existing using setKeywords
293-
m.setKeywords({'x': ['x'], 'y': ['y']})
294-
self.assertEqual(m.keywords(), {'x': ['x'],
295-
'y': ['y']})
296-
297-
def testAddress(self):
298-
a = QgsLayerMetadata.Address()
299-
a.type = 'postal'
300-
a.address = '13 north rd'
301-
a.city = 'huxleys haven'
302-
a.administrativeArea = 'land of the queens'
303-
a.postalCode = '4123'
304-
a.country = 'straya!'
305-
self.assertEqual(a.type, 'postal')
306-
self.assertEqual(a.address, '13 north rd')
307-
self.assertEqual(a.city, 'huxleys haven')
308-
self.assertEqual(a.administrativeArea, 'land of the queens')
309-
self.assertEqual(a.postalCode, '4123')
310-
self.assertEqual(a.country, 'straya!')
311-
312-
def testContact(self):
313-
c = QgsLayerMetadata.Contact()
314-
c.name = 'Prince Gristle'
315-
c.organization = 'Bergen co'
316-
c.position = 'prince'
317-
c.voice = '1500 515 555'
318-
c.fax = 'who the f*** still uses fax?'
319-
c.email = 'limpbiskitrulez69@hotmail.com'
320-
c.role = 'person to blame when all goes wrong'
321-
a = QgsLayerMetadata.Address()
322-
a.type = 'postal'
323-
a2 = QgsLayerMetadata.Address()
324-
a2.type = 'street'
325-
c.addresses = [a, a2]
326-
self.assertEqual(c.name, 'Prince Gristle')
327-
self.assertEqual(c.organization, 'Bergen co')
328-
self.assertEqual(c.position, 'prince')
329-
self.assertEqual(c.voice, '1500 515 555')
330-
self.assertEqual(c.fax, 'who the f*** still uses fax?')
331-
self.assertEqual(c.email, 'limpbiskitrulez69@hotmail.com')
332-
self.assertEqual(c.role, 'person to blame when all goes wrong')
333-
self.assertEqual(c.addresses[0].type, 'postal')
334-
self.assertEqual(c.addresses[1].type, 'street')
335-
336-
m = QgsLayerMetadata()
337-
c2 = QgsLayerMetadata.Contact(c)
338-
c2.name = 'Bridgette'
339-
340-
m.setContacts([c, c2])
341-
self.assertEqual(m.contacts()[0].name, 'Prince Gristle')
342-
self.assertEqual(m.contacts()[1].name, 'Bridgette')
343-
344-
# add contact
345-
c3 = QgsLayerMetadata.Contact(c)
346-
c3.name = 'Princess Poppy'
347-
m.addContact(c3)
348-
self.assertEqual(len(m.contacts()), 3)
349-
self.assertEqual(m.contacts()[2].name, 'Princess Poppy')
350-
351-
def testLinks(self):
352-
l = QgsLayerMetadata.Link()
353-
l.name = 'Trashbat'
354-
l.type = 'fashion'
355-
l.description = 'registered in the cook islands!'
356-
l.url = 'http://trashbat.co.uk'
357-
l.format = 'whois'
358-
l.mimeType = 'text/string'
359-
l.size = '112'
360-
self.assertEqual(l.name, 'Trashbat')
361-
self.assertEqual(l.type, 'fashion')
362-
self.assertEqual(l.description, 'registered in the cook islands!')
363-
self.assertEqual(l.url, 'http://trashbat.co.uk')
364-
self.assertEqual(l.format, 'whois')
365-
self.assertEqual(l.mimeType, 'text/string')
366-
self.assertEqual(l.size, '112')
367-
368-
m = QgsLayerMetadata()
369-
l2 = QgsLayerMetadata.Link(l)
370-
l2.name = 'Trashbat2'
371-
372-
m.setLinks([l, l2])
373-
self.assertEqual(m.links()[0].name, 'Trashbat')
374-
self.assertEqual(m.links()[1].name, 'Trashbat2')
375-
376-
# add link
377-
l3 = QgsLayerMetadata.Link(l)
378-
l3.name = 'Trashbat3'
379-
m.addLink(l3)
380-
self.assertEqual(len(m.links()), 3)
381-
self.assertEqual(m.links()[2].name, 'Trashbat3')
382-
383167
def createTestMetadata(self):
384168
"""
385169
Returns a standard metadata which can be tested with checkExpectedMetadata
@@ -548,8 +332,6 @@ def testSaveReadFromXml(self):
548332
"""
549333
Test saving and reading metadata from a XML.
550334
"""
551-
vl = QgsVectorLayer('Point', 'test', 'memory')
552-
self.assertTrue(vl.isValid())
553335

554336
# save metadata to XML
555337
m = self.createTestMetadata()

0 commit comments

Comments
 (0)