import mock
import os

from boto.s3.connection import S3Connection
from django.test import TestCase, override_settings
from reports.utils import get_s3_connection


class UtilsTestCase(TestCase):
    @override_settings(AWS_ACCESS_KEY_ID="000000000001", AWS_SECRET_ACCESS_KEY="000000000002")
    def test_get_s3_connection(self):
        envs = {"AWS_S3_HOST": "s3.eu-west-2.amazonaws.com", "S3_USE_SIGV4": "True"}
        with mock.patch.dict(os.environ, envs):
            conn = get_s3_connection()
            self.assertIsInstance(conn, S3Connection)

import mock
import os

from boto.s3.connection import S3Connection
from django.test import TestCase, override_settings
from reports.utils import get_s3_connection


class UtilsTestCase(TestCase):
    @override_settings(AWS_ACCESS_KEY_ID="000000000001", AWS_SECRET_ACCESS_KEY="000000000002", AWS_S3_HOST="s3.eu-west-2.amazonaws.com")
    def test_get_s3_connection(self):
        envs = {"S3_USE_SIGV4": "True"}
        with mock.patch.dict(os.environ, envs):
            conn = get_s3_connection()
            self.assertIsInstance(conn, S3Connection)

Modify s3 connection test for new AWS_S3_HOST setting
Modify s3 connection test for new AWS_S3_HOST setting

The value is now calculated from the env var at load time, so mocking
the env var value is not effective

(cherry picked from commit 044219df7123e3a03a38cc06c9e8e8e9e80b0cbe)

  import mock
  import os
  
  from boto.s3.connection import S3Connection
  from django.test import TestCase, override_settings
  from reports.utils import get_s3_connection
  
  
  class UtilsTestCase(TestCase):
-     @override_settings(AWS_ACCESS_KEY_ID="000000000001", AWS_SECRET_ACCESS_KEY="000000000002")
+     @override_settings(AWS_ACCESS_KEY_ID="000000000001", AWS_SECRET_ACCESS_KEY="000000000002", AWS_S3_HOST="s3.eu-west-2.amazonaws.com")
      def test_get_s3_connection(self):
-         envs = {"AWS_S3_HOST": "s3.eu-west-2.amazonaws.com", "S3_USE_SIGV4": "True"}
+         envs = {"S3_USE_SIGV4": "True"}
          with mock.patch.dict(os.environ, envs):
              conn = get_s3_connection()
              self.assertIsInstance(conn, S3Connection)
  
Modify s3 connection test for new AWS_S3_HOST setting
## Code Before:
import mock
import os

from boto.s3.connection import S3Connection
from django.test import TestCase, override_settings
from reports.utils import get_s3_connection


class UtilsTestCase(TestCase):
    @override_settings(AWS_ACCESS_KEY_ID="000000000001", AWS_SECRET_ACCESS_KEY="000000000002")
    def test_get_s3_connection(self):
        envs = {"AWS_S3_HOST": "s3.eu-west-2.amazonaws.com", "S3_USE_SIGV4": "True"}
        with mock.patch.dict(os.environ, envs):
            conn = get_s3_connection()
            self.assertIsInstance(conn, S3Connection)

## Instruction:
Modify s3 connection test for new AWS_S3_HOST setting
## Code After:
import mock
import os

from boto.s3.connection import S3Connection
from django.test import TestCase, override_settings
from reports.utils import get_s3_connection


class UtilsTestCase(TestCase):
    @override_settings(AWS_ACCESS_KEY_ID="000000000001", AWS_SECRET_ACCESS_KEY="000000000002", AWS_S3_HOST="s3.eu-west-2.amazonaws.com")
    def test_get_s3_connection(self):
        envs = {"S3_USE_SIGV4": "True"}
        with mock.patch.dict(os.environ, envs):
            conn = get_s3_connection()
            self.assertIsInstance(conn, S3Connection)
