@mock.patch.object(TestShortURLBaseHandler, '_MAX_GUESSES', 1)
  def testMaxGuesses(self):
    # ------------------------------
    # Try to access non-existent link (404).
    # ------------------------------
    url = self.get_url('/test/abcd12345678')
    response = self._RunAsync(self.http_client.fetch, url, method='GET')
    self.assertEqual(response.code, 404)

    # ------------------------------
    # No more guesses should be allowed (403).
    # ------------------------------
    response = self._RunAsync(self.http_client.fetch, url, method='GET')
    self.assertEqual(response.code, 403)

    # ------------------------------
    # Not even correct guesses (403).
    # ------------------------------
    response = self._RunAsync(self.http_client.fetch, self._url, method='GET')
    self.assertEqual(response.code, 403)

    # ------------------------------
    # But do allow guesses on other group ids.
    # ------------------------------
    url = self.get_url('/test/another12345678')
    response = self._RunAsync(self.http_client.fetch, url, method='GET')
    self.assertEqual(response.code, 404)

    # ------------------------------
    # Now "wait" 24 hours and make sure another guess is allowed.
    # ------------------------------
    util._TEST_TIME += constants.SECONDS_PER_DAY
    response = self._RunAsync(self.http_client.fetch, url, method='GET')
    self.assertEqual(response.code, 404)
Test enforcement of max guesses for a particular group id.
dataset/ETHPy150Open viewfinderco/viewfinder/backend/www/test/short_url_test.py/ShortURLTestCase.testMaxGuesses