class DataStoreTestCase(unittest.TestCase): def setUp(self): self.datastore = DataStore() def test_add_value(self): """The values are added under the series name key.""" self.datastore.add_value('name', 123456789, 42) self.assertEqual(len(self.datastore.keys()), 1) self.assert_('name' in self.datastore.keys()) self.assertEqual(len(self.datastore['name']), 1) self.assertEqual(self.datastore['name'], [(123456789, 42)])
def setUp(self): datastore = DataStore() self.factory = SimpleStatsFactory(datastore) self.proto = self.factory.buildProtocol(('127.0.0.1', 0)) self.tr = proto_helpers.StringTransport() self.proto.makeConnection(self.tr) # clear welcome message self.tr.clear()
def test_download_render_POST(self): """Download JSON data file.""" datastore = DataStore() datastore.add_value("var1", 1, 1) datastore.add_value("var2", 2, 2) resource = Index(datastore) request = DummyRequest(['foo']) request.args = {'download': 'download'} d = request.notifyFinish() result = resource.render_POST(request) self.assertEqual(result, server.NOT_DONE_YET) yield d expected = '["var1", 1, 1]\n["var2", 2, 2]' self.assertEqual(expected, ''.join(request.written))
def test_data_render_POST(self): """Main page rendering with data.""" datastore = DataStore() datastore.add_value("var1", 1, 1) datastore.add_value("var2", 2, 2) resource = Index(datastore) request = DummyRequest(['foo']) d = request.notifyFinish() result = resource.render_GET(request) self.assertEqual(result, server.NOT_DONE_YET) yield d element = ChartDataElement(datastore) expected = yield flattenString(request, element) self.assertIn(expected, ''.join(request.written))
def test_render_GET(self): """Render SimpleStats main page.""" datastore = DataStore() resource = Index(datastore) request = DummyRequest(['foo']) d = request.notifyFinish() result = resource.render_GET(request) self.assertEqual(result, server.NOT_DONE_YET) yield d element = ChartDataElement(datastore) expected = yield flattenString(request, element) self.assertIn(expected, ''.join(request.written))
def test_upload_render_POST(self): """Upload JSON data file.""" datastore = DataStore() resource = Index(datastore) request = DummyRequest(['foo']) request.args = {'data_file': ['["var1", 1, 1]\n["var2", 2, 2]'], 'upload': 'upload'} def fake_redirect(path): request.redirect_to = path request.redirect = fake_redirect d = request.notifyFinish() result = resource.render_POST(request) self.assertEqual(result, server.NOT_DONE_YET) yield d self.assertEqual(request.redirect_to, '/')
def setUp(self): self.datastore = DataStore()