def clear_varnish_cache(env, username, password):
    """
    Clears the Varnish cache from a Drupal domain.

    Args:
        env (str): The environment to clear varnish caches in (e.g. test or prod)
        username (str): The Acquia username necessary to run the command.
        password (str): The Acquia password necessary to run the command.
    """
    drupal.clear_varnish_cache(env, username, password)
Beispiel #2
0
def clear_varnish_cache(app_id, env, client_id, secret):
    """
    Clears the Varnish cache from a Drupal domain.

    Args:
        app_id (str): The application id for drupal instance.
        env (str): The environment to clear varnish caches in (e.g. test or prod)
        client_id (str): The Acquia api client id necessary to run the command.
        secret (str): The Acquia api secret key to run the command.
    """
    drupal.clear_varnish_cache(app_id, env, client_id, secret)
Beispiel #3
0
 def test_clear_varnish_cache_failure(self, mock):
     """
     Tests clear_varnish_cache raises BackendError when status != 200
     """
     for domain in ACQUIA_DOMAINS:
         mock.delete(drupal.CLEAR_CACHE_URL.format(env=ACQUIA_ENV,
                                                   domain=domain),
                     json={},
                     status_code=401)
     with self.assertRaises(BackendError):
         drupal.clear_varnish_cache(env=ACQUIA_ENV,
                                    username=TEST_USERNAME,
                                    password=TEST_PASSWORD)
Beispiel #4
0
 def test_clear_varnish_cache_failure(self):
     """
     Tests clear_varnish_cache raises BackendError when status != 200
     """
     for domain in ACQUIA_DOMAINS:
         httpretty.register_uri(
             httpretty.DELETE,
             drupal.CLEAR_CACHE_URL.format(env=ACQUIA_ENV, domain=domain),
             body="{}",
             content_type="application/json",
             status=401,
         )
     with self.assertRaises(BackendError):
         drupal.clear_varnish_cache(env=ACQUIA_ENV, username=TEST_USERNAME, password=TEST_PASSWORD)
Beispiel #5
0
    def test_clear_varnish_cache_success(self, mock_env_id, mock_token,
                                         mock_post_request, mock_get_request):
        """
        Tests clear_varnish_cache returns True when there is a valid response.
        """
        mock_env_id.return_value = ACQUIA_ENV_ID
        mock_token.return_value = TEST_TOKEN
        mock_post_request.return_value = Mock()
        mock_post_request.return_value.status_code = 202
        mock_post_request.return_value.json.return_value = {
            '_links': {
                'notification': {
                    'href': TEST_NOTIFICATION_URL
                }
            }
        }
        mock_get_request.return_value = Mock()
        mock_get_request.return_value.status_code = 200
        mock_get_request.return_value.json.return_value = {
            'status': 'completed'
        }

        self.assertTrue(
            drupal.clear_varnish_cache(app_id=ACQUIA_APP_ID,
                                       env=ACQUIA_ENV,
                                       client_id=TEST_CLIENT_ID,
                                       secret=TEST_SECRET))
Beispiel #6
0
    def test_clear_varnish_cache_failure(self, mock_env_id, mock_token,
                                         mock_post_request):
        """
        Tests clear_varnish_cache raises BackendError when status != 200
        """

        mock_env_id.return_value = ACQUIA_ENV_ID
        mock_token.return_value = TEST_TOKEN
        mock_post_request.return_value = Mock()
        mock_post_request.return_value.status_code = 403

        with self.assertRaises(BackendError):
            drupal.clear_varnish_cache(app_id=ACQUIA_APP_ID,
                                       env=ACQUIA_ENV,
                                       client_id=TEST_CLIENT_ID,
                                       secret=TEST_SECRET)
Beispiel #7
0
 def test_clear_varnish_cache_success(self, mock):
     """
     Tests clear_varnish_cache returns True when there is a valid response.
     """
     for domain in ACQUIA_DOMAINS:
         mock.delete(
             drupal.CLEAR_CACHE_URL.format(env=ACQUIA_ENV, domain=domain),
             json=CLEAR_CACHE_RESPONSE_WAITING,
         )
     mock.get(drupal.CHECK_TASKS_URL.format(id="1"),
              json=CLEAR_CACHE_RESPONSE_DONE)
     self.assertTrue(
         drupal.clear_varnish_cache(env=ACQUIA_ENV,
                                    username=TEST_USERNAME,
                                    password=TEST_PASSWORD))
Beispiel #8
0
 def test_clear_varnish_cache_success(self):
     """
     Tests clear_varnish_cache returns True when there is a valid response.
     """
     for domain in ACQUIA_DOMAINS:
         httpretty.register_uri(
             httpretty.DELETE,
             drupal.CLEAR_CACHE_URL.format(env=ACQUIA_ENV, domain=domain),
             body=CLEAR_CACHE_RESPONSE_WAITING,
             content_type="application/json",
         )
     httpretty.register_uri(
         httpretty.GET,
         drupal.CHECK_TASKS_URL.format(id="1"),
         body=CLEAR_CACHE_RESPONSE_DONE,
         content_type="application/json",
     )
     self.assertTrue(drupal.clear_varnish_cache(env=ACQUIA_ENV, username=TEST_USERNAME, password=TEST_PASSWORD))