Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
cubicweb
cubes
postgis
Commits
30eec09dd074
Commit
5c34c862
authored
Jan 15, 2016
by
Julien Cristau
Browse files
Start adding some tests
parent
781f4d446261
Changes
3
Hide whitespace changes
Inline
Side-by-side
.hgignore
0 → 100644
View file @
30eec09d
test/data/database
test/data/schema.py
0 → 100644
View file @
30eec09d
# -*- coding: utf-8 -*-
# copyright 2015 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
# contact http://www.logilab.fr -- mailto:contact@logilab.fr
#
# This program is free software: you can redistribute it and/or modify it under
# the terms of the GNU Lesser General Public License as published by the Free
# Software Foundation, either version 2.1 of the License, or (at your option)
# any later version.
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
# details.
#
# You should have received a copy of the GNU Lesser General Public License along
# with this program. If not, see <http://www.gnu.org/licenses/>.
from
yams.buildobjs
import
EntityType
,
String
from
cubes.postgis.schema
import
Geometry
,
Geography
class
City
(
EntityType
):
name
=
String
(
required
=
True
,
maxsize
=
100
)
center_4326
=
Geometry
(
srid
=
4326
,
geom_type
=
'POINT'
)
center_nosrid
=
Geometry
(
srid
=-
1
,
geom_type
=
'POINT'
)
limits
=
Geography
(
geom_type
=
'POLYGON'
)
test/test_postgis.py
View file @
30eec09d
...
...
@@ -14,36 +14,42 @@
# You should have received a copy of the GNU Lesser General Public License along
# with this program. If not, see <http://www.gnu.org/licenses/>.
"""cubicweb-postgis automatic tests
uncomment code below if you want to activate automatic test for your cube:
"""cubicweb-postgis tests
"""
.. sourcecode:: python
from
cubicweb.devtools
import
testlib
from
cubicweb.devtools
import
(
startpgcluster
,
stoppgcluster
,
PostgresApptestConfiguration
)
from cubicweb.devtools.testlib import AutomaticWebTest
def
setUpModule
():
startpgcluster
(
__file__
)
class AutomaticWebTest(AutomaticWebTest):
'''provides `to_test_etypes` and/or `list_startup_views` implementation
to limit test scope
'''
def
tearDownModule
():
stoppgcluster
(
__file__
)
def to_test_etypes(self):
'''only test views for entities of the returned types'''
return set(('My', 'Cube', 'Entity', 'Types'))
def list_startup_views(self):
'''only test startup views of the returned identifiers'''
return ('some', 'startup', 'views')
"""
class
PostgisTC
(
testlib
.
CubicWebTC
):
configcls
=
PostgresApptestConfiguration
from
cubicweb.devtools
import
testlib
def
test_geometry_srid
(
self
):
with
self
.
admin_access
.
repo_cnx
()
as
cnx
:
cnx
.
create_entity
(
'City'
,
name
=
u
'Paris'
,
center_4326
=
(
u
'POINT(48.4 2.34)'
,
4326
))
cnx
.
commit
()
self
.
assertEqual
(
cnx
.
execute
(
'Any ST_SRID(C) WHERE X center_4326 C'
)[
0
][
0
],
4326
)
# wrong srid
with
self
.
assertRaises
(
Exception
)
as
ctx
:
cnx
.
create_entity
(
'City'
,
name
=
u
'Nantes'
,
center_4326
=
(
u
'POINT(47.25 1.5)'
,
-
1
))
self
.
assertEqual
(
ctx
.
exception
.
__class__
.
__name__
,
'DataError'
)
class
DefaultTC
(
testlib
.
CubicWebTC
):
def
test_something
(
self
):
self
.
skipTest
(
'this cube has no test'
)
def
test_geometry_nosrid
(
self
):
with
self
.
admin_access
.
repo_cnx
()
as
cnx
:
cnx
.
create_entity
(
'City'
,
name
=
u
'Paris'
,
center_nosrid
=
(
u
'POINT(48.4 2.34)'
,
4326
))
cnx
.
commit
()
self
.
assertEqual
(
cnx
.
execute
(
'Any ST_SRID(C) WHERE X center_nosrid C'
)[
0
][
0
],
4326
)
cnx
.
create_entity
(
'City'
,
name
=
u
'Nantes'
,
center_nosrid
=
(
u
'POINT(47.25 1.5)'
,
-
1
))
cnx
.
commit
()
if
__name__
==
'__main__'
:
from
logilab.common.testlib
import
unittest
_main
unittest
_
main
()
import
unittest
unittest
.
main
()
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment