Skip to content

Commit

Permalink
Ref #310 -- Add regression test for custom formactions
Browse files Browse the repository at this point in the history
  • Loading branch information
codingjoe committed Nov 1, 2024
1 parent 368999b commit cf9234b
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 0 deletions.
18 changes: 18 additions & 0 deletions tests/test_forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,22 @@ def test_file_insert_submit_value(
assert "save_continue" in driver.page_source
assert "continue_value" in driver.page_source

@pytest.mark.selenium
def test_file_insert_submit_formaction(
self, driver, live_server, upload_file, freeze_upload_folder
):
driver.get(live_server + self.create_url)
file_input = driver.find_element(By.XPATH, "//input[@name='file']")
file_input.send_keys(upload_file)
assert file_input.get_attribute("name") == "file"
save_button = driver.find_element(By.XPATH, "//button[@name='custom_save']")
with wait_for_page_load(driver, timeout=10):
save_button.click()
assert "custom_save" in driver.page_source
assert "custom_target" in driver.page_source
assert "foo" in driver.page_source
assert "bar" in driver.page_source

@pytest.mark.selenium
def test_multi_file(
self,
Expand Down Expand Up @@ -284,6 +300,8 @@ def test_multi_file(
"other_file": [os.path.basename(yet_another_upload_file)],
}



def test_media(self):
assert ClearableFileInput().media._js == ["s3file/js/s3file.js"]

Expand Down
1 change: 1 addition & 0 deletions tests/testapp/templates/form.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
{{ form }}
<input type="submit" name="save" value="Save"/>
<button type="submit" name="save_continue" value="continue_value">Save &amp; continue</button>
<button type="submit" name="custom_save" value="custom_target" formaction="{% url 'example-create' %}?foo=bar">Save &amp; continue</button>
</form>
{{ form.media.js }}
</body>
Expand Down
1 change: 1 addition & 0 deletions tests/testapp/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ class ExampleCreateView(generic.CreateView):
def form_valid(self, form):
return JsonResponse(
{
"GET": self.request.GET,
"POST": self.request.POST,
"FILES": {
"file": self.request.FILES.getlist("file"),
Expand Down

0 comments on commit cf9234b

Please sign in to comment.