Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid using cache for dynamic settings while running unit tests #3885

Merged
merged 1 commit into from Jun 23, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 6 additions & 7 deletions kobo/apps/hook/tests/test_api_hook.py
@@ -1,8 +1,8 @@
# coding: utf-8
import json

import constance
import responses
from constance.test import override_config
from django.contrib.auth.models import User
from django.urls import reverse
from mock import patch
Expand Down Expand Up @@ -277,22 +277,21 @@ def request_callback(request):

self.assertEqual(first_hooklog_response.get('status_code'),
status.HTTP_200_OK)
self.assertEqual(json.loads(first_hooklog_response.get('message')),
self.assertEqual(json.loads(first_hooklog_response.get('message')),
expected_response)

@override_config(ALLOW_UNSECURED_HOOK_ENDPOINTS=False)
def test_unsecured_endpoint_validation(self):

constance.config.ALLOW_UNSECURED_HOOK_ENDPOINTS = False

response = self._create_hook(return_response_only=True)
self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
expected_response = {"endpoint": ["Unsecured endpoint is not allowed"]}
self.assertEqual(response.data, expected_response)

def test_payload_template_validation(self):

# Test invalid JSON
response = self._create_hook(payload_template='foo',
response = self._create_hook(payload_template='foo',
return_response_only=True)
self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
expected_response = {
Expand All @@ -309,7 +308,7 @@ def test_payload_template_validation(self):
self.asset.save()

payload_template = '{{"fields": {}}}'.format(SUBMISSION_PLACEHOLDER)
response = self._create_hook(payload_template=payload_template,
response = self._create_hook(payload_template=payload_template,
format_type=Hook.XML,
return_response_only=True)
self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
Expand Down
5 changes: 3 additions & 2 deletions kobo/apps/hook/tests/test_ssrf.py
@@ -1,6 +1,7 @@
# coding: utf-8
import constance

import responses
from constance.test import override_config
from mock import patch
from rest_framework import status

Expand All @@ -15,10 +16,10 @@ class SSRFHookTestCase(HookTestCase):

@patch('ssrf_protect.ssrf_protect.SSRFProtect._get_ip_address',
new=MockSSRFProtect._get_ip_address)
@override_config(SSRF_DENIED_IP_ADDRESS='1.2.3.4')
@responses.activate
def test_send_with_ssrf_options(self):
# Create first hook
constance.config.SSRF_DENIED_IP_ADDRESS = '1.2.3.4'

hook = self._create_hook()

Expand Down
4 changes: 4 additions & 0 deletions kobo/settings/testing.py
Expand Up @@ -31,3 +31,7 @@

ENKETO_URL = 'http://enketo.mock'
ENKETO_INTERNAL_URL = 'http://enketo.mock'

# Do not use cache with Constance in tests to avoid overwriting production
# cached values
CONSTANCE_DATABASE_CACHE_BACKEND = None