We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Fix health checker /ping/ - infinite looping

Improve check_database_connection function
We can improve this code like that:

```python
def check_database_connection(**kwargs):
        for conn in connections.all():
            try:
                conn.cursor()
                return True
            except OperationalError:
                return False
        return False
```

reported by @eltonplima in #158 
Improve check_database_connection function
We can improve this code like that:

```python
def check_database_connection(**kwargs):
        for conn in connections.all():
            try:
                conn.cursor()
                return True
            except OperationalError:
                return False
        return False
```

reported by @eltonplima in #158 

--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `bothub/health/checks.py`
Content:
```
1 def check_database_connection(**kwargs):
2     from django.db import connections
3     from django.db.utils import OperationalError
4     db_conn = connections['default']
5     if not db_conn:
6         return False
7     try:
8         db_conn.cursor()
9         return True
10     except OperationalError as e:
11         return False
12 
13 
14 def check_accessible_api(request, **kwargs):
15     import requests
16     HTTP_HOST = request.META.get('HTTP_HOST')
17     repositories_url = 'http://{}/api/repositories/'.format(HTTP_HOST)
18     request = requests.get(repositories_url)
19     try:
20         request.raise_for_status()
21         return True
22     except requests.HTTPError as e:
23         return False
24
```

Path: `setup.py`
Content:
```
1 from setuptools import setup, find_packages
2 
3 
4 setup(
5     name='bothub',
6     version='1.13.3',
7     description='bothub',
8     packages=find_packages(),
9     install_requires=[
10         'python-decouple',
11         'requests',
12         'django==2.0.6',
13         'djangorestframework==3.7.7',
14         'whitenoise',
15         'dj-database-url',
16         'django-cors-headers',
17         'django-filter',
18         'coreapi',
19     ],
20     python_requires='>=3.6',
21 )
22
```

Path: `bothub/settings.py`
Content:
```
1 import os
2 import dj_database_url
3 
4 from decouple import config
5 
6 
7 # Build paths inside the project like this: os.path.join(BASE_DIR, ...)
8 BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
9 
10 
11 # SECURITY WARNING: keep the secret key used in production secret!
12 SECRET_KEY = config('SECRET_KEY')
13 
14 # SECURITY WARNING: don't run with debug turned on in production!
15 DEBUG = config('DEBUG', default=False, cast=bool)
16 
17 ALLOWED_HOSTS = config(
18     'ALLOWED_HOSTS',
19     default='*',
20     cast=lambda v: [s.strip() for s in v.split(',')])
21 
22 
23 # Application definition
24 
25 INSTALLED_APPS = [
26     'django.contrib.admin',
27     'django.contrib.auth',
28     'django.contrib.contenttypes',
29     'django.contrib.sessions',
30     'django.contrib.messages',
31     'django.contrib.staticfiles',
32     'rest_framework',
33     'rest_framework.authtoken',
34     'django_filters',
35     'corsheaders',
36     'bothub.authentication',
37     'bothub.common',
38     'bothub.api',
39 ]
40 
41 MIDDLEWARE = [
42     'django.middleware.security.SecurityMiddleware',
43     'whitenoise.middleware.WhiteNoiseMiddleware',
44     'django.contrib.sessions.middleware.SessionMiddleware',
45     'corsheaders.middleware.CorsMiddleware',
46     'django.middleware.common.CommonMiddleware',
47     'django.middleware.csrf.CsrfViewMiddleware',
48     'django.contrib.auth.middleware.AuthenticationMiddleware',
49     'django.contrib.messages.middleware.MessageMiddleware',
50     'django.middleware.clickjacking.XFrameOptionsMiddleware',
51 ]
52 
53 ROOT_URLCONF = 'bothub.urls'
54 
55 TEMPLATES = [
56     {
57         'BACKEND': 'django.template.backends.django.DjangoTemplates',
58         'DIRS': [],
59         'APP_DIRS': True,
60         'OPTIONS': {
61             'context_processors': [
62                 'django.template.context_processors.debug',
63                 'django.template.context_processors.request',
64                 'django.contrib.auth.context_processors.auth',
65                 'django.contrib.messages.context_processors.messages',
66             ],
67         },
68     },
69 ]
70 
71 WSGI_APPLICATION = 'bothub.wsgi.application'
72 
73 
74 # Database
75 
76 DATABASES = {}
77 DATABASES['default'] = dj_database_url.parse(
78     config(
79         'DEFAULT_DATABASE',
80         default='sqlite:///db.sqlite3'))
81 
82 
83 # Auth
84 
85 AUTH_USER_MODEL = 'authentication.User'
86 
87 
88 # Password validation
89 
90 AUTH_PASSWORD_VALIDATORS = [
91     {
92         'NAME': 'django.contrib.auth.password_validation.' +
93         'UserAttributeSimilarityValidator',
94     },
95     {
96         'NAME': 'django.contrib.auth.password_validation.' +
97         'MinimumLengthValidator',
98     },
99     {
100         'NAME': 'django.contrib.auth.password_validation.' +
101         'CommonPasswordValidator',
102     },
103     {
104         'NAME': 'django.contrib.auth.password_validation.' +
105         'NumericPasswordValidator',
106     },
107 ]
108 
109 
110 # Internationalization
111 
112 LANGUAGE_CODE = config('LANGUAGE_CODE', default='en-us')
113 
114 TIME_ZONE = config('TIME_ZONE', default='UTC')
115 
116 USE_I18N = True
117 
118 USE_L10N = True
119 
120 USE_TZ = True
121 
122 
123 # Static files (CSS, JavaScript, Images)
124 
125 STATIC_URL = config('STATIC_URL', default='/static/')
126 
127 STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles')
128 
129 STATICFILES_STORAGE = 'whitenoise.storage.CompressedManifestStaticFilesStorage'
130 
131 
132 # rest framework
133 
134 REST_FRAMEWORK = {
135     'DEFAULT_AUTHENTICATION_CLASSES': [
136         'rest_framework.authentication.TokenAuthentication',
137     ],
138     'DEFAULT_PAGINATION_CLASS': 'rest_framework.pagination.' +
139     'LimitOffsetPagination',
140     'PAGE_SIZE': 20,
141     'DEFAULT_FILTER_BACKENDS': [
142         'django_filters.rest_framework.DjangoFilterBackend',
143     ],
144     'DEFAULT_METADATA_CLASS': 'bothub.api.metadata.Metadata',
145 }
146 
147 
148 # cors headers
149 
150 CORS_ORIGIN_ALLOW_ALL = True
151 CORS_URLS_REGEX = r'^/api/.*$'
152 
153 
154 # mail
155 
156 envvar_EMAIL_HOST = config('EMAIL_HOST', default=None)
157 
158 ADMINS = config(
159     'ADMINS',
160     default='',
161     cast=lambda v: [
162         (
163             s.strip().split('|')[0],
164             s.strip().split('|')[1],
165         ) for s in v.split(',')] if v else [])
166 EMAIL_SUBJECT_PREFIX = '[bothub] '
167 DEFAULT_FROM_EMAIL = config(
168     'DEFAULT_FROM_EMAIL',
169     default='webmaster@localhost')
170 SERVER_EMAIL = config('SERVER_EMAIL', default='root@localhost')
171 
172 if envvar_EMAIL_HOST:
173     EMAIL_HOST = envvar_EMAIL_HOST
174     EMAIL_PORT = config('EMAIL_PORT', default=25, cast=int)
175     EMAIL_HOST_USER = config('EMAIL_HOST_USER', default='')
176     EMAIL_HOST_PASSWORD = config('EMAIL_HOST_PASSWORD', default='')
177     EMAIL_USE_SSL = config('EMAIL_USE_SSL', default=False, cast=bool)
178     EMAIL_USE_TLS = config('EMAIL_USE_TLS', default=False, cast=bool)
179 else:
180     EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend'
181 
182 
183 # webapp
184 
185 BOTHUB_WEBAPP_BASE_URL = config(
186     'BOTHUB_WEBAPP_BASE_URL',
187     default='http://localhost:8080/')
188 
189 
190 # NLP
191 
192 BOTHUB_NLP_BASE_URL = config(
193     'BOTHUB_NLP_BASE_URL',
194     default='http://localhost:8001/')
195 
196 
197 # CSRF
198 
199 CSRF_COOKIE_DOMAIN = config(
200     'CSRF_COOKIE_DOMAIN',
201     default=None)
202 
203 CSRF_COOKIE_SECURE = config(
204     'CSRF_COOKIE_SECURE',
205     default=False,
206     cast=bool)
207
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/bothub/health/checks.py b/bothub/health/checks.py
--- a/bothub/health/checks.py
+++ b/bothub/health/checks.py
@@ -1,23 +1,37 @@
+import logging
+
+from rest_framework import status
+
+
+logger = logging.getLogger('bothub.health.checks')
+
+CHECK_ACCESSIBLE_API_URL = '/api/repositories/'
+
+
 def check_database_connection(**kwargs):
     from django.db import connections
     from django.db.utils import OperationalError
-    db_conn = connections['default']
-    if not db_conn:
-        return False
-    try:
-        db_conn.cursor()
-        return True
-    except OperationalError as e:
+    if len(connections.all()) is 0:
         return False
+    logger.info('found {} database connection'.format(len(connections.all())))
+    for i, conn in enumerate(connections.all(), 1):
+        try:
+            conn.cursor()
+            logger.info('#{} db connection OKAY'.format(i))
+        except OperationalError as e:
+            logger.warning('#{} db connection ERROR'.format(i))
+            return False
+    return True
 
 
 def check_accessible_api(request, **kwargs):
-    import requests
-    HTTP_HOST = request.META.get('HTTP_HOST')
-    repositories_url = 'http://{}/api/repositories/'.format(HTTP_HOST)
-    request = requests.get(repositories_url)
-    try:
-        request.raise_for_status()
+    from django.test import Client
+    logger.info('making request to {}'.format(CHECK_ACCESSIBLE_API_URL))
+    client = Client()
+    response = client.get(CHECK_ACCESSIBLE_API_URL)
+    logger.info('{} status code: {}'.format(
+        CHECK_ACCESSIBLE_API_URL,
+        response.status_code))
+    if response.status_code is status.HTTP_200_OK:
         return True
-    except requests.HTTPError as e:
-        return False
+    return False
diff --git a/bothub/settings.py b/bothub/settings.py
--- a/bothub/settings.py
+++ b/bothub/settings.py
@@ -2,6 +2,7 @@
 import dj_database_url
 
 from decouple import config
+from django.utils.log import DEFAULT_LOGGING
 
 
 # Build paths inside the project like this: os.path.join(BASE_DIR, ...)
@@ -191,7 +192,7 @@
 
 BOTHUB_NLP_BASE_URL = config(
     'BOTHUB_NLP_BASE_URL',
-    default='http://localhost:8001/')
+    default='http://localhost:2657/')
 
 
 # CSRF
@@ -204,3 +205,21 @@
     'CSRF_COOKIE_SECURE',
     default=False,
     cast=bool)
+
+
+# Logging
+
+LOGGING = DEFAULT_LOGGING
+LOGGING['formatters']['bothub.health'] = {
+    'format': '[bothub.health] {message}',
+    'style': '{',
+}
+LOGGING['handlers']['bothub.health'] = {
+    'level': 'DEBUG',
+    'class': 'logging.StreamHandler',
+    'formatter': 'bothub.health',
+}
+LOGGING['loggers']['bothub.health.checks'] = {
+    'handlers': ['bothub.health'],
+    'level': 'DEBUG',
+}
diff --git a/setup.py b/setup.py
--- a/setup.py
+++ b/setup.py
@@ -3,7 +3,7 @@
 
 setup(
     name='bothub',
-    version='1.13.3',
+    version='1.13.4',
     description='bothub',
     packages=find_packages(),
     install_requires=[

{"golden_diff": "diff --git a/bothub/health/checks.py b/bothub/health/checks.py\n--- a/bothub/health/checks.py\n+++ b/bothub/health/checks.py\n@@ -1,23 +1,37 @@\n+import logging\n+\n+from rest_framework import status\n+\n+\n+logger = logging.getLogger('bothub.health.checks')\n+\n+CHECK_ACCESSIBLE_API_URL = '/api/repositories/'\n+\n+\n def check_database_connection(**kwargs):\n     from django.db import connections\n     from django.db.utils import OperationalError\n-    db_conn = connections['default']\n-    if not db_conn:\n-        return False\n-    try:\n-        db_conn.cursor()\n-        return True\n-    except OperationalError as e:\n+    if len(connections.all()) is 0:\n         return False\n+    logger.info('found {} database connection'.format(len(connections.all())))\n+    for i, conn in enumerate(connections.all(), 1):\n+        try:\n+            conn.cursor()\n+            logger.info('#{} db connection OKAY'.format(i))\n+        except OperationalError as e:\n+            logger.warning('#{} db connection ERROR'.format(i))\n+            return False\n+    return True\n \n \n def check_accessible_api(request, **kwargs):\n-    import requests\n-    HTTP_HOST = request.META.get('HTTP_HOST')\n-    repositories_url = 'http://{}/api/repositories/'.format(HTTP_HOST)\n-    request = requests.get(repositories_url)\n-    try:\n-        request.raise_for_status()\n+    from django.test import Client\n+    logger.info('making request to {}'.format(CHECK_ACCESSIBLE_API_URL))\n+    client = Client()\n+    response = client.get(CHECK_ACCESSIBLE_API_URL)\n+    logger.info('{} status code: {}'.format(\n+        CHECK_ACCESSIBLE_API_URL,\n+        response.status_code))\n+    if response.status_code is status.HTTP_200_OK:\n         return True\n-    except requests.HTTPError as e:\n-        return False\n+    return False\ndiff --git a/bothub/settings.py b/bothub/settings.py\n--- a/bothub/settings.py\n+++ b/bothub/settings.py\n@@ -2,6 +2,7 @@\n import dj_database_url\n \n from decouple import config\n+from django.utils.log import DEFAULT_LOGGING\n \n \n # Build paths inside the project like this: os.path.join(BASE_DIR, ...)\n@@ -191,7 +192,7 @@\n \n BOTHUB_NLP_BASE_URL = config(\n     'BOTHUB_NLP_BASE_URL',\n-    default='http://localhost:8001/')\n+    default='http://localhost:2657/')\n \n \n # CSRF\n@@ -204,3 +205,21 @@\n     'CSRF_COOKIE_SECURE',\n     default=False,\n     cast=bool)\n+\n+\n+# Logging\n+\n+LOGGING = DEFAULT_LOGGING\n+LOGGING['formatters']['bothub.health'] = {\n+    'format': '[bothub.health] {message}',\n+    'style': '{',\n+}\n+LOGGING['handlers']['bothub.health'] = {\n+    'level': 'DEBUG',\n+    'class': 'logging.StreamHandler',\n+    'formatter': 'bothub.health',\n+}\n+LOGGING['loggers']['bothub.health.checks'] = {\n+    'handlers': ['bothub.health'],\n+    'level': 'DEBUG',\n+}\ndiff --git a/setup.py b/setup.py\n--- a/setup.py\n+++ b/setup.py\n@@ -3,7 +3,7 @@\n \n setup(\n     name='bothub',\n-    version='1.13.3',\n+    version='1.13.4',\n     description='bothub',\n     packages=find_packages(),\n     install_requires=[\n", "issue": "Fix health checker /ping/ - infinite looping\n\nImprove check_database_connection function\nWe can improve this code like that:\r\n\r\n```python\r\ndef check_database_connection(**kwargs):\r\n        for conn in connections.all():\r\n            try:\r\n                conn.cursor()\r\n                return True\r\n            except OperationalError:\r\n                return False\r\n        return False\r\n```\r\n\r\nreported by @eltonplima in #158 \nImprove check_database_connection function\nWe can improve this code like that:\r\n\r\n```python\r\ndef check_database_connection(**kwargs):\r\n        for conn in connections.all():\r\n            try:\r\n                conn.cursor()\r\n                return True\r\n            except OperationalError:\r\n                return False\r\n        return False\r\n```\r\n\r\nreported by @eltonplima in #158 \n", "before_files": [{"content": "def check_database_connection(**kwargs):\n    from django.db import connections\n    from django.db.utils import OperationalError\n    db_conn = connections['default']\n    if not db_conn:\n        return False\n    try:\n        db_conn.cursor()\n        return True\n    except OperationalError as e:\n        return False\n\n\ndef check_accessible_api(request, **kwargs):\n    import requests\n    HTTP_HOST = request.META.get('HTTP_HOST')\n    repositories_url = 'http://{}/api/repositories/'.format(HTTP_HOST)\n    request = requests.get(repositories_url)\n    try:\n        request.raise_for_status()\n        return True\n    except requests.HTTPError as e:\n        return False\n", "path": "bothub/health/checks.py"}, {"content": "from setuptools import setup, find_packages\n\n\nsetup(\n    name='bothub',\n    version='1.13.3',\n    description='bothub',\n    packages=find_packages(),\n    install_requires=[\n        'python-decouple',\n        'requests',\n        'django==2.0.6',\n        'djangorestframework==3.7.7',\n        'whitenoise',\n        'dj-database-url',\n        'django-cors-headers',\n        'django-filter',\n        'coreapi',\n    ],\n    python_requires='>=3.6',\n)\n", "path": "setup.py"}, {"content": "import os\nimport dj_database_url\n\nfrom decouple import config\n\n\n# Build paths inside the project like this: os.path.join(BASE_DIR, ...)\nBASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))\n\n\n# SECURITY WARNING: keep the secret key used in production secret!\nSECRET_KEY = config('SECRET_KEY')\n\n# SECURITY WARNING: don't run with debug turned on in production!\nDEBUG = config('DEBUG', default=False, cast=bool)\n\nALLOWED_HOSTS = config(\n    'ALLOWED_HOSTS',\n    default='*',\n    cast=lambda v: [s.strip() for s in v.split(',')])\n\n\n# Application definition\n\nINSTALLED_APPS = [\n    'django.contrib.admin',\n    'django.contrib.auth',\n    'django.contrib.contenttypes',\n    'django.contrib.sessions',\n    'django.contrib.messages',\n    'django.contrib.staticfiles',\n    'rest_framework',\n    'rest_framework.authtoken',\n    'django_filters',\n    'corsheaders',\n    'bothub.authentication',\n    'bothub.common',\n    'bothub.api',\n]\n\nMIDDLEWARE = [\n    'django.middleware.security.SecurityMiddleware',\n    'whitenoise.middleware.WhiteNoiseMiddleware',\n    'django.contrib.sessions.middleware.SessionMiddleware',\n    'corsheaders.middleware.CorsMiddleware',\n    'django.middleware.common.CommonMiddleware',\n    'django.middleware.csrf.CsrfViewMiddleware',\n    'django.contrib.auth.middleware.AuthenticationMiddleware',\n    'django.contrib.messages.middleware.MessageMiddleware',\n    'django.middleware.clickjacking.XFrameOptionsMiddleware',\n]\n\nROOT_URLCONF = 'bothub.urls'\n\nTEMPLATES = [\n    {\n        'BACKEND': 'django.template.backends.django.DjangoTemplates',\n        'DIRS': [],\n        'APP_DIRS': True,\n        'OPTIONS': {\n            'context_processors': [\n                'django.template.context_processors.debug',\n                'django.template.context_processors.request',\n                'django.contrib.auth.context_processors.auth',\n                'django.contrib.messages.context_processors.messages',\n            ],\n        },\n    },\n]\n\nWSGI_APPLICATION = 'bothub.wsgi.application'\n\n\n# Database\n\nDATABASES = {}\nDATABASES['default'] = dj_database_url.parse(\n    config(\n        'DEFAULT_DATABASE',\n        default='sqlite:///db.sqlite3'))\n\n\n# Auth\n\nAUTH_USER_MODEL = 'authentication.User'\n\n\n# Password validation\n\nAUTH_PASSWORD_VALIDATORS = [\n    {\n        'NAME': 'django.contrib.auth.password_validation.' +\n        'UserAttributeSimilarityValidator',\n    },\n    {\n        'NAME': 'django.contrib.auth.password_validation.' +\n        'MinimumLengthValidator',\n    },\n    {\n        'NAME': 'django.contrib.auth.password_validation.' +\n        'CommonPasswordValidator',\n    },\n    {\n        'NAME': 'django.contrib.auth.password_validation.' +\n        'NumericPasswordValidator',\n    },\n]\n\n\n# Internationalization\n\nLANGUAGE_CODE = config('LANGUAGE_CODE', default='en-us')\n\nTIME_ZONE = config('TIME_ZONE', default='UTC')\n\nUSE_I18N = True\n\nUSE_L10N = True\n\nUSE_TZ = True\n\n\n# Static files (CSS, JavaScript, Images)\n\nSTATIC_URL = config('STATIC_URL', default='/static/')\n\nSTATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles')\n\nSTATICFILES_STORAGE = 'whitenoise.storage.CompressedManifestStaticFilesStorage'\n\n\n# rest framework\n\nREST_FRAMEWORK = {\n    'DEFAULT_AUTHENTICATION_CLASSES': [\n        'rest_framework.authentication.TokenAuthentication',\n    ],\n    'DEFAULT_PAGINATION_CLASS': 'rest_framework.pagination.' +\n    'LimitOffsetPagination',\n    'PAGE_SIZE': 20,\n    'DEFAULT_FILTER_BACKENDS': [\n        'django_filters.rest_framework.DjangoFilterBackend',\n    ],\n    'DEFAULT_METADATA_CLASS': 'bothub.api.metadata.Metadata',\n}\n\n\n# cors headers\n\nCORS_ORIGIN_ALLOW_ALL = True\nCORS_URLS_REGEX = r'^/api/.*$'\n\n\n# mail\n\nenvvar_EMAIL_HOST = config('EMAIL_HOST', default=None)\n\nADMINS = config(\n    'ADMINS',\n    default='',\n    cast=lambda v: [\n        (\n            s.strip().split('|')[0],\n            s.strip().split('|')[1],\n        ) for s in v.split(',')] if v else [])\nEMAIL_SUBJECT_PREFIX = '[bothub] '\nDEFAULT_FROM_EMAIL = config(\n    'DEFAULT_FROM_EMAIL',\n    default='webmaster@localhost')\nSERVER_EMAIL = config('SERVER_EMAIL', default='root@localhost')\n\nif envvar_EMAIL_HOST:\n    EMAIL_HOST = envvar_EMAIL_HOST\n    EMAIL_PORT = config('EMAIL_PORT', default=25, cast=int)\n    EMAIL_HOST_USER = config('EMAIL_HOST_USER', default='')\n    EMAIL_HOST_PASSWORD = config('EMAIL_HOST_PASSWORD', default='')\n    EMAIL_USE_SSL = config('EMAIL_USE_SSL', default=False, cast=bool)\n    EMAIL_USE_TLS = config('EMAIL_USE_TLS', default=False, cast=bool)\nelse:\n    EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend'\n\n\n# webapp\n\nBOTHUB_WEBAPP_BASE_URL = config(\n    'BOTHUB_WEBAPP_BASE_URL',\n    default='http://localhost:8080/')\n\n\n# NLP\n\nBOTHUB_NLP_BASE_URL = config(\n    'BOTHUB_NLP_BASE_URL',\n    default='http://localhost:8001/')\n\n\n# CSRF\n\nCSRF_COOKIE_DOMAIN = config(\n    'CSRF_COOKIE_DOMAIN',\n    default=None)\n\nCSRF_COOKIE_SECURE = config(\n    'CSRF_COOKIE_SECURE',\n    default=False,\n    cast=bool)\n", "path": "bothub/settings.py"}], "after_files": [{"content": "import logging\n\nfrom rest_framework import status\n\n\nlogger = logging.getLogger('bothub.health.checks')\n\nCHECK_ACCESSIBLE_API_URL = '/api/repositories/'\n\n\ndef check_database_connection(**kwargs):\n    from django.db import connections\n    from django.db.utils import OperationalError\n    if len(connections.all()) is 0:\n        return False\n    logger.info('found {} database connection'.format(len(connections.all())))\n    for i, conn in enumerate(connections.all(), 1):\n        try:\n            conn.cursor()\n            logger.info('#{} db connection OKAY'.format(i))\n        except OperationalError as e:\n            logger.warning('#{} db connection ERROR'.format(i))\n            return False\n    return True\n\n\ndef check_accessible_api(request, **kwargs):\n    from django.test import Client\n    logger.info('making request to {}'.format(CHECK_ACCESSIBLE_API_URL))\n    client = Client()\n    response = client.get(CHECK_ACCESSIBLE_API_URL)\n    logger.info('{} status code: {}'.format(\n        CHECK_ACCESSIBLE_API_URL,\n        response.status_code))\n    if response.status_code is status.HTTP_200_OK:\n        return True\n    return False\n", "path": "bothub/health/checks.py"}, {"content": "from setuptools import setup, find_packages\n\n\nsetup(\n    name='bothub',\n    version='1.13.4',\n    description='bothub',\n    packages=find_packages(),\n    install_requires=[\n        'python-decouple',\n        'requests',\n        'django==2.0.6',\n        'djangorestframework==3.7.7',\n        'whitenoise',\n        'dj-database-url',\n        'django-cors-headers',\n        'django-filter',\n        'coreapi',\n    ],\n    python_requires='>=3.6',\n)\n", "path": "setup.py"}, {"content": "import os\nimport dj_database_url\n\nfrom decouple import config\nfrom django.utils.log import DEFAULT_LOGGING\n\n\n# Build paths inside the project like this: os.path.join(BASE_DIR, ...)\nBASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))\n\n\n# SECURITY WARNING: keep the secret key used in production secret!\nSECRET_KEY = config('SECRET_KEY')\n\n# SECURITY WARNING: don't run with debug turned on in production!\nDEBUG = config('DEBUG', default=False, cast=bool)\n\nALLOWED_HOSTS = config(\n    'ALLOWED_HOSTS',\n    default='*',\n    cast=lambda v: [s.strip() for s in v.split(',')])\n\n\n# Application definition\n\nINSTALLED_APPS = [\n    'django.contrib.admin',\n    'django.contrib.auth',\n    'django.contrib.contenttypes',\n    'django.contrib.sessions',\n    'django.contrib.messages',\n    'django.contrib.staticfiles',\n    'rest_framework',\n    'rest_framework.authtoken',\n    'django_filters',\n    'corsheaders',\n    'bothub.authentication',\n    'bothub.common',\n    'bothub.api',\n]\n\nMIDDLEWARE = [\n    'django.middleware.security.SecurityMiddleware',\n    'whitenoise.middleware.WhiteNoiseMiddleware',\n    'django.contrib.sessions.middleware.SessionMiddleware',\n    'corsheaders.middleware.CorsMiddleware',\n    'django.middleware.common.CommonMiddleware',\n    'django.middleware.csrf.CsrfViewMiddleware',\n    'django.contrib.auth.middleware.AuthenticationMiddleware',\n    'django.contrib.messages.middleware.MessageMiddleware',\n    'django.middleware.clickjacking.XFrameOptionsMiddleware',\n]\n\nROOT_URLCONF = 'bothub.urls'\n\nTEMPLATES = [\n    {\n        'BACKEND': 'django.template.backends.django.DjangoTemplates',\n        'DIRS': [],\n        'APP_DIRS': True,\n        'OPTIONS': {\n            'context_processors': [\n                'django.template.context_processors.debug',\n                'django.template.context_processors.request',\n                'django.contrib.auth.context_processors.auth',\n                'django.contrib.messages.context_processors.messages',\n            ],\n        },\n    },\n]\n\nWSGI_APPLICATION = 'bothub.wsgi.application'\n\n\n# Database\n\nDATABASES = {}\nDATABASES['default'] = dj_database_url.parse(\n    config(\n        'DEFAULT_DATABASE',\n        default='sqlite:///db.sqlite3'))\n\n\n# Auth\n\nAUTH_USER_MODEL = 'authentication.User'\n\n\n# Password validation\n\nAUTH_PASSWORD_VALIDATORS = [\n    {\n        'NAME': 'django.contrib.auth.password_validation.' +\n        'UserAttributeSimilarityValidator',\n    },\n    {\n        'NAME': 'django.contrib.auth.password_validation.' +\n        'MinimumLengthValidator',\n    },\n    {\n        'NAME': 'django.contrib.auth.password_validation.' +\n        'CommonPasswordValidator',\n    },\n    {\n        'NAME': 'django.contrib.auth.password_validation.' +\n        'NumericPasswordValidator',\n    },\n]\n\n\n# Internationalization\n\nLANGUAGE_CODE = config('LANGUAGE_CODE', default='en-us')\n\nTIME_ZONE = config('TIME_ZONE', default='UTC')\n\nUSE_I18N = True\n\nUSE_L10N = True\n\nUSE_TZ = True\n\n\n# Static files (CSS, JavaScript, Images)\n\nSTATIC_URL = config('STATIC_URL', default='/static/')\n\nSTATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles')\n\nSTATICFILES_STORAGE = 'whitenoise.storage.CompressedManifestStaticFilesStorage'\n\n\n# rest framework\n\nREST_FRAMEWORK = {\n    'DEFAULT_AUTHENTICATION_CLASSES': [\n        'rest_framework.authentication.TokenAuthentication',\n    ],\n    'DEFAULT_PAGINATION_CLASS': 'rest_framework.pagination.' +\n    'LimitOffsetPagination',\n    'PAGE_SIZE': 20,\n    'DEFAULT_FILTER_BACKENDS': [\n        'django_filters.rest_framework.DjangoFilterBackend',\n    ],\n    'DEFAULT_METADATA_CLASS': 'bothub.api.metadata.Metadata',\n}\n\n\n# cors headers\n\nCORS_ORIGIN_ALLOW_ALL = True\nCORS_URLS_REGEX = r'^/api/.*$'\n\n\n# mail\n\nenvvar_EMAIL_HOST = config('EMAIL_HOST', default=None)\n\nADMINS = config(\n    'ADMINS',\n    default='',\n    cast=lambda v: [\n        (\n            s.strip().split('|')[0],\n            s.strip().split('|')[1],\n        ) for s in v.split(',')] if v else [])\nEMAIL_SUBJECT_PREFIX = '[bothub] '\nDEFAULT_FROM_EMAIL = config(\n    'DEFAULT_FROM_EMAIL',\n    default='webmaster@localhost')\nSERVER_EMAIL = config('SERVER_EMAIL', default='root@localhost')\n\nif envvar_EMAIL_HOST:\n    EMAIL_HOST = envvar_EMAIL_HOST\n    EMAIL_PORT = config('EMAIL_PORT', default=25, cast=int)\n    EMAIL_HOST_USER = config('EMAIL_HOST_USER', default='')\n    EMAIL_HOST_PASSWORD = config('EMAIL_HOST_PASSWORD', default='')\n    EMAIL_USE_SSL = config('EMAIL_USE_SSL', default=False, cast=bool)\n    EMAIL_USE_TLS = config('EMAIL_USE_TLS', default=False, cast=bool)\nelse:\n    EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend'\n\n\n# webapp\n\nBOTHUB_WEBAPP_BASE_URL = config(\n    'BOTHUB_WEBAPP_BASE_URL',\n    default='http://localhost:8080/')\n\n\n# NLP\n\nBOTHUB_NLP_BASE_URL = config(\n    'BOTHUB_NLP_BASE_URL',\n    default='http://localhost:2657/')\n\n\n# CSRF\n\nCSRF_COOKIE_DOMAIN = config(\n    'CSRF_COOKIE_DOMAIN',\n    default=None)\n\nCSRF_COOKIE_SECURE = config(\n    'CSRF_COOKIE_SECURE',\n    default=False,\n    cast=bool)\n\n\n# Logging\n\nLOGGING = DEFAULT_LOGGING\nLOGGING['formatters']['bothub.health'] = {\n    'format': '[bothub.health] {message}',\n    'style': '{',\n}\nLOGGING['handlers']['bothub.health'] = {\n    'level': 'DEBUG',\n    'class': 'logging.StreamHandler',\n    'formatter': 'bothub.health',\n}\nLOGGING['loggers']['bothub.health.checks'] = {\n    'handlers': ['bothub.health'],\n    'level': 'DEBUG',\n}\n", "path": "bothub/settings.py"}]}