<commit_before><commit_msg>adds tests for new allowed-methods behavior<commit_after># -*- coding: utf-8 -*-
"""
    test
    ~~~~
    Flask-CORS is a simple extension to Flask allowing you to support cross
    origin resource sharing (CORS) using a simple decorator.

    :copyright: (c) 2014 by <NAME>.
    :license: MIT, see LICENSE for more details.
"""

from tests.base_test import FlaskCorsTestCase
from flask import Flask

try:
    # this is how you would normally import
    from flask.ext.cors import *
except:
    # support local usage without installed package
    from flask_cors import *


class MethodsCase(FlaskCorsTestCase):
    def setUp(self):
        self.app = Flask(__name__)

        @self.app.route('/defaults')
        @cross_origin()
        def defaults():
            return 'Should only return headers on OPTIONS'

        @self.app.route('/get')
        @cross_origin(methods=['GET'])
        def test_open():
            return 'Open!'

    def test_defaults(self):
        ''' By default, Access-Control-Allow-Methods should only be returned
            if the client makes an OPTIONS request.
        '''
        with self.app.test_client() as c:
            self.assertFalse(ACL_METHODS in c.get('/defaults').headers)
            self.assertFalse(ACL_METHODS in c.head('/defaults').headers)
            self.assertTrue(ACL_METHODS in c.options('/defaults').headers)

    def test_methods_defined(self):
        ''' If the methods parameter is defined, always return the allowed
            methods defined by the user.
        '''
        with self.app.test_client() as c:
            for verb in self.iter_verbs(c):
                self.assertTrue(ACL_METHODS in verb('/get').headers)
                self.assertTrue('GET' in verb('/get').headers[ACL_METHODS])


if __name__ == "__main__":
    unittest.main()
{'fraction_non_alphanumeric': 0.10694896851248643, 'fraction_numerical': 0.0027144408251900108, 'mean_word_length': 2.544230769230769, 'pattern_counts': {'":': 1, '<': 4, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2844115', 'n_tokens_mistral': 526, 'n_tokens_neox': 510, 'n_words': 157}