test_conf.py 文件源码

python
阅读 27 收藏 0 点赞 0 评论 0

项目:netmet 作者: godaddy 项目源码 文件源码
def test_restore_success_scenario(self, mock_open, mock_wait,
                                      mock_post, mock_gen_hmac, mock_warn):

        data = json.dumps({"refresh_conf_url": "aa"})
        mock_open.side_effect = [mock.mock_open(read_data=data).return_value,
                                 mock.mock_open(read_data=data).return_value,
                                 mock.mock_open(read_data=data).return_value]

        mock_gen_hmac.return_value = "headers"

        mock_post.side_effect = [
            requests.exceptions.RequestException,
            mock.Mock(status_code=500),
            mock.Mock(status_code=200)
        ]
        conf.restore(["hmac"], 50)
        mock_open.assert_has_calls(
            [mock.call(conf._RUNTIME_CONF_FILE % 50, "rw")] * 3)
        self.assertEqual(1, mock_warn.call_count)
        mock_post.assert_has_calls([
            mock.call("aa", headers="headers"),
            mock.call("aa", headers="headers"),
            mock.call("aa", headers="headers")
        ])
        mock_wait.assert_has_calls([mock.call(1), mock.call(1)])
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号