Skip to content

Commit

Permalink
Issue #2288. Move screenshot return value test to test_upload.py.
Browse files Browse the repository at this point in the history
  • Loading branch information
miketaylr committed May 1, 2018
1 parent ca700ed commit 62f1452
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 21 deletions.
21 changes: 0 additions & 21 deletions tests/functional/comments-auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,27 +82,6 @@ registerSuite("Comments (auth)", {
});
},

"Add a screenshot to a comment"() {
return FunctionalHelpers.openPage(
this,
url("/issues/100"),
".js-buttonUpload"
)
.findById("image")
.type("tests/fixtures/green_square.png")
.end()
.sleep(5000)
.execute(() => document.querySelector("textarea").value)
.then(val => {
assert.include(
val,
"[![Screenshot Description](http://localhost:5000/uploads/",
"The image was correctly uploaded and its URL was copied to the comment text."
);
})
.end();
},

"Pressing 'g' inside of comment textarea *doesn't* go to github issue"() {
return FunctionalHelpers.openPage(
this,
Expand Down
28 changes: 28 additions & 0 deletions tests/unit/test_uploads.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

'''Tests for image upload API endpoint.'''

import json
import os.path
import sys
import unittest
Expand All @@ -21,6 +22,30 @@
from webcompat import app # nopep8


def check_rv_format(self, resp):
"""Check that the server gave us JSON in the expected format.
expected format:
'{"url": "http://localhost:5000/uploads/...ade311d4.jpg",
"thumb_url": "http://localhost:5000/uploads/...e311d4-thumb.jpg",
"filename": "ca589794-875b-44bd-9cd9-ed6cade311d4.jpg"}'
"""
if resp.status_code == 201:
response = json.loads(resp.data)
self.assertTrue(
'url' in response and
'http://localhost:5000/uploads/' in response.get('url')
)
self.assertTrue(
'thumb_url' in response and
'-thumb.' in response.get('thumb_url')
)
self.assertTrue(
'filename' in response and
response.get('filename') in response.get('url')
)


class TestingFileStorage(FileStorage):
"""
This is a helper for testing upload behavior in your application. You
Expand All @@ -41,6 +66,7 @@ class TestingFileStorage(FileStorage):
taken from https://github.com/srusskih/flask-uploads/blob/master/flaskext/uploads.py#L476 # nopep8
"""

def __init__(self, stream=None, filename=None, name=None,
content_type='application/octet-stream', content_length=-1,
headers=None):
Expand Down Expand Up @@ -114,6 +140,7 @@ def files(self):

rv = test_client.post('/upload/', data=dict())
self.assertEqual(rv.status_code, status_code)
check_rv_format(self, rv)

def test_base64_screenshot_uploads(self):
'''Test that Base64 screenshots return the expected status codes.'''
Expand Down Expand Up @@ -143,6 +170,7 @@ def form(self):

rv = test_client.post('/upload/', data=dict())
self.assertEqual(rv.status_code, status_code)
check_rv_format(self, rv)


if __name__ == '__main__':
Expand Down

0 comments on commit 62f1452

Please sign in to comment.