Skip to content
Snippets Groups Projects
Commit b652f000 authored by Flavio TARSETTI's avatar Flavio TARSETTI
Browse files

[plotters] updated unit tests

parent 83a46195
No related branches found
No related tags found
No related merge requests found
Pipeline #
...@@ -35,6 +35,7 @@ from django.contrib.auth.models import User ...@@ -35,6 +35,7 @@ from django.contrib.auth.models import User
from django.conf import settings from django.conf import settings
from django.core.urlresolvers import reverse from django.core.urlresolvers import reverse
from ..dataformats.models import DataFormat
from .models import Plotter, PlotterParameter from .models import Plotter, PlotterParameter
from ..common.models import Shareable from ..common.models import Shareable
...@@ -59,7 +60,61 @@ class PlotterParameterTestCase(APITestCase): ...@@ -59,7 +60,61 @@ class PlotterParameterTestCase(APITestCase):
self.jackdoe = User.objects.create_user('jackdoe', 'jackdoe@test.org', self.password) self.jackdoe = User.objects.create_user('jackdoe', 'jackdoe@test.org', self.password)
self.plot = User.objects.create_user('plot', 'plotdoe@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): def tearDown(self):
for path in [settings.TOOLCHAINS_ROOT, settings.EXPERIMENTS_ROOT, for path in [settings.TOOLCHAINS_ROOT, settings.EXPERIMENTS_ROOT,
...@@ -83,13 +138,14 @@ class PlotterParameterCreationTestCase(PlotterParameterTestCase): ...@@ -83,13 +138,14 @@ class PlotterParameterCreationTestCase(PlotterParameterTestCase):
#'author':self.johndoe,\ #'author':self.johndoe,\
'name':'plotterparameter1',\ 'name':'plotterparameter1',\
'short_description':'some description',\ 'short_description':'some description',\
'description':'some longer description'\ 'description':'some longer description',\
'plotter':self.plotter.id\
} }
def test_anonymous_user(self): def test_anonymous_user(self):
response = self.client.post(self.url, self.data, format='json') response = self.client.post(self.url, self.data, format='json')
self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN) 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): def test_logged_in_user(self):
...@@ -125,14 +181,16 @@ class PlotterParameterListTestCase(PlotterParameterTestCase): ...@@ -125,14 +181,16 @@ class PlotterParameterListTestCase(PlotterParameterTestCase):
#'author':self.johndoe,\ #'author':self.johndoe,\
'name':'plotterparameter1',\ 'name':'plotterparameter1',\
'short_description':'some description',\ 'short_description':'some description',\
'description':'some longer description'\ 'description':'some longer description',\
'plotter':self.plotter.id\
} }
self.data2 = {\ self.data2 = {\
#'author':self.johndoe,\ #'author':self.johndoe,\
'name':'plotterparameter2',\ 'name':'plotterparameter2',\
'short_description':'some description2',\ 'short_description':'some description2',\
'description':'some longer description2'\ 'description':'some longer description2',\
'plotter':self.plotter.id\
} }
def test_anonymous_user(self): def test_anonymous_user(self):
...@@ -199,14 +257,16 @@ class PlotterParameterRetrievalTestCase(PlotterParameterTestCase): ...@@ -199,14 +257,16 @@ class PlotterParameterRetrievalTestCase(PlotterParameterTestCase):
#'author':self.johndoe,\ #'author':self.johndoe,\
'name':'plotterparameter1',\ 'name':'plotterparameter1',\
'short_description':'some description',\ 'short_description':'some description',\
'description':'some longer description'\ 'description':'some longer description',\
'plotter':self.plotter.id\
} }
self.data2 = {\ self.data2 = {\
#'author':self.johndoe,\ #'author':self.johndoe,\
'name':'plotterparameter2',\ 'name':'plotterparameter2',\
'short_description':'some description2',\ 'short_description':'some description2',\
'description':'some longer description2'\ 'description':'some longer description2',\
'plotter':self.plotter.id\
} }
def test_anonymous_user(self): def test_anonymous_user(self):
...@@ -276,14 +336,16 @@ class PlotterParameterUpdateTestCase(PlotterParameterTestCase): ...@@ -276,14 +336,16 @@ class PlotterParameterUpdateTestCase(PlotterParameterTestCase):
#'author':self.johndoe,\ #'author':self.johndoe,\
'name':'plotterparameter1',\ 'name':'plotterparameter1',\
'short_description':'some description',\ 'short_description':'some description',\
'description':'some longer description'\ 'description':'some longer description',\
'plotter':self.plotter.id\
} }
self.data2 = {\ self.data2 = {\
#'author':self.johndoe,\ #'author':self.johndoe,\
'name':'plotterparameter2',\ 'name':'plotterparameter2',\
'short_description':'some description2',\ 'short_description':'some description2',\
'description':'some longer description2'\ 'description':'some longer description2',\
'plotter':self.plotter.id\
} }
def test_anonymous_user(self): def test_anonymous_user(self):
...@@ -353,14 +415,16 @@ class PlotterParameterDeletionTestCase(PlotterParameterTestCase): ...@@ -353,14 +415,16 @@ class PlotterParameterDeletionTestCase(PlotterParameterTestCase):
#'author':self.johndoe,\ #'author':self.johndoe,\
'name':'plotterparameter1',\ 'name':'plotterparameter1',\
'short_description':'some description',\ 'short_description':'some description',\
'description':'some longer description'\ 'description':'some longer description',\
'plotter':self.plotter.id\
} }
self.data2 = {\ self.data2 = {\
#'author':self.johndoe,\ #'author':self.johndoe,\
'name':'plotterparameter2',\ 'name':'plotterparameter2',\
'short_description':'some description2',\ 'short_description':'some description2',\
'description':'some longer description2'\ 'description':'some longer description2',\
'plotter':self.plotter.id\
} }
def test_anonymous_user(self): def test_anonymous_user(self):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment