Skip to content

Commit

Permalink
Merge 28b65d2 into 417902c
Browse files Browse the repository at this point in the history
  • Loading branch information
owenl131 committed Dec 9, 2017
2 parents 417902c + 28b65d2 commit c4e4966
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 1 deletion.
Binary file added api/sample_image.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
46 changes: 46 additions & 0 deletions api/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -458,6 +458,52 @@ def test_delete_permalink(self):
self.assertEqual(response["removed"], True)


class CustomUploadSampleInputControllerTests(TestCase):

def setUp(self):
self.client = Client()
self.demo = {
"name": "test",
"id": 99,
"user_id": 99,
"address": "address",
"description": "description",
"footer_message": "footer_message",
"cover_image": "cover_image",
"terminal": True,
"timestamp": datetime.datetime.now().isoformat(),
"token": "token",
"status": "input"
}
Demo.objects.create(name=self.demo["name"],
id=self.demo["id"],
user_id=self.demo["user_id"],
address=self.demo["address"],
description=self.demo["description"],
footer_message=self.demo["footer_message"],
cover_image=self.demo["cover_image"],
terminal=self.demo["terminal"],
timestamp=self.demo["timestamp"],
token=self.demo["token"],
status=self.demo["status"])

def test_upload_sample_input_nofile(self):
response = self.client.post("/upload_sample_input",
{"demo_id": self.demo["id"]})
self.assertContains(response, '', None, 200)

def test_upload_sample_input(self):
with open('api/sample_image.png', 'rb') as f:
response = self.client.post(
"/upload_sample_input",
{"demo_id": self.demo["id"], "sample-image": f})
self.assertContains(response, '', None, 200)
response = json.loads(response.content.decode('utf-8'))
response = response[0]
self.assertEqual(int(response["type_of_input"]),
3, str(dir(response)))


class CustomRootSettingsControllerClass(TestCase):

def setUp(self):
Expand Down
2 changes: 1 addition & 1 deletion api/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -439,7 +439,7 @@ def upload_sample_input(request):
data = request.data
demo_id = data["demo_id"]
demo = Demo.objects.get(id=demo_id)
for key, value in data.iteritems():
for key, value in data.items():
if key.startswith("sample-image"):
img = request.FILES[key]
absolute_path = default_storage.save(
Expand Down

0 comments on commit c4e4966

Please sign in to comment.