40 lines
1.2 KiB
Python
40 lines
1.2 KiB
Python
import mock
|
|
import pytest
|
|
|
|
from django.test import override_settings
|
|
|
|
from combo.data.models import Page
|
|
from combo.apps.dataviz.models import Gauge
|
|
|
|
pytestmark = pytest.mark.django_db
|
|
|
|
@pytest.fixture
|
|
def cell():
|
|
page = Page(title='One', slug='index')
|
|
page.save()
|
|
|
|
cell = Gauge(page=page, order=0, placeholder='content')
|
|
cell.data_source = '[test_url]/XXX'
|
|
cell.save()
|
|
|
|
return cell
|
|
|
|
|
|
def test_jsonp_gauge(app, cell):
|
|
with override_settings(TEMPLATE_VARS={'test_url': 'http://www.example.net'}):
|
|
resp = app.get('/')
|
|
assert 'data-gauge-count-jsonp-url="http://www.example.net/XXX"' in resp.body
|
|
|
|
|
|
def test_json_gauge(app, cell):
|
|
cell.jsonp_data_source = False
|
|
cell.save()
|
|
with override_settings(TEMPLATE_VARS={'test_url': 'http://www.example.net'}):
|
|
with mock.patch('combo.apps.dataviz.views.requests.get') as requests_get:
|
|
requests_get.return_value = mock.Mock(content='xxx', status_code=200)
|
|
resp = app.get('/')
|
|
assert 'data-gauge-count-url="/ajax/gauge-count/%s/"' % cell.id in resp.body
|
|
resp = app.get('/ajax/gauge-count/%s/' % cell.id)
|
|
assert resp.content == 'xxx'
|
|
assert requests_get.call_args[0][0] == 'http://www.example.net/XXX'
|