Skip to content

Commit

Permalink
Add a test for base_url choice field
Browse files Browse the repository at this point in the history
  • Loading branch information
atodorov committed Sep 12, 2023
1 parent 9224700 commit d186aa1
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions trackers_integration/tests/test_internals.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,41 @@ def test_adding_a_token_updates_the_owner_field_to_the_current_user(self):
self.assertEqual(token.base_url, "http://open-project.example.com")
self.assertEqual(token.api_username, "kiwitcms-bot")

def test_add_view_shows_dropdown_select_of_existing_bug_trackers(self):
response = self.client.get(reverse("admin:trackers_integration_apitoken_add"))
# warning: can't assert on the select tag b/c order of its attribute change
# but html=True expects a closed <select> tag with everything in between
self.assertContains(
response,
'<option value="https://mantis.example.com:8443/mantisbt">'
'https://mantis.example.com:8443/mantisbt</option>',
html=True,
)
self.assertContains(
response,
'<option value="http://open-project.example.com">'
'http://open-project.example.com</option>',
html=True,
)

# POSTing an invalid base_url will trigger an error
response = self.client.post(
reverse("admin:trackers_integration_apitoken_add"),
{
"base_url": "http://invalid.com",
"api_username": "kiwitcms-bot",
"api_password": __FOR_TESTING__,
},
follow=True,
)
self.assertNotContains(response, "kiwitcms-bot @ http://invalid.com")
self.assertNotContains(response, "was added successfully")
self.assertContains(response, "Please correct the error below")
self.assertContains(
response,
"Select a valid choice. http://invalid.com is not one of the available choices.",
)

def test_changelist_view_doesnt_show_records_from_other_users(self):
response = self.client.get(
reverse("admin:trackers_integration_apitoken_changelist")
Expand Down

0 comments on commit d186aa1

Please sign in to comment.