# Copyright 2014 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

import alerts
import internal_alerts
import json
import random
import string
import unittest
import webtest

from google.appengine.api import memcache
from google.appengine.ext import testbed


class InternalAlertsTest(unittest.TestCase):

  def setUp(self):
    self.testbed = testbed.Testbed()
    self.testbed.activate()
    self.testbed.init_all_stubs()
    self.testapp = webtest.TestApp(internal_alerts.app)

  def tearDown(self):
    self.testbed.deactivate()

  def user_helper(self, email, uid):
    self.testbed.setup_env(
        USER_EMAIL=email,
        USER_ID=uid,
        USER_IS_ADMIN='0',
        overwrite=True)

  def check_json_headers(self, res):
    self.user_helper('tester@google.com', '123')
    self.assertEqual(res.content_type, 'application/json')
    # This is necessary for cross-site tools to retrieve internal alerts.
    self.assertEqual(res.headers['access-control-allow-origin'], '*')

  def test_get_no_data_cached(self):
    self.user_helper('tester@google.com', '123')
    res = self.testapp.get('/internal-alerts')