我在处理Mock.call_args_list返回的嵌套元组时遇到了一些麻烦.
def test_foo(self):
def foo(fn):
fn('PASS and some other stuff')
f = Mock()
foo(f)
foo(f)
foo(f)
for call in f.call_args_list:
for args in call:
for arg in args:
self.assertTrue(arg.startswith('PASS'))
Run Code Online (Sandbox Code Playgroud)
我想知道是否有更好的方法来解压缩模拟对象上的call_args_list以便进行断言.这个循环有效,但感觉必须有一个更直接的方式.
我一直在努力弄清楚如何从我的EC2实例与Amazon ES服务进行通信.
文档明确指出Amazon ES服务支持基于IAM用户和角色的访问策略.http://docs.aws.amazon.com/elasticsearch-service/latest/developerguide/es-createupdatedomains.html#es-createdomain-configure-access-policies
但是,当我的ES域具有此访问策略时:
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "",
"Effect": "Allow",
"Principal": {
"AWS": "arn:aws:iam::123456789:role/my-ec2-role"
},
"Action": "es:*",
"Resource": "arn:aws:es:us-west-2:123456789:domain/myDomain/*"
}
]
}
Run Code Online (Sandbox Code Playgroud)
我无法登录ec2实例并运行curl来访问我的elasticsearch集群.
尝试对_search API进行简单的卷曲:
curl "http://search-myDomain.es.amazonaws.com/_search"
Run Code Online (Sandbox Code Playgroud)
生成身份验证错误响应:
{"Message":"User: anonymous is not authorized to perform: es:ESHttpGet on resource: arn:aws:es:us-west-2:123456789:domain/myDomain/_search"}
Run Code Online (Sandbox Code Playgroud)
为了更安全,我把AmazonESFullAccess政策放在我的IAM角色上,仍然无效.
我必须遗漏一些东西,因为能够以编程方式从使用IAM角色的ec2实例与Elasticsearch进行交互,这对于使用Amazon ES服务完成任何事情至关重要.
我也在文档中看到了这个矛盾的陈述.
基于IAM的策略示例您可以使用AWS IAM控制台而不是Amazon ES控制台创建基于IAM的访问策略.有关创建基于IAM的访问策略的信息,请参阅IAM文档.
IAM文档的链接是IAM的主页,其中包含有关如何执行此操作的零信息.有人为我找到了解决方案吗?
您认为使用lodash实用程序编写函数以便检查数组是否存在重复值时,您认为最好(最好可以解释为最可读或最高效,您的选择)的方法.
我想输入['foo', 'foo', 'bar']并返回函数true.并输入['foo', 'bar', 'baz']并具有返回功能false.
我只是想检查的对象是Map或Set,而不是一个Array.
检查我正在使用lodash的数组_.isArray.
function myFunc(arg) {
if (_.isArray(arg)) {
// doSomethingWithArray(arg)
}
if (isMap(arg)) {
// doSomethingWithMap(arg)
}
if (isSet(arg)) {
// doSomethingWithSet(arg)
}
}
Run Code Online (Sandbox Code Playgroud)
如果我要实现isMap/ isSet,它需要看起来像什么?我希望它能够捕获Map/的子类,Set如果可能的话.
我有一个问题,这很难被注意到,因为大多数情况下一切都有效.只有当我试图在我的集合初始化函数中操作我的数据时才发现问题.
骨干文档位于http://backbonejs.org/#Collection-constructor
"如果你定义了一个初始化函数,它将在创建集合时被调用."
所以我解释为,我的初始化函数直到我的模型设置后才会运行."这听起来很理想,"我说,但后来我遇到了这个.
我的引导代码如下:
new MyCollection(<?php if ($data) {echo json_encode($data);} ?>);
Run Code Online (Sandbox Code Playgroud)
我的收藏:
var MyCollection = Backbone.Collection.extend({
model: MyModel,
initialize: function() {
console.log(this);
console.log(this.length);
this.each(function(model) {
console.log(model);
});
}
});
Run Code Online (Sandbox Code Playgroud)
我得到了奇怪的结果.
第一个console.log(this);是预期的集合对象:
{
....
models: [3],
length: 3
....
}
Run Code Online (Sandbox Code Playgroud)
第二个console(this.length);打印出来的号码0
里面的控制台this.each()没有显示出来.
发生了什么?
我正在使用 python日志记录模块以及python-json-logger,我想添加一些键:
{
"app_name": "myapp",
"env": "prod"
}
Run Code Online (Sandbox Code Playgroud)
自动查看我的所有日志,无需执行以下操作。
{
"app_name": "myapp",
"env": "prod"
}
Run Code Online (Sandbox Code Playgroud)
但要让它像我一样工作。:)
我没有找到有关如何显式设置vagrant环境变量的任何信息.
我正在尝试按照这些文档中的描述进行设置VAGRANT_DEFAULT_PROVIDER,vmware_fusion因此我并不总是必须使用vagrant up --provider=vmware_fusion.
我把这行放在我的Vagrantfile中.
VAGRANT_DEFAULT_PROVIDER = "vmware_fusion"
它不起作用,我认为这必然意味着我不知道我在做什么,而且必须做错了.当我运行vagrant up它仍然使用默认的虚拟框提供程序.
我已经阅读了一些关于此错误的 stackoverflow,但我仍然不明白。
-- Returns full JSON document of a user, and all their user_files.
with user_files_json as (
select user_id,
json_agg(
json_build_object(
'user_file_id', user_file_id,
's3_key', s3_key,
'settings', series_settings
)
) as user_files
from user_files
where user_id = :user_id
group by user_id
order by user_file_id asc
)
select json_build_object(
'user_id', user_id,
'user_name', user_name,
'job_type_name', job_type_name,
'user_files', user_files
)
from user_files_json
join users using(user_id)
join job_type using(job_type_id);
Run Code Online (Sandbox Code Playgroud)
我希望文件按其 user_file_id 顺序列出。就这样。如果我取出order by工作,但文件以错误的顺序出现。
但我收到一条错误消息:
column "user_files.user_file_id" must appear in the GROUP BY …Run Code Online (Sandbox Code Playgroud) javascript ×3
python ×2
backbone.js ×1
collections ×1
dictionary ×1
ecmascript-6 ×1
lodash ×1
postgresql ×1
puppet ×1
python-3.x ×1
set ×1
unit-testing ×1
vagrant ×1