diff --git a/beat/web/plotters/tests.py b/beat/web/plotters/tests.py index e8d8f3b1a578268092864b15bcb2565e1cd70e09..b12e08efea9e8f29a5f90dd990dd4c6f91ba219e 100644 --- a/beat/web/plotters/tests.py +++ b/beat/web/plotters/tests.py @@ -35,6 +35,7 @@ from django.contrib.auth.models import User from django.conf import settings from django.core.urlresolvers import reverse +from ..dataformats.models import DataFormat from .models import Plotter, PlotterParameter from ..common.models import Shareable @@ -59,7 +60,61 @@ class PlotterParameterTestCase(APITestCase): self.jackdoe = User.objects.create_user('jackdoe', 'jackdoe@test.org', self.password) self.plot = User.objects.create_user('plot', 'plotdoe@test.org', self.password) - + # Create a data format for user plot + (dataformat, errors) = DataFormat.objects.create_dataformat( + author=self.plot, + name='float', + short_description='description', + declaration={ + "value": "float64" + }, + ) + + assert dataformat, errors + + (dataformat, errors) = DataFormat.objects.create_dataformat( + author=self.plot, + name='text', + short_description='description', + declaration={ + "text": "string" + }, + ) + + assert dataformat, errors + + (dataformat_plot, errors) = DataFormat.objects.create_dataformat( + author=self.plot, + name='single_integer', + short_description='description', + declaration={ + "value": "int32" + }, + ) + dataformat_plot.share() + + # Create plotter + #self.plotter = Plotter() + #self.plotter.author = self.plot + #self.plotter.name = "test" + #self.plotter.declaration = {"language": "python","parameters":{},"dataformat":"plot/text/1"} + #self.plotter.code = "#test" + #self.plotter.save() + + self.client.login(username=self.plot.username, password=self.password) + self.url_plotter = reverse('api_plotters:list_create', kwargs={'author_name': self.plot.username}) + + self.data_plotter = {\ + 'author':self.plot.username,\ + 'name':'plotter_test',\ + 'short_description':'some description plotter',\ + 'description':'some longer description plotter',\ + 'declaration':{"language": "python","parameters":{},"dataformat":"plot/text/1"},\ + 'code':'#test'\ + } + response = self.client.post(self.url_plotter, self.data_plotter, format='json') + self.assertEqual(response.status_code, status.HTTP_201_CREATED) + self.plotter = Plotter.objects.get(name='plotter_test') def tearDown(self): for path in [settings.TOOLCHAINS_ROOT, settings.EXPERIMENTS_ROOT, @@ -83,13 +138,14 @@ class PlotterParameterCreationTestCase(PlotterParameterTestCase): #'author':self.johndoe,\ 'name':'plotterparameter1',\ 'short_description':'some description',\ - 'description':'some longer description'\ + 'description':'some longer description',\ + 'plotter':self.plotter.id\ } def test_anonymous_user(self): response = self.client.post(self.url, self.data, format='json') self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN) - self.assertEqual(response.content, '{"detail":"Authentication credentials were not provided."}') + self.assertEqual(response.content, '{"detail":"You do not have permission to perform this action."}') def test_logged_in_user(self): @@ -125,14 +181,16 @@ class PlotterParameterListTestCase(PlotterParameterTestCase): #'author':self.johndoe,\ 'name':'plotterparameter1',\ 'short_description':'some description',\ - 'description':'some longer description'\ + 'description':'some longer description',\ + 'plotter':self.plotter.id\ } self.data2 = {\ #'author':self.johndoe,\ 'name':'plotterparameter2',\ 'short_description':'some description2',\ - 'description':'some longer description2'\ + 'description':'some longer description2',\ + 'plotter':self.plotter.id\ } def test_anonymous_user(self): @@ -199,14 +257,16 @@ class PlotterParameterRetrievalTestCase(PlotterParameterTestCase): #'author':self.johndoe,\ 'name':'plotterparameter1',\ 'short_description':'some description',\ - 'description':'some longer description'\ + 'description':'some longer description',\ + 'plotter':self.plotter.id\ } self.data2 = {\ #'author':self.johndoe,\ 'name':'plotterparameter2',\ 'short_description':'some description2',\ - 'description':'some longer description2'\ + 'description':'some longer description2',\ + 'plotter':self.plotter.id\ } def test_anonymous_user(self): @@ -276,14 +336,16 @@ class PlotterParameterUpdateTestCase(PlotterParameterTestCase): #'author':self.johndoe,\ 'name':'plotterparameter1',\ 'short_description':'some description',\ - 'description':'some longer description'\ + 'description':'some longer description',\ + 'plotter':self.plotter.id\ } self.data2 = {\ #'author':self.johndoe,\ 'name':'plotterparameter2',\ 'short_description':'some description2',\ - 'description':'some longer description2'\ + 'description':'some longer description2',\ + 'plotter':self.plotter.id\ } def test_anonymous_user(self): @@ -353,14 +415,16 @@ class PlotterParameterDeletionTestCase(PlotterParameterTestCase): #'author':self.johndoe,\ 'name':'plotterparameter1',\ 'short_description':'some description',\ - 'description':'some longer description'\ + 'description':'some longer description',\ + 'plotter':self.plotter.id\ } self.data2 = {\ #'author':self.johndoe,\ 'name':'plotterparameter2',\ 'short_description':'some description2',\ - 'description':'some longer description2'\ + 'description':'some longer description2',\ + 'plotter':self.plotter.id\ } def test_anonymous_user(self):