still testing
This commit is contained in:
35
tests/ext/test_ods.py
Normal file
35
tests/ext/test_ods.py
Normal file
@ -0,0 +1,35 @@
|
||||
from mock import patch
|
||||
|
||||
from bonobo.ext.ods import extract_ods
|
||||
|
||||
|
||||
class ResponseMock:
|
||||
def __init__(self, json_value):
|
||||
self.json_value = json_value
|
||||
self.count = 0
|
||||
|
||||
def json(self):
|
||||
if self.count:
|
||||
return {}
|
||||
else:
|
||||
self.count += 1
|
||||
return {'records': self.json_value, }
|
||||
|
||||
|
||||
def test_read_from_opendatasoft_api():
|
||||
extract = extract_ods('http://example.com/', 'test-a-set')
|
||||
with patch(
|
||||
'requests.get', return_value=ResponseMock([
|
||||
{
|
||||
'fields': {
|
||||
'foo': 'bar'
|
||||
}
|
||||
},
|
||||
{
|
||||
'fields': {
|
||||
'foo': 'zab'
|
||||
}
|
||||
},
|
||||
])):
|
||||
for line in extract():
|
||||
assert 'foo' in line
|
||||
37
tests/io/test_json.py
Normal file
37
tests/io/test_json.py
Normal file
@ -0,0 +1,37 @@
|
||||
import pytest
|
||||
|
||||
from bonobo import to_json
|
||||
from bonobo.util.lifecycle import get_initializer, get_finalizer
|
||||
|
||||
|
||||
class ContextMock:
|
||||
pass
|
||||
|
||||
|
||||
def test_write_json_to_file(tmpdir):
|
||||
file = tmpdir.join('output.json')
|
||||
json_writer = to_json(file)
|
||||
context = ContextMock()
|
||||
|
||||
get_initializer(json_writer)(context)
|
||||
json_writer(context, {'foo': 'bar'})
|
||||
get_finalizer(json_writer)(context)
|
||||
|
||||
assert file.read() == '''[
|
||||
{"foo": "bar"}
|
||||
]'''
|
||||
|
||||
with pytest.raises(AttributeError):
|
||||
getattr(context, 'fp')
|
||||
|
||||
with pytest.raises(AttributeError):
|
||||
getattr(context, 'first')
|
||||
|
||||
|
||||
def test_write_json_without_initializer_should_not_work(tmpdir):
|
||||
file = tmpdir.join('output.json')
|
||||
json_writer = to_json(file)
|
||||
|
||||
context = ContextMock()
|
||||
with pytest.raises(AttributeError):
|
||||
json_writer(context, {'foo': 'bar'})
|
||||
Reference in New Issue
Block a user