Skip to content

Commit

Permalink
CMR-9848: Fixed some tests
Browse files Browse the repository at this point in the history
  • Loading branch information
siwei xu authored and siwei xu committed Sep 16, 2024
1 parent 64ee76f commit 61eb516
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 15 deletions.
5 changes: 5 additions & 0 deletions system-int-test/src/cmr/system_int_test/utils/tool_util.clj
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,11 @@
(is (= (set (map :concept-id expected-colls))
(set colls)))))

(defn assert-tool-dissociation-response-ok?
"Assert the tool association response when status code is 200 is correct."
[coll-tool-associations response]
(assert-tool-association-response-ok? coll-tool-associations response false))

(defn assert-tool-dissociation-bad-request
"Assert the tool association response when status code is 400 is correct."
[coll-tool-associations response]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,10 @@
:revision-id coll2-revision-id}])
tla2-concept-id (some #(when (:tool-association %) (get-in % [:tool-association :concept-id]))
(:body assoc-response2))]
(is (= {:status 400, :body [{:errors [(str "User doesn't have update permission on INGEST_MANAGEMENT_ACL for provider of collection [" coll1-concept-id "] to make the association.")], :associated-item {:concept-id coll1-concept-id}} {:tool-association {:concept-id tla1-concept-id, :revision-id 1}, :associated-item {:concept-id coll2-concept-id, :revision-id coll2-revision-id}}]}
(is (= {:status 200, :body [{:errors [(str "User doesn't have update permission on INGEST_MANAGEMENT_ACL for provider of collection [" coll1-concept-id "] to make the association.")], :associated-item {:concept-id coll1-concept-id}} {:tool-association {:concept-id tla1-concept-id, :revision-id 1}, :associated-item {:concept-id coll2-concept-id, :revision-id coll2-revision-id}}]}
assoc-response1))

(is (= {:status 400, :body [{:errors [(str "User doesn't have update permission on INGEST_MANAGEMENT_ACL for provider of collection [" coll1-concept-id "] to make the association.")], :associated-item {:concept-id coll1-concept-id}} {:tool-association {:concept-id tla2-concept-id, :revision-id 1}, :associated-item {:concept-id coll2-concept-id, :revision-id coll2-revision-id}}]}
(is (= {:status 200, :body [{:errors [(str "User doesn't have update permission on INGEST_MANAGEMENT_ACL for provider of collection [" coll1-concept-id "] to make the association.")], :associated-item {:concept-id coll1-concept-id}} {:tool-association {:concept-id tla2-concept-id, :revision-id 1}, :associated-item {:concept-id coll2-concept-id, :revision-id coll2-revision-id}}]}
assoc-response2))))

(testing "dissociation-permission-test"
Expand Down Expand Up @@ -118,7 +118,7 @@
[{:concept-id coll1-concept-id}
{:concept-id coll2-concept-id
:revision-id coll2-revision-id}])]
(is (= {:status 400, :body [{:errors [(str "User doesn't have update permission on INGEST_MANAGEMENT_ACL for provider of collection [" coll1-concept-id "] or provider of service/tool to delete the association.")], :associated-item {:concept-id coll1-concept-id}} {:tool-association {:concept-id (last tla1-concept-ids), :revision-id 3}, :associated-item {:concept-id coll2-concept-id, :revision-id 1}}]}
(is (= {:status 200, :body [{:errors [(str "User doesn't have update permission on INGEST_MANAGEMENT_ACL for provider of collection [" coll1-concept-id "] or provider of service/tool to delete the association.")], :associated-item {:concept-id coll1-concept-id}} {:tool-association {:concept-id (last tla1-concept-ids), :revision-id 3}, :associated-item {:concept-id coll2-concept-id, :revision-id 1}}]}
dissoc-response1))

(is (= {:status 200, :body [{:tool-association {:concept-id (first tla2-concept-ids), :revision-id 2}, :associated-item {:concept-id coll1-concept-id}} {:tool-association {:concept-id (last tla2-concept-ids), :revision-id 3}, :associated-item {:concept-id coll2-concept-id, :revision-id 1}}]}
Expand All @@ -143,14 +143,14 @@
:revision-id coll2-revision-id}])
sa2-concept-id (some #(when (:service-association %) (get-in % [:service-association :concept-id]))
(:body assoc-response2))]
(is (= {:status 400
(is (= {:status 200
:body [{:errors [(str "User doesn't have update permission on INGEST_MANAGEMENT_ACL for provider of collection [" coll1-concept-id "] to make the association.")]
:associated-item {:concept-id coll1-concept-id}}
{:service-association {:concept-id sa1-concept-id, :revision-id 1}
:associated-item {:concept-id coll2-concept-id, :revision-id coll2-revision-id}}]}
assoc-response1))

(is (= {:status 400
(is (= {:status 200
:body [{:errors [(str "User doesn't have update permission on INGEST_MANAGEMENT_ACL for provider of collection [" coll1-concept-id "] to make the association.")]
:associated-item {:concept-id coll1-concept-id}}
{:service-association {:concept-id sa2-concept-id, :revision-id 1}
Expand Down Expand Up @@ -191,7 +191,7 @@
[{:concept-id coll1-concept-id}
{:concept-id coll2-concept-id
:revision-id coll2-revision-id}])]
(is (= {:status 400
(is (= {:status 200
:body [{:errors [(str "User doesn't have update permission on INGEST_MANAGEMENT_ACL for provider of collection [" coll1-concept-id "] or provider of service/tool to delete the association.")]
:associated-item {:concept-id coll1-concept-id}}
{:service-association {:concept-id (last sa1-concept-ids), :revision-id 3}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@
(let [response (association-util/associate-by-concept-ids
token concept-id [{:concept-id c2-p1}
{:concept-id "C100-P5"}])]
(service-util/assert-service-association-bad-request
(service-util/assert-service-association-response-ok?
{[c2-p1] {:concept-id "SA1200000028-CMR"
:revision-id 1}
["C100-P5"] {:errors ["User doesn't have update permission on INGEST_MANAGEMENT_ACL for provider of collection [C100-P5] to make the association."]}}
Expand Down Expand Up @@ -302,7 +302,7 @@
{:concept-id (:concept-id coll2) :revision-id 1} ;; success
{:concept-id (:concept-id coll3)}])] ;; no service association

(service-util/assert-service-dissociation-bad-request
(service-util/assert-service-dissociation-response-ok?
{["C100-P5"] {:errors ["Collection [C100-P5] does not exist or is not visible."]}
["C1200000012-PROV1"] {:concept-id "SA1200000016-CMR" :revision-id 2}
["C1200000013-PROV1" 1] {:concept-id "SA1200000017-CMR" :revision-id 2}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,8 @@
_ (tags/create-tag token tag1)
_ (tags/create-tag token tag2)]
(testing "associate by query works before disable"
(let [response (tags/associate-by-query token tag1-key {:provider "PROV1"})]
(let [response (tags/associate-by-query token tag1-key {:provider "PROV1"})
_ (println "response: " response)]
(is (= 200 (:status response)))))

(testing "associate tag to collection works before disable"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@
token tag-key
[{:concept-id concept-id :revision-id 5}
{:concept-id concept-id :revision-id revision-id}])]
(tags/assert-tag-association-response-error?
(tags/assert-tag-association-response-ok?
{[concept-id 5]
{:errors [(format "Collection with concept id [%s] revision id [5] does not exist or is not visible."
concept-id)]}
Expand Down Expand Up @@ -290,7 +290,7 @@
token tag-key
[{:concept-id concept-id :revision-id 5}
{:concept-id concept-id :revision-id revision-id}])]
(tags/assert-tag-dissociation-response-error?
(tags/assert-tag-dissociation-response-ok?
{[concept-id 5]
{:errors [(format "Collection with concept id [%s] revision id [5] does not exist or is not visible."
concept-id)]}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@
(let [response (tags/associate-by-concept-ids
token tag-key [{:concept-id c2-p1}
{:concept-id "C100-P5"}])]
(tags/assert-tag-association-response-error?
(tags/assert-tag-association-response-ok?
{["C1200000014-PROV1"] {:concept-id "TA1200000028-CMR"
:revision-id 1}
["C100-P5"] {:errors ["Collection [C100-P5] does not exist or is not visible."]}}
Expand Down Expand Up @@ -451,7 +451,7 @@
{:concept-id (:concept-id coll1)} ;; success
{:concept-id (:concept-id coll2) :revision-id 1} ;; success
{:concept-id (:concept-id coll3)}])] ;; no tag association
(tags/assert-tag-dissociation-response-error?
(tags/assert-tag-dissociation-response-ok?
{["C100-P5"] {:errors ["Collection [C100-P5] does not exist or is not visible."]}
["C1200000012-PROV1"] {:concept-id "TA1200000016-CMR" :revision-id 2}
["C1200000013-PROV1" 1] {:concept-id "TA1200000017-CMR" :revision-id 2}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@
(let [response (association-util/associate-by-concept-ids
token concept-id [{:concept-id c2-p1}
{:concept-id "C100-P5"}])]
(tool-util/assert-tool-association-bad-request
(tool-util/assert-tool-association-response-ok?
{[c2-p1] {:concept-id "TLA1200000028-CMR"
:revision-id 1}
["C100-P5"] {:errors ["User doesn't have update permission on INGEST_MANAGEMENT_ACL for provider of collection [C100-P5] to make the association."]}}
Expand Down Expand Up @@ -301,7 +301,7 @@
{:concept-id (:concept-id coll2) :revision-id 1} ;; success
{:concept-id (:concept-id coll3)}])] ;; no tool association

(tool-util/assert-tool-dissociation-bad-request
(tool-util/assert-tool-dissociation-response-ok?
{["C100-P5"] {:errors ["Collection [C100-P5] does not exist or is not visible."]}
["C1200000012-PROV1"] {:concept-id "TLA1200000016-CMR" :revision-id 2}
["C1200000013-PROV1" 1] {:concept-id "TLA1200000017-CMR" :revision-id 2}
Expand Down

0 comments on commit 61eb516

Please sign in to comment.