This repository was archived by the owner on Apr 4, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 40
Web API: file upload & proposal_pipeline support, tests, and some cleanup #301
Merged
Merged
Changes from 1 commit
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
33dac42
Add support for proposal_pipeline, file uploads. Also add some tests.
tadhg-ohiggins a3d8937
Improve upload file tests, add tests for proposal_pipeline endpoints.
tadhg-ohiggins 8950026
Clean up web API serializer code.
tadhg-ohiggins 6e980be
Add docstrings to more methods of web API views.
tadhg-ohiggins d898673
Web API tests: add fake calls so that tests (which aren't testing act…
tadhg-ohiggins cd39a80
Web API tests: fix Python 2/3 encoding mismatches; stop overriding __…
tadhg-ohiggins 6636491
Web API: fix some minor issues pointed out by CM.
tadhg-ohiggins 4952595
Web API: use email address variable and not my own email address…
tadhg-ohiggins 944df41
Web API: use instead of checking count with filtered .
tadhg-ohiggins 9c71e1e
Web API: add tests for some utility functions, refactor those functions.
tadhg-ohiggins 20d5f97
Web API: per CM's suggestion, move some class properties to instance …
tadhg-ohiggins a2593a4
Web API: per CM's suggestion, make the filesize limit test deal in mu…
tadhg-ohiggins 8d1d836
Web API: per CM's suggestion, move some class properties to instance …
tadhg-ohiggins 9d4ddf4
Web API: per CM's suggestion, use uuid4() instead of fixed values for…
tadhg-ohiggins 03836ec
Web API: per CM's suggestion, patch at a lower level to minimize requ…
tadhg-ohiggins 10c2fbc
Web API: per CM's suggestion, populate expected results dict with def…
tadhg-ohiggins 58f8246
Web API: per CM's suggestion, split test_create_ints() into helper me…
tadhg-ohiggins File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
from hashlib import md5 | ||
from mock import patch | ||
from os import path as ospath | ||
from random import choice | ||
from regparser.web.jobs.models import job_status_values | ||
from regparser.web.jobs.utils import ( | ||
eregs_site_api_url, | ||
|
@@ -9,7 +10,12 @@ | |
) | ||
from regparser.web.jobs.views import FileUploadView as PatchedFileUploadView | ||
from rest_framework.test import APITestCase | ||
from string import hexdigits | ||
from tempfile import NamedTemporaryFile | ||
|
||
import pytest | ||
import settings | ||
|
||
try: | ||
from urllib.parse import urlparse | ||
except ImportError: | ||
|
@@ -19,6 +25,10 @@ | |
fake_email_id = "4774f0f6-b53e-4b34-821e-fc8ae5e113fe" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would it make sense to use |
||
|
||
|
||
def fake_getter(attrname): | ||
return attrname | ||
|
||
|
||
def fake_add_redis_data_to_job_data(job_data): | ||
return job_data | ||
|
||
|
@@ -305,3 +315,61 @@ def test_create_and_read_and_delete(self): | |
|
||
response = self.client.get("/rp/job/proposal-pipeline/", format="json") | ||
self.assertEqual(0, len(response.data)) | ||
|
||
|
||
@patch.object(settings, "CANONICAL_HOSTNAME", "http://domain.tld") | ||
def test_status_url(): | ||
domain = "http://domain.tld" | ||
urlpath = "/rp/job/" | ||
hexes = ["".join([choice(hexdigits) for i in range(32)]) for j in range(6)] | ||
|
||
def _check(port=None): | ||
for hx in hexes: | ||
url = urlparse(status_url(hx)) | ||
assert domain == "%s://%s" % (url.scheme, url.hostname) | ||
if port is None: | ||
assert url.port is port | ||
else: | ||
assert url.port == port | ||
assert "%s%s/" % (urlpath, hx) == url.path | ||
|
||
url = urlparse(status_url(hx, sub_path="%s/" % hx[:10])) | ||
assert domain == "%s://%s" % (url.scheme, url.hostname) | ||
if port is None: | ||
assert url.port is port | ||
else: | ||
assert url.port == port | ||
assert "%s%s%s/" % (urlpath, "%s/" % hx[:10], hx) == url.path | ||
|
||
with patch.object(settings, "CANONICAL_PORT", "2323"): | ||
_check(port=2323) | ||
|
||
with patch.object(settings, "CANONICAL_PORT", "80"): | ||
_check() | ||
|
||
with patch.object(settings, "CANONICAL_PORT", ""): | ||
_check() | ||
|
||
with pytest.raises(ValueError) as err: | ||
status_url("something", "something-without-a-slash") | ||
|
||
assert isinstance(err.value, ValueError) | ||
|
||
|
||
@patch.object(settings, "CANONICAL_HOSTNAME", "http://domain.tld") | ||
def test_file_url(): | ||
urlpath = "/rp/job/upload/" | ||
domain = "http://domain.tld" | ||
hexes = ["".join([choice(hexdigits) for i in range(32)]) for j in range(6)] | ||
|
||
with patch.object(settings, "CANONICAL_PORT", "2323"): | ||
for hx in hexes: | ||
assert file_url(hx) == "%s:2323%s%s/" % (domain, urlpath, hx) | ||
|
||
with patch.object(settings, "CANONICAL_PORT", "80"): | ||
for hx in hexes: | ||
assert file_url(hx) == "%s%s%s/" % (domain, urlpath, hx) | ||
|
||
with patch.object(settings, "CANONICAL_PORT", ""): | ||
for hx in hexes: | ||
assert file_url(hx) == "%s%s%s/" % (domain, urlpath, hx) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would it make sense to do the same for tls + 443?