Skip to content

Commit

Permalink
Test Basic Auth parameter is passed to requests
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel Kirkham committed Nov 6, 2023
1 parent a350a5a commit c0d864c
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 0 deletions.
7 changes: 7 additions & 0 deletions tests/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,13 @@
'SECRET_KEY': 'i-am-the-local-secret-key',
}
}
WAGTAILTRANSFER_SOURCES_BASIC_AUTH = {
'staging': {
'BASE_URL': 'https://www.example.com/wagtail-transfer/',
'SECRET_KEY': 'i-am-the-staging-example-secret-key',
'BASIC_AUTH_SECRET': ('staging-user', 'staging-pass'),
},
}

WAGTAILTRANSFER_FOLLOWED_REVERSE_RELATIONS = [('wagtailimages.image', 'tagged_items', True), ('tests.advert', 'tagged_items', True)]

Expand Down
37 changes: 37 additions & 0 deletions tests/tests/test_import.py
Original file line number Diff line number Diff line change
Expand Up @@ -2037,3 +2037,40 @@ def test_import_model_with_untracked_deleted_reverse_related_models(self):
imported_ad = Advert.objects.filter(id=4).first()
self.assertIsNotNone(imported_ad)
self.assertIsNotNone(imported_ad.tags.first())

@override_settings(WAGTAILTRANSFER_SOURCES=settings.WAGTAILTRANSFER_SOURCES_BASIC_AUTH)
@mock.patch('requests.get')
def test_basic_auth(self, get):
# tests the auth parameters are added to the GET request
# based on test_import_custom_file_field()

data = """{
"ids_for_import": [
["tests.avatar", 123]
],
"mappings": [
["tests.avatar", 123, "01230123-0000-0000-0000-000000000000"]
],
"objects": [
{
"model": "tests.avatar",
"pk": 123,
"fields": {
"image": {
"download_url": "https://wagtail.io/media/original_images/muddy_waters.jpg",
"size": 18521,
"hash": "e4eab12cc50b6b9c619c9ddd20b61d8e6a961ada"
}
}
}
]
}"""

importer = ImportPlanner(root_page_source_pk=1, destination_parent_id=None, source_site="staging")
importer.add_json(data)
importer.run()

self.assertEquals(
get.call_args.kwargs['auth'],
settings.WAGTAILTRANSFER_SOURCES_BASIC_AUTH['staging']['BASIC_AUTH_SECRET']
)

0 comments on commit c0d864c

Please sign in to comment.