Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
P
PEDASI
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Research Software Group
PEDASI
Commits
fe65f4eb
Commit
fe65f4eb
authored
6 years ago
by
James Graham
Browse files
Options
Downloads
Patches
Plain Diff
Remove redundant HyperCat connector tests and change data for API test
parent
665d1cad
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
api/tests.py
+2
-2
2 additions, 2 deletions
api/tests.py
datasources/tests/test_connectors_hypercat.py
+31
-138
31 additions, 138 deletions
datasources/tests/test_connectors_hypercat.py
with
33 additions
and
140 deletions
api/tests.py
+
2
−
2
View file @
fe65f4eb
...
...
@@ -482,8 +482,8 @@ class DataSourceApiIoTUKTest(TestCase):
class
DataSourceApiHyperCatTest
(
TestCase
):
test_name
=
'
HyperCat
'
plugin_name
=
'
HyperCat
'
test_url
=
'
https://api.cityverve.org.uk/v1/cat
/polling-station
'
dataset
=
'
https://api.cityverve.org.uk/v1/
entity
/polling-station
/5
'
test_url
=
'
https://api.cityverve.org.uk/v1/cat
'
dataset
=
'
https://api.cityverve.org.uk/v1/
cat
/polling-station
'
@classmethod
def
setUpTestData
(
cls
):
...
...
This diff is collapsed.
Click to expand it.
datasources/tests/test_connectors_hypercat.py
+
31
−
138
View file @
fe65f4eb
...
...
@@ -2,7 +2,6 @@ import itertools
import
typing
from
django.test
import
TestCase
from
requests.auth
import
HTTPBasicAuth
from
datasources.connectors.base
import
AuthMethod
,
BaseDataConnector
,
HttpHeaderAuth
...
...
@@ -27,15 +26,15 @@ def _count_items_by_key_value(collection: typing.Iterable[typing.Mapping],
class
ConnectorHyperCatTest
(
TestCase
):
url
=
'
https://portal.bt-hypercat.com/cat
'
# Met Office dataset for weather at Heathrow
dataset
=
'
http://api.
bt-hypercat.com/sensors/feeds/c7f361c6-7cb7-4ef5-aed9-397a0c0c4088
'
# TODO find working dataset
url
=
'
https://api.cityverve.org.uk/v1/cat
'
subcatalogue
=
'
https://api.cityverve.org.uk/v1/cat/polling-station
'
dataset
=
'
http
s
://api.
cityverve.org.uk/v1/entity/polling-station/5
'
def
_get_connection
(
self
)
->
BaseDataConnector
:
return
self
.
plugin
(
self
.
url
,
api_key
=
self
.
api_key
,
auth
=
H
TTPBasic
Auth
)
auth
=
H
ttpHeader
Auth
)
def
setUp
(
self
):
from
decouple
import
config
...
...
@@ -43,7 +42,8 @@ class ConnectorHyperCatTest(TestCase):
BaseDataConnector
.
load_plugins
(
'
datasources/connectors
'
)
self
.
plugin
=
BaseDataConnector
.
get_plugin
(
'
HyperCat
'
)
self
.
api_key
=
config
(
'
HYPERCAT_BT_API_KEY
'
)
self
.
api_key
=
config
(
'
HYPERCAT_CISCO_API_KEY
'
)
self
.
auth
=
None
def
test_get_plugin
(
self
):
self
.
assertIsNotNone
(
self
.
plugin
)
...
...
@@ -58,7 +58,14 @@ class ConnectorHyperCatTest(TestCase):
self
.
assertTrue
(
connection
.
is_catalogue
)
def
test_plugin_get_metadata
(
self
):
def
test_determine_auth
(
self
):
connection
=
self
.
_get_connection
()
auth_method
=
connection
.
determine_auth_method
(
connection
.
location
,
connection
.
api_key
)
self
.
assertEqual
(
AuthMethod
.
HEADER
,
auth_method
)
def
test_plugin_get_catalogue_metadata
(
self
):
connection
=
self
.
_get_connection
()
result
=
connection
.
get_metadata
()
...
...
@@ -67,15 +74,19 @@ class ConnectorHyperCatTest(TestCase):
for
property
in
[
'
urn:X-hypercat:rels:hasDescription:en
'
,
'
urn:X-hypercat:rels:isContentType
'
,
'
urn:X-hypercat:rels:hasHomepage
'
,
]:
self
.
assertIn
(
property
,
relations
)
self
.
assertEqual
(
'
BT Hypercat DataHub C
atalog
'
,
self
.
assertEqual
(
'
CityVerve Public API - master c
atalog
ue
'
,
_get_item_by_key_value
(
result
,
'
rel
'
,
'
urn:X-hypercat:rels:hasDescription:en
'
)[
'
val
'
])
self
.
assertEqual
(
'
application/vnd.hypercat.catalogue+json
'
,
_get_item_by_key_value
(
result
,
'
rel
'
,
'
urn:X-hypercat:rels:isContentType
'
)[
'
val
'
])
self
.
assertEqual
(
'
https://developer.cityverve.org.uk
'
,
_get_item_by_key_value
(
result
,
'
rel
'
,
'
urn:X-hypercat:rels:hasHomepage
'
)[
'
val
'
])
def
test_plugin_get_datasets
(
self
):
connection
=
self
.
_get_connection
()
...
...
@@ -87,8 +98,16 @@ class ConnectorHyperCatTest(TestCase):
self
.
assertLessEqual
(
1
,
len
(
datasets
))
self
.
assertIn
(
self
.
dataset
,
datasets
)
# Only check a couple of expected results are present - there's too many to list here
expected
=
{
'
https://api.cityverve.org.uk/v1/cat/accident
'
,
'
https://api.cityverve.org.uk/v1/cat/advertising-board
'
,
'
https://api.cityverve.org.uk/v1/cat/advertising-post
'
,
# And because later tests rely on it...
'
https://api.cityverve.org.uk/v1/cat/polling-station
'
,
}
for
exp
in
expected
:
self
.
assertIn
(
exp
,
datasets
)
def
test_plugin_iter_datasets
(
self
):
connection
=
self
.
_get_connection
()
...
...
@@ -127,7 +146,7 @@ class ConnectorHyperCatTest(TestCase):
This process is relatively slow so we only do a couple of iterations.
"""
with
self
.
plugin
(
self
.
url
,
api_key
=
self
.
api_key
,
auth
=
HTTPBasicAuth
)
as
connection
:
with
self
.
_get_connection
(
)
as
connection
:
for
k
,
v
in
itertools
.
islice
(
connection
.
items
(),
5
):
self
.
assertEqual
(
str
,
type
(
k
))
...
...
@@ -138,132 +157,6 @@ class ConnectorHyperCatTest(TestCase):
self
.
assertEqual
(
k
,
v
.
location
)
def
test_plugin_get_dataset_metadata
(
self
):
connection
=
self
.
_get_connection
()
result
=
connection
[
self
.
dataset
].
get_metadata
()
relations
=
[
relation
[
'
rel
'
]
for
relation
in
result
]
for
property
in
[
'
urn:X-bt:rels:feedTitle
'
,
'
urn:X-hypercat:rels:hasDescription:en
'
,
'
urn:X-bt:rels:feedTag
'
,
'
urn:X-bt:rels:hasSensorStream
'
,
'
urn:X-hypercat:rels:isContentType
'
,
]:
self
.
assertIn
(
property
,
relations
)
self
.
assertIn
(
'
Met Office
'
,
_get_item_by_key_value
(
result
,
'
rel
'
,
'
urn:X-bt:rels:feedTitle
'
)[
'
val
'
])
self
.
assertIn
(
'
Met Office
'
,
_get_item_by_key_value
(
result
,
'
rel
'
,
'
urn:X-hypercat:rels:hasDescription:en
'
)[
'
val
'
])
self
.
assertEqual
(
1
,
_count_items_by_key_value
(
result
,
'
rel
'
,
'
urn:X-bt:rels:feedTag
'
))
self
.
assertGreaterEqual
(
_count_items_by_key_value
(
result
,
'
rel
'
,
'
urn:X-bt:rels:hasSensorStream
'
),
1
)
def
test_plugin_get_dataset_data
(
self
):
"""
Test that we can get data from a single dataset within the catalogue.
"""
connection
=
self
.
_get_connection
()
dataset
=
connection
[
self
.
dataset
]
result
=
dataset
.
get_data
()
self
.
assertIsInstance
(
result
,
str
)
self
.
assertGreaterEqual
(
len
(
result
),
1
)
self
.
assertIn
(
'
c7f361c6-7cb7-4ef5-aed9-397a0c0c4088
'
,
result
)
class
ConnectorHyperCatCiscoTest
(
TestCase
):
# TODO find working dataset
url
=
'
https://api.cityverve.org.uk/v1/cat
'
subcatalogue
=
'
https://api.cityverve.org.uk/v1/cat/polling-station
'
dataset
=
'
https://api.cityverve.org.uk/v1/entity/polling-station/5
'
def
_get_connection
(
self
)
->
BaseDataConnector
:
return
self
.
plugin
(
self
.
url
,
api_key
=
self
.
api_key
,
auth
=
HttpHeaderAuth
)
def
setUp
(
self
):
from
decouple
import
config
BaseDataConnector
.
load_plugins
(
'
datasources/connectors
'
)
self
.
plugin
=
BaseDataConnector
.
get_plugin
(
'
HyperCat
'
)
self
.
api_key
=
config
(
'
HYPERCAT_CISCO_API_KEY
'
)
self
.
auth
=
None
def
test_get_plugin
(
self
):
self
.
assertIsNotNone
(
self
.
plugin
)
def
test_plugin_init
(
self
):
connection
=
self
.
_get_connection
()
self
.
assertEqual
(
connection
.
location
,
self
.
url
)
def
test_plugin_type
(
self
):
connection
=
self
.
_get_connection
()
self
.
assertTrue
(
connection
.
is_catalogue
)
def
test_determine_auth
(
self
):
connection
=
self
.
_get_connection
()
auth_method
=
connection
.
determine_auth_method
(
connection
.
location
,
connection
.
api_key
)
self
.
assertEqual
(
AuthMethod
.
HEADER
,
auth_method
)
def
test_plugin_get_catalogue_metadata
(
self
):
connection
=
self
.
_get_connection
()
result
=
connection
.
get_metadata
()
relations
=
[
relation
[
'
rel
'
]
for
relation
in
result
]
for
property
in
[
'
urn:X-hypercat:rels:hasDescription:en
'
,
'
urn:X-hypercat:rels:isContentType
'
,
'
urn:X-hypercat:rels:hasHomepage
'
,
]:
self
.
assertIn
(
property
,
relations
)
self
.
assertEqual
(
'
CityVerve Public API - master catalogue
'
,
_get_item_by_key_value
(
result
,
'
rel
'
,
'
urn:X-hypercat:rels:hasDescription:en
'
)[
'
val
'
])
self
.
assertEqual
(
'
application/vnd.hypercat.catalogue+json
'
,
_get_item_by_key_value
(
result
,
'
rel
'
,
'
urn:X-hypercat:rels:isContentType
'
)[
'
val
'
])
self
.
assertEqual
(
'
https://developer.cityverve.org.uk
'
,
_get_item_by_key_value
(
result
,
'
rel
'
,
'
urn:X-hypercat:rels:hasHomepage
'
)[
'
val
'
])
def
test_plugin_get_datasets
(
self
):
connection
=
self
.
_get_connection
()
datasets
=
connection
.
get_datasets
()
self
.
assertEqual
(
list
,
type
(
datasets
))
self
.
assertLessEqual
(
1
,
len
(
datasets
))
# Only check a couple of expected results are present - there's too many to list here
expected
=
{
'
https://api.cityverve.org.uk/v1/cat/accident
'
,
'
https://api.cityverve.org.uk/v1/cat/advertising-board
'
,
'
https://api.cityverve.org.uk/v1/cat/advertising-post
'
,
# And because later tests rely on it...
'
https://api.cityverve.org.uk/v1/cat/polling-station
'
,
}
for
exp
in
expected
:
self
.
assertIn
(
exp
,
datasets
)
def
test_plugin_get_subcatalogue_metadata
(
self
):
connection
=
self
.
_get_connection
()
...
...
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