示例#1
0
    def test_get_config(self, mock_open, mock_environ, mock_json):
        def reset_mocks():
            for m in (mock_open, mock_environ, mock_json):
                m.reset_mock()

        config.config = None
        mock_json.load.return_value = {"foo": 42, "bar": "spam"}
        mock_environ.get.return_value = "foo_path"
        mock_open.return_value = "foo_stream"

        cfg = config.get_config()
        self.assertEqual({"foo": 42, "bar": "spam"}, cfg)
        mock_environ.get.assert_called_once_with(
            "PERFORMANCE_CONF", "/etc/oss/performance/config.json")
        mock_open.assert_called_once_with("foo_path")
        mock_json.load.assert_called_once_with("foo_stream")

        reset_mocks()
        config.config = None
        mock_open.side_effect = IOError
        cfg = config.get_config()
        self.assertEqual(
            {"flask": {
                "DEBUG": False,
                "HOST": "0.0.0.0",
                "PORT": 5010
            }}, cfg)
示例#2
0
 def test_get_config_cached(self):
     config.config = 42
     self.assertEqual(42, config.get_config())
示例#3
0
#         http://www.apache.org/licenses/LICENSE-2.0
#
#    Unless required by applicable law or agreed to in writing, software
#    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
#    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
#    License for the specific language governing permissions and limitations
#    under the License.

import flask
from flask_helpers import routing

from performance import api
from performance import config

app = flask.Flask(__name__, static_folder=None)
app.config.update(config.get_config()["flask"])

for module in [api]:
    for url_prefix, blueprint in module.get_blueprints():
        app.register_blueprint(blueprint, url_prefix="/api%s" % url_prefix)

app = routing.add_routing_map(app, html_uri=None, json_uri="/")


@app.errorhandler(404)
def not_found(error):
    return flask.jsonify({"error": "Not Found"}), 404


def main():
    app.run(host=app.config.get("HOST", "0.0.0.0"),