Skip to content
Snippets Groups Projects
Commit 10a12a66 authored by Samuel GAIST's avatar Samuel GAIST Committed by Samuel GAIST
Browse files

[algoritms][tests] Update tests for new put implementation

Also improves coverage, code related change tests were not
properly done.
parent 62f3ad1b
No related branches found
No related tags found
No related merge requests found
This commit is part of merge request !327. Comments created here will be created in the context of that merge request.
......@@ -1229,20 +1229,26 @@ class AlgorithmUpdate(AlgorithmsAPIBase):
def test_no_update_without_content(self):
self.login_jackdoe()
response = self.client.put(self.url)
self.checkResponse(response, 400)
self.checkResponse(response, 200, content_type="application/json")
def test_successfull_update(self):
self.login_jackdoe()
code = b"""import numpy as np"""
response = self.client.put(
self.url,
json.dumps(
{"description": "blah", "declaration": AlgorithmsAPIBase.UPDATE}
{
"description": "blah",
"declaration": AlgorithmsAPIBase.UPDATE,
"code": code,
}
),
content_type="application/json",
)
self.checkResponse(response, 204)
self.checkResponse(response, 200, content_type="application/json")
algorithm = Algorithm.objects.get(
author__username="jackdoe", name="personal", version=1
......@@ -1252,7 +1258,10 @@ class AlgorithmUpdate(AlgorithmsAPIBase):
storage = beat.core.algorithm.Storage(settings.PREFIX, algorithm.fullname())
storage.language = "python"
self.assertTrue(storage.exists())
self.assertEqual(storage.json.load(), AlgorithmsAPIBase.UPDATE)
self.assertEqual(
json.loads(storage.json.load()), json.loads(AlgorithmsAPIBase.UPDATE)
)
self.assertEqual(storage.code.load(), code)
def test_successfull_update_description_only(self):
self.login_jackdoe()
......@@ -1263,14 +1272,14 @@ class AlgorithmUpdate(AlgorithmsAPIBase):
content_type="application/json",
)
self.checkResponse(response, 204)
self.checkResponse(response, 200, content_type="application/json")
algorithm = Algorithm.objects.get(
author__username="jackdoe", name="personal", version=1
)
self.assertEqual(algorithm.description, b"blah")
def test_successfull_update_code_only(self):
def test_successfull_declaration_only(self):
self.login_jackdoe()
response = self.client.put(
......@@ -1279,7 +1288,29 @@ class AlgorithmUpdate(AlgorithmsAPIBase):
content_type="application/json",
)
self.checkResponse(response, 204)
self.checkResponse(response, 200, content_type="application/json")
algorithm = Algorithm.objects.get(
author__username="jackdoe", name="personal", version=1
)
storage = beat.core.algorithm.Storage(settings.PREFIX, algorithm.fullname())
storage.language = "python"
self.assertTrue(storage.exists())
self.assertEqual(
json.loads(storage.json.load()), json.loads(AlgorithmsAPIBase.UPDATE)
)
def test_successfull_update_code_only(self):
self.login_jackdoe()
code = b"""import pandas"""
response = self.client.put(
self.url, json.dumps({"code": code}), content_type="application/json"
)
self.checkResponse(response, 200, content_type="application/json")
algorithm = Algorithm.objects.get(
author__username="jackdoe", name="personal", version=1
......@@ -1288,7 +1319,7 @@ class AlgorithmUpdate(AlgorithmsAPIBase):
storage = beat.core.algorithm.Storage(settings.PREFIX, algorithm.fullname())
storage.language = "python"
self.assertTrue(storage.exists())
self.assertEqual(storage.json.load(), AlgorithmsAPIBase.UPDATE)
self.assertEqual(storage.code.load(), code)
def test_successfull_update_change_input_name(self):
declaration = """{
......@@ -1317,7 +1348,7 @@ class AlgorithmUpdate(AlgorithmsAPIBase):
content_type="application/json",
)
self.checkResponse(response, 204)
self.checkResponse(response, 200, content_type="application/json")
algorithm = Algorithm.objects.get(
author__username="jackdoe", name="personal", version=1
......@@ -1369,7 +1400,7 @@ class AlgorithmUpdate(AlgorithmsAPIBase):
content_type="application/json",
)
self.checkResponse(response, 204)
self.checkResponse(response, 200, content_type="application/json")
algorithm = Algorithm.objects.get(
author__username="jackdoe", name="personal", version=1
......@@ -1407,7 +1438,7 @@ class AlgorithmUpdate(AlgorithmsAPIBase):
"parameters": {
}
}"""
code = """class Algorithm:
code = b"""class Algorithm:
def process(self, inputs, outputs):
return True
......@@ -1422,7 +1453,7 @@ class AlgorithmUpdate(AlgorithmsAPIBase):
content_type="application/json",
)
self.checkResponse(response, 204)
self.checkResponse(response, 200, content_type="application/json")
algorithm = Algorithm.objects.get(
author__username="jackdoe", name="personal", version=1
......@@ -1474,7 +1505,7 @@ class AlgorithmUpdate(AlgorithmsAPIBase):
content_type="application/json",
)
self.checkResponse(response, 204)
self.checkResponse(response, 200, content_type="application/json")
algorithm = Algorithm.objects.get(
author__username="jackdoe", name="personal", version=1
......@@ -1522,7 +1553,7 @@ class AlgorithmUpdate(AlgorithmsAPIBase):
content_type="application/json",
)
self.checkResponse(response, 204)
self.checkResponse(response, 200, content_type="application/json")
algorithm = Algorithm.objects.get(
author__username="jackdoe", name="personal", version=1
......@@ -1572,7 +1603,7 @@ class AlgorithmUpdate(AlgorithmsAPIBase):
content_type="application/json",
)
self.checkResponse(response, 204)
self.checkResponse(response, 200, content_type="application/json")
algorithm = Algorithm.objects.get(
author__username="jackdoe", name="personal", version=1
......@@ -1616,7 +1647,7 @@ class AlgorithmUpdate(AlgorithmsAPIBase):
content_type="application/json",
)
self.checkResponse(response, 204)
self.checkResponse(response, 200, content_type="application/json")
algorithm = Algorithm.objects.get(
author__username="jackdoe", name="personal", version=1
......@@ -1695,7 +1726,7 @@ class AlgorithmUpdate(AlgorithmsAPIBase):
content_type="application/json",
)
self.checkResponse(response, 204)
self.checkResponse(response, 200, content_type="application/json")
response = self.client.put(
self.url,
......@@ -1703,7 +1734,7 @@ class AlgorithmUpdate(AlgorithmsAPIBase):
content_type="application/json",
)
self.checkResponse(response, 204)
self.checkResponse(response, 200, content_type="application/json")
algorithm = Algorithm.objects.get(
author__username="jackdoe", name="personal", version=1
......@@ -1751,7 +1782,7 @@ class AlgorithmUpdate(AlgorithmsAPIBase):
content_type="application/json",
)
self.checkResponse(response, 204)
self.checkResponse(response, 200, content_type="application/json")
algorithm = Algorithm.objects.get(
author__username="jackdoe", name="personal", version=1
......@@ -1827,7 +1858,7 @@ class AlgorithmUpdate(AlgorithmsAPIBase):
content_type="application/json",
)
self.checkResponse(response, 204)
self.checkResponse(response, 200, content_type="application/json")
response = self.client.put(
self.url,
......@@ -1835,7 +1866,7 @@ class AlgorithmUpdate(AlgorithmsAPIBase):
content_type="application/json",
)
self.checkResponse(response, 204)
self.checkResponse(response, 200, content_type="application/json")
algorithm = Algorithm.objects.get(
author__username="jackdoe", name="personal", version=1
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment