Beispiel #1
0
_host = _CRA_DEFAULT_HOST

# Allow the user to specify the port create-react-app is running on
if hasattr(settings, 'CRA_PORT') and type(settings.CRA_PORT) is int:
    _port = settings.CRA_PORT

# Allow the user to specify the host create-react-app is running on
if hasattr(settings, 'CRA_HOST'):
    _host = settings.CRA_HOST

# The URL the create-react-app liveserver is accessible at
CRA_URL = 'http://{}:{}'.format(_host, _port)

if hasattr(settings, 'CRA_APP_NAME'):
    CRA_APP_NAME = settings.CRA_APP_NAME
else:
    CRA_APP_NAME = 'react'

# The ability to access this file means the create-react-app liveserver is running
CRA_BUNDLE_PATH = '{}/static/js/bundle.js'.format(CRA_URL)

# Check if Create-React-App live server is up and running
CRA_LIVE = is_server_live(CRA_BUNDLE_PATH)

# The path to the CRA project directory, relative to the Django project's base directory
CRA_FS_APP_DIR = os.path.join(settings.BASE_DIR, CRA_APP_NAME)

# A list of entries in CRA's build bundle's
STATIC_ASSET_MANIFEST = generate_manifest(CRA_LIVE, CRA_BUNDLE_PATH,
                                          CRA_FS_APP_DIR)
 def test_returns_false_when_cra_not_running(self, mock_urlopen):
     mock_urlopen.side_effect = url_error.URLError('CRA not running')
     self.assertFalse(server_check.is_server_live(CRA_URL))
 def test_returns_false_when_cra_errors(self, mock_urlopen):
     mock_urlopen.return_value = MagicMock(status=500)
     self.assertFalse(server_check.is_server_live(CRA_URL))
 def test_returns_false_when_cra_running_and_production(self, mock_urlopen):
     mock_urlopen.return_value = MagicMock(status=200)
     setattr(settings, 'DEBUG', False)
     self.assertFalse(server_check.is_server_live(CRA_URL))
 def test_returns_true_when_cra_running_and_debug(self, mock_urlopen):
     mock_urlopen.return_value = MagicMock(status=200)
     self.assertTrue(server_check.is_server_live(CRA_URL))
 def test_returns_boolean(self):
     self.assertIsInstance(server_check.is_server_live(CRA_URL), bool)