Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
ckanext-odsh
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Open-Data
ckanext-odsh
Commits
a839cac1
Commit
a839cac1
authored
6 years ago
by
chbaeh
Browse files
Options
Downloads
Patches
Plain Diff
add unit tests for validation
parent
5407174b
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
ckanext/odsh/tests/test_validation.py
+69
-0
69 additions, 0 deletions
ckanext/odsh/tests/test_validation.py
with
69 additions
and
0 deletions
ckanext/odsh/tests/test_validation.py
0 → 100644
+
69
−
0
View file @
a839cac1
import
sys
import
json
from
nose.tools
import
*
from
mock
import
MagicMock
,
Mock
,
patch
def
mockInvalid
(
*
args
,
**
kwargs
):
return
Exception
(
*
args
,
**
kwargs
)
def
mock_
(
s
):
return
s
sys
.
modules
[
'
ckan
'
]
=
MagicMock
()
sys
.
modules
[
'
ckan.plugins
'
]
=
MagicMock
()
sys
.
modules
[
'
ckan.plugins.toolkit
'
]
=
MagicMock
()
sys
.
modules
[
'
ckan.model
'
]
=
MagicMock
()
sys
.
modules
[
'
ckan.lib
'
]
=
MagicMock
()
sys
.
modules
[
'
ckan.lib.navl
'
]
=
MagicMock
()
sys
.
modules
[
'
ckan.lib.navl.dictization_functions
'
]
=
MagicMock
()
sys
.
modules
[
'
pylons
'
]
=
MagicMock
()
import
ckan.plugins.toolkit
as
toolkit
toolkit
.
Invalid
=
mockInvalid
toolkit
.
_
=
mock_
import
pylons
from
ckanext.odsh.validation
import
*
def
test_get_validators
():
assert
get_validators
()
def
test_tag_string_convert
():
# arrange
data
=
{
'
tag_string
'
:
'
tag1,tag2
'
}
# act
tag_string_convert
(
'
tag_string
'
,
data
,
{},
None
)
# assert
assert
data
[(
'
tags
'
,
0
,
'
name
'
)]
==
'
tag1
'
assert
data
[(
'
tags
'
,
1
,
'
name
'
)]
==
'
tag2
'
@raises
(
Exception
)
def
test_tag_name_validator_invalid
():
tag_name_validator
(
'
&
'
,
None
)
def
test_tag_name_validator_valid
():
tag_name_validator
(
'
valid
'
,
None
)
@patch
(
'
urllib2.urlopen
'
)
@patch
(
'
pylons.config.get
'
,
side_effect
=
'
foo
'
)
@patch
(
'
csv.reader
'
,
side_effect
=
[[[
'
uri
'
,
'
text
'
,
json
.
dumps
({
"
geometry
"
:
0
})]]])
def
test_known_spatial_uri
(
url_mock
,
get_mock
,
csv_mock
):
# arrange
data
=
{(
'
extras
'
,
0
,
'
key
'
):
'
spatial_uri
'
,
(
'
extras
'
,
0
,
'
value
'
):
'
uri
'
}
# act
known_spatial_uri
(
'
spatial_uri
'
,
data
,
{},
None
)
# assert
assert
data
[(
'
extras
'
,
1
,
'
key
'
)]
==
'
spatial_text
'
assert
data
[(
'
extras
'
,
1
,
'
value
'
)]
==
'
text
'
assert
data
[(
'
extras
'
,
2
,
'
key
'
)]
==
'
spatial
'
assert
data
[(
'
extras
'
,
2
,
'
value
'
)]
==
'
0
'
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment