def testSavePlot(self): """ Tests saving a single plot """ new_files = generateDocs(PlotTest.account_id, 1, 4, 3) PlotTest.files.extend(new_files) plot_args = { 'type' : 'SCATTER3D', 'title': PlotTest.testSavePlot.__name__, 'x_label': 'x', 'y_label': 'y', 'x_points': ['test1', 'c0'], 'y_points': [['test1', 'c1'], ['test1', 'c2']], } details = PlotDetails( plot_args['type'], plot_args['title'], plot_args['x_label'], plot_args['y_label'], plot_args['x_points'], plot_args['y_points'], ) Plot.save_plot(PlotTest.account_id, details) saved_plot = Plot.objects.get(account_id=PlotTest.account_id) # self.assertEqual(plot_args['account'], saved_plot.account_id) self.assertEqual(details.plot_type, saved_plot.plot_type) self.assertEqual(details.plot_title, saved_plot.plot_title) self.assertEqual(details.x_label, saved_plot.x_label) self.assertEqual(details.y_label, saved_plot.y_label) self.assertEqual(details.x_points, ast.literal_eval(saved_plot.x_points)) self.assertEqual(details.y_points, ast.literal_eval(saved_plot.y_points))
def testDeletePlot(self): """ Tests deleting a single saved plot """ new_files = generateDocs(PlotTest.account_id, 1, 4, 3) PlotTest.files.extend(new_files) plot_args = { 'type' : 'scatter', 'title': PlotTest.testSavePlot.__name__, 'x_label': 'x', 'y_label': 'y', 'x_points': {'file_name': "test1", 'header_name': "c0", 'owner_id': PlotTest.account_id}, 'y_points': [ {'file_name': "test1", 'header_name': "c1", 'owner_id': PlotTest.account_id}, {'file_name': "test1", 'header_name': "c2", 'owner_id': PlotTest.account_id} ] } details = PlotDetails( plot_args['type'], plot_args['title'], plot_args['x_label'], plot_args['y_label'], plot_args['x_points'], plot_args['y_points'], ) Plot.save_plot(PlotTest.account_id, details) self.assertEqual(1, Plot.objects.all().count()) plot_id = Plot.objects.get(account_id=PlotTest.account_id).id Plot.remove_user_plot(plot_id) self.assertEqual(0, Plot.objects.all().count())
def testGetUserPlots(self): """ Tests that correct number of user plots are returned """ new_files = generateDocs(PlotTest.account_id, 1, 4, 4) PlotTest.files.extend(new_files) plot_args = { 'type' : 'scatter', 'title': PlotTest.testSavePlot.__name__, 'x_label': 'x', 'y_label': 'y', 'x_points': {'file_name': 'test1', 'header_name': 'c0', 'owner_id': PlotTest.account_id}, 'y_points': [ {'file_name': 'test1', 'header_name': 'c1', 'owner_id': PlotTest.account_id}, {'file_name': 'test1', 'header_name': 'c2', 'owner_id': PlotTest.account_id} ], } details = PlotDetails( plot_args['type'], plot_args['title'], plot_args['x_label'], plot_args['y_label'], plot_args['x_points'], plot_args['y_points'], ) DFACTOR=3 for _ in range(DFACTOR): Plot.save_plot(PlotTest.account_id, details) self.assertEqual(DFACTOR, len(Plot.get_user_plots(PlotTest.account_id)))
def testBadData(self): new_files = generateBadDoc(PlotTest.account_id) PlotTest.files.extend(new_files) plot_args = { 'type' : 'scatter', 'title': PlotTest.testSavePlot.__name__, 'x_label': 'x', 'y_label': 'y', 'x_points': {'file_name': "test1", 'header_name': "c0", 'owner_id': PlotTest.account_id}, 'y_points': [ {'file_name': "test1", 'header_name': "c1", 'owner_id': PlotTest.account_id}, {'file_name': "test1", 'header_name': "c2", 'owner_id': PlotTest.account_id} ] } details = PlotDetails( plot_args['type'], plot_args['title'], plot_args['x_label'], plot_args['y_label'], plot_args['x_points'], plot_args['y_points'], ) response = Plot.generate_plot(PlotTest.account_id, details) self.assertIn('errors', response.keys()) self.assertEqual(1, len(response['errors']))
def testCreate2DPlot(self): """ Tests 2D scatter plot with y-columns from 2 different files """ new_files = generateDocs(PlotTest.account_id, 2, 4, 4) PlotTest.files.extend(new_files) plot_args = { 'user': PlotTest.account_id, 'ptype': 'scatter', 'title': PlotTest.testSavePlot.__name__, 'xlabel': 'x', 'ylabels': 'y', 'xpoints': {'file_name': "test1", 'header_name': "c0", 'owner_id': PlotTest.account_id}, 'ypoints': [ {'file_name': "test1", 'header_name': "c1", 'owner_id': PlotTest.account_id}, {'file_name': "test1", 'header_name': "c2", 'owner_id': PlotTest.account_id} ] } details = PlotDetails( plot_args['ptype'], plot_args['title'], plot_args['xlabel'], plot_args['ylabels'], plot_args['xpoints'], plot_args['ypoints'], ) response_data = Plot.generate_plot(PlotTest.account_id, details) self.assertEqual(response_data['status'], 1) if settings.TEST_VERBOSE: pprint(PlotTest.testCreate2DPlot.__name__) pprint(response_data)
def testSingleFileCreatePlot(self): """ Tests multiple y-columns drawn from same file """ new_files = generateDocs(PlotTest.account_id, 1, 4, 4) PlotTest.files.extend(new_files) plot_args = { 'type' : SCATTER, 'title': PlotTest.testSavePlot.__name__, 'x_label': 'x', 'y_label': 'y', 'x_points': {'file_name': "test1", 'header_name': "c0", 'owner_id': PlotTest.account_id}, 'y_points': [ {'file_name': "test1", 'header_name': "c1", 'owner_id': PlotTest.account_id}, {'file_name': "test1", 'header_name': "c2", 'owner_id': PlotTest.account_id} ] } details = PlotDetails( plot_args['type'], plot_args['title'], plot_args['x_label'], plot_args['y_label'], plot_args['x_points'], plot_args['y_points'], ) # saved_plot = Plot.save_plot(PlotTest.account_id, details) response_data = Plot.generate_plot(PlotTest.account_id, details) self.assertEquals(details.x_label, response_data['plot']['x_label']) self.assertEquals(details.y_label, response_data['plot']['y_label']) expected_y_points = [ {'data': [[1.0, 2.0], [1.0, 2.0], [1.0, 2.0], [1.0, 2.0]], 'legend': 'c1 from test1'}, {'data': [[1.0, 3.0], [1.0, 3.0], [1.0, 3.0], [1.0, 3.0]], 'legend': 'c2 from test1'} ] self.assertEquals(expected_y_points, response_data['plot']['y_points'], "{}\n\n did not match expected\n\n \ {}".format(pformat(response_data['plot']['y_points']), pformat(expected_y_points))) self.assertEquals(details.plot_type, response_data['plot']['type']) self.assertEqual(details.plot_title, response_data['plot']['title'])