Beispiel #1
0
    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))
Beispiel #2
0
    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))
Beispiel #3
0
    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))
Beispiel #4
0
    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, '/')