Skip to content

Commit

Permalink
fix test fixtures
Browse files Browse the repository at this point in the history
  • Loading branch information
DGaffney committed May 9, 2024
1 parent 5ebc101 commit 3408105
Show file tree
Hide file tree
Showing 2 changed files with 100 additions and 3 deletions.
52 changes: 50 additions & 2 deletions test/controllers/reports_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,56 @@ def from_alegre(pm)
pm5 = create_project_media team: @t, media: create_uploaded_video
create_project_media team: @t

Bot::Alegre.stubs(:request).returns({ 'result' => [from_alegre(@pm), from_alegre(pm), from_alegre(pm2), from_alegre(pm3), from_alegre(pm4), from_alegre(pm5)] })

Bot::Alegre.stubs(:get_items_with_similar_media_v2).returns({
@pm.id => {
score: 1.0,
context: {"team_id" => @pm.team_id, "project_media_id" => @pm.id, "temporary_media" => false},
model: Bot::Alegre.get_type(@pm),
source_field: Bot::Alegre.get_type(@pm),
target_field: Bot::Alegre.get_type(@pm),
relationship_type: {:source=>"confirmed_sibling", :target=>"confirmed_sibling"}
},
pm.id => {
score: 1.0,
context: {"team_id" => pm.team_id, "project_media_id" => pm.id, "temporary_media" => false},
model: Bot::Alegre.get_type(pm),
source_field: Bot::Alegre.get_type(pm),
target_field: Bot::Alegre.get_type(pm),
relationship_type: {:source=>"confirmed_sibling", :target=>"confirmed_sibling"}
},
pm2.id => {
score: 1.0,
context: {"team_id" => pm2.team_id, "project_media_id" => pm2.id, "temporary_media" => false},
model: Bot::Alegre.get_type(pm2),
source_field: Bot::Alegre.get_type(pm2),
target_field: Bot::Alegre.get_type(pm2),
relationship_type: {:source=>"confirmed_sibling", :target=>"confirmed_sibling"}
},
pm3.id => {
score: 1.0,
context: {"team_id" => pm3.team_id, "project_media_id" => pm3.id, "temporary_media" => false},
model: Bot::Alegre.get_type(pm3),
source_field: Bot::Alegre.get_type(pm3),
target_field: Bot::Alegre.get_type(pm3),
relationship_type: {:source=>"confirmed_sibling", :target=>"confirmed_sibling"}
},
pm4.id => {
score: 1.0,
context: {"team_id" => pm4.team_id, "project_media_id" => pm4.id, "temporary_media" => false},
model: Bot::Alegre.get_type(pm4),
source_field: Bot::Alegre.get_type(pm4),
target_field: Bot::Alegre.get_type(pm4),
relationship_type: {:source=>"confirmed_sibling", :target=>"confirmed_sibling"}
},
pm5.id => {
score: 1.0,
context: {"team_id" => pm5.team_id, "project_media_id" => pm5.id, "temporary_media" => false},
model: Bot::Alegre.get_type(pm5),
source_field: Bot::Alegre.get_type(pm5),
target_field: Bot::Alegre.get_type(pm5),
relationship_type: {:source=>"confirmed_sibling", :target=>"confirmed_sibling"}
},
})
post :index, params: {}
assert_response :success
assert_equal 7, json_response['data'].size
Expand Down
51 changes: 50 additions & 1 deletion test/models/bot/alegre_v2_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -816,8 +816,57 @@ def teardown
}
}
}
unconfirmed_params = {
"model_type": "image",
"data": {
"item": {
"id": "Y2hlY2stcHJvamVjdF9tZWRpYS0yMTQt",
"callback_url": "http://alegre:3100/presto/receive/add_item/image",
"url": "http://minio:9000/check-api-dev/uploads/uploaded_image/55/09572dedf610aad68090214303c14829.png",
"text": nil,
"raw": {
"doc_id": "Y2hlY2stcHJvamVjdF9tZWRpYS0yMTQt",
"context": {
"team_id": pm1.team_id,
"project_media_id": pm1.id,
"has_custom_id": true,
"temporary_media": false,
},
"url": "http://minio:9000/check-api-dev/uploads/uploaded_image/55/09572dedf610aad68090214303c14829.png",
"threshold": 0.63,
"confirmed": false,
"created_at": "2024-03-14T22:05:47.588975",
"limit": 200,
"requires_callback": true,
"final_task": "search"
},
"hash_value": "1110101010001011110100000011110010101000000010110101101010100101101111110101101001011010100001011111110101011010010000101010010110101101010110100000001010100101101010111110101000010101011100001110101010101111100001010101001011101010101011010001010101010010"
},
"results": {
"result": [
{
"id": "Y2hlY2stcHJvamVjdF9tZWRpYS0yMTQt",
"doc_id": "Y2hlY2stcHJvamVjdF9tZWRpYS0yMTQt",
"pdq": "1110101010001011110100000011110010101000000010110101101010100101101111110101101001011010100001011111110101011010010000101010010110101101010110100000001010100101101010111110101000010101011100001110101010101111100001010101001011101010101011010001010101010010",
"url": "http://minio:9000/check-api-dev/uploads/uploaded_image/55/09572dedf610aad68090214303c14829.png",
"context": [
{
"team_id": pm2.team_id,
"has_custom_id": true,
"project_media_id": pm2.id,
"temporary_media": false,
}
],
"score": 1.0,
"model": "image/pdq"
}
]
}
}
}
assert_difference 'Relationship.count' do
# Simulate the webhook hitting the server and being executed....
Bot::Alegre.process_alegre_callback(JSON.parse(unconfirmed_params.to_json))
relationship = Bot::Alegre.process_alegre_callback(JSON.parse(params.to_json)) #hack to force into stringed keys
end
assert_equal relationship.source, pm2
Expand Down Expand Up @@ -997,7 +1046,7 @@ def teardown

test "should get_cached_data with right fallbacks" do
pm1 = create_project_media team: @team, media: create_uploaded_audio
assert_equal Bot::Alegre.get_cached_data(Bot::Alegre.get_required_keys(pm1, nil)), {confirmed_results: [], suggested_or_confirmed_results: []}
assert_equal Bot::Alegre.get_cached_data(Bot::Alegre.get_required_keys(pm1, nil)), {confirmed_results: nil, suggested_or_confirmed_results: nil}
end

test "should relate project media for audio" do
Expand Down

0 comments on commit 3408105

Please sign in to comment.