More test suite cleanup
This commit is contained in:
parent
ef2af245e7
commit
971b2e230c
2 changed files with 104 additions and 104 deletions
|
|
@ -4,8 +4,8 @@
|
|||
(:import [com.mongodb WriteResult WriteConcern DBCursor DBObject CommandResult$CommandFailure MapReduceOutput MapReduceCommand MapReduceCommand$OutputType]
|
||||
org.bson.types.ObjectId
|
||||
java.util.Date)
|
||||
(:require [monger core util]
|
||||
[monger.collection :as mgcol]
|
||||
(:require [monger.core :as mg]
|
||||
[monger.collection :as mc]
|
||||
[monger.result :as mgres]
|
||||
[monger.test.helper :as helper])
|
||||
(:use clojure.test
|
||||
|
|
@ -23,49 +23,49 @@
|
|||
|
||||
(deftest get-collection-size
|
||||
(let [collection "things"]
|
||||
(is (= 0 (mgcol/count collection)))
|
||||
(mgcol/insert-batch collection [{ :language "Clojure", :name "langohr" }
|
||||
{ :language "Clojure", :name "monger" }
|
||||
{ :language "Clojure", :name "incanter" }
|
||||
{ :language "Scala", :name "akka" }] )
|
||||
(is (= 4 (mgcol/count collection)))
|
||||
(is (mgcol/any? collection))
|
||||
(is (= 3 (mgcol/count monger.core/*mongodb-database* collection { :language "Clojure" })))
|
||||
(is (mgcol/any? monger.core/*mongodb-database* collection { :language "Clojure" }))
|
||||
(is (= 1 (mgcol/count collection { :language "Scala" })))
|
||||
(is (mgcol/any? collection { :language "Scala" }))
|
||||
(is (= 0 (mgcol/count monger.core/*mongodb-database* collection { :language "Python" })))
|
||||
(is (not (mgcol/any? monger.core/*mongodb-database* collection { :language "Python" })))))
|
||||
(is (= 0 (mc/count collection)))
|
||||
(mc/insert-batch collection [{:language "Clojure" :name "langohr"}
|
||||
{:language "Clojure" :name "monger"}
|
||||
{:language "Clojure" :name "incanter"}
|
||||
{:language "Scala" :name "akka"}])
|
||||
(is (= 4 (mc/count collection)))
|
||||
(is (mc/any? collection))
|
||||
(is (= 3 (mc/count mg/*mongodb-database* collection {:language "Clojure"})))
|
||||
(is (mc/any? mg/*mongodb-database* collection {:language "Clojure"}))
|
||||
(is (= 1 (mc/count collection {:language "Scala" })))
|
||||
(is (mc/any? collection {:language "Scala"}))
|
||||
(is (= 0 (mc/count mg/*mongodb-database* collection {:language "Python" })))
|
||||
(is (not (mc/any? mg/*mongodb-database* collection {:language "Python"})))))
|
||||
|
||||
|
||||
(deftest remove-all-documents-from-collection
|
||||
(let [collection "libraries"]
|
||||
(mgcol/insert-batch collection [{ :language "Clojure", :name "monger" }
|
||||
{ :language "Clojure", :name "langohr" }
|
||||
{ :language "Clojure", :name "incanter" }
|
||||
{ :language "Scala", :name "akka" }])
|
||||
(is (= 4 (mgcol/count collection)))
|
||||
(mgcol/remove collection)
|
||||
(is (= 0 (mgcol/count collection)))))
|
||||
(mc/insert-batch collection [{:language "Clojure" :name "monger"}
|
||||
{:language "Clojure" :name "langohr"}
|
||||
{:language "Clojure" :name "incanter"}
|
||||
{:language "Scala" :name "akka"}])
|
||||
(is (= 4 (mc/count collection)))
|
||||
(mc/remove collection)
|
||||
(is (= 0 (mc/count collection)))))
|
||||
|
||||
|
||||
(deftest remove-some-documents-from-collection
|
||||
(let [collection "libraries"]
|
||||
(mgcol/insert-batch collection [{ :language "Clojure", :name "monger" }
|
||||
{ :language "Clojure", :name "langohr" }
|
||||
{ :language "Clojure", :name "incanter" }
|
||||
{ :language "Scala", :name "akka" }])
|
||||
(is (= 4 (mgcol/count collection)))
|
||||
(mgcol/remove collection { :language "Clojure" })
|
||||
(is (= 1 (mgcol/count collection)))))
|
||||
(mc/insert-batch collection [{:language "Clojure" :name "monger"}
|
||||
{:language "Clojure" :name "langohr"}
|
||||
{:language "Clojure" :name "incanter"}
|
||||
{:language "Scala" :name "akka"}])
|
||||
(is (= 4 (mc/count collection)))
|
||||
(mc/remove collection {:language "Clojure"})
|
||||
(is (= 1 (mc/count collection)))))
|
||||
|
||||
(deftest remove-a-single-document-from-collection
|
||||
(let [collection "libraries"
|
||||
oid (ObjectId.)]
|
||||
(mgcol/insert-batch collection [{ :language "Clojure" :name "monger" :_id oid }])
|
||||
(mgcol/remove-by-id collection oid)
|
||||
(is (= 0 (mgcol/count collection)))
|
||||
(is (nil? (mgcol/find-by-id collection oid)))))
|
||||
(mc/insert-batch collection [{:language "Clojure" :name "monger" :_id oid}])
|
||||
(mc/remove-by-id collection oid)
|
||||
(is (= 0 (mc/count collection)))
|
||||
(is (nil? (mc/find-by-id collection oid)))))
|
||||
|
||||
|
||||
;;
|
||||
|
|
@ -74,23 +74,23 @@
|
|||
|
||||
(deftest checking-for-collection-existence-when-it-does-not-exist
|
||||
(let [collection "widgets"]
|
||||
(mgcol/drop collection)
|
||||
(is (false? (mgcol/exists? collection)))))
|
||||
(mc/drop collection)
|
||||
(is (false? (mc/exists? collection)))))
|
||||
|
||||
(deftest checking-for-collection-existence-when-it-does-exist
|
||||
(let [collection "widgets"]
|
||||
(mgcol/drop collection)
|
||||
(mgcol/insert-batch collection [{ :name "widget1" }
|
||||
(mc/drop collection)
|
||||
(mc/insert-batch collection [{:name "widget1"}
|
||||
{:name "widget2"}])
|
||||
(is (mgcol/exists? collection))
|
||||
(mgcol/drop collection)
|
||||
(is (false? (mgcol/exists? collection)))
|
||||
(mgcol/create "widgets" { :capped true :size 100000 :max 10 })
|
||||
(is (mgcol/exists? collection))
|
||||
(mgcol/rename collection "gadgets")
|
||||
(is (not (mgcol/exists? collection)))
|
||||
(is (mgcol/exists? "gadgets"))
|
||||
(mgcol/drop "gadgets")))
|
||||
(is (mc/exists? collection))
|
||||
(mc/drop collection)
|
||||
(is (false? (mc/exists? collection)))
|
||||
(mc/create "widgets" {:capped true :size 100000 :max 10})
|
||||
(is (mc/exists? collection))
|
||||
(mc/rename collection "gadgets")
|
||||
(is (not (mc/exists? collection)))
|
||||
(is (mc/exists? "gadgets"))
|
||||
(mc/drop "gadgets")))
|
||||
|
||||
;;
|
||||
;; any?, empty?
|
||||
|
|
@ -98,23 +98,23 @@
|
|||
|
||||
(deftest test-any-on-empty-collection
|
||||
(let [collection "things"]
|
||||
(is (not (mgcol/any? collection)))))
|
||||
(is (not (mc/any? collection)))))
|
||||
|
||||
(deftest test-any-on-non-empty-collection
|
||||
(let [collection "things"
|
||||
_ (mgcol/insert collection { :language "Clojure", :name "langohr" })]
|
||||
(is (mgcol/any? "things"))
|
||||
(is (mgcol/any? monger.core/*mongodb-database* "things" {:language "Clojure"}))))
|
||||
_ (mc/insert collection {:language "Clojure" :name "langohr"})]
|
||||
(is (mc/any? "things"))
|
||||
(is (mc/any? mg/*mongodb-database* "things" {:language "Clojure"}))))
|
||||
|
||||
(deftest test-empty-on-empty-collection
|
||||
(let [collection "things"]
|
||||
(is (mgcol/empty? collection))
|
||||
(is (mgcol/empty? monger.core/*mongodb-database* collection))))
|
||||
(is (mc/empty? collection))
|
||||
(is (mc/empty? mg/*mongodb-database* collection))))
|
||||
|
||||
(deftest test-empty-on-non-empty-collection
|
||||
(let [collection "things"
|
||||
_ (mgcol/insert collection { :language "Clojure", :name "langohr" })]
|
||||
(is (not (mgcol/empty? "things")))))
|
||||
_ (mc/insert collection {:language "Clojure" :name "langohr"})]
|
||||
(is (not (mc/empty? "things")))))
|
||||
|
||||
|
||||
;;
|
||||
|
|
@ -129,6 +129,6 @@
|
|||
{:state "IL" :quantity 2 :price 11.50 }
|
||||
{:state "CA" :quantity 2 :price 2.95 }
|
||||
{:state "IL" :quantity 3 :price 5.50 }]]
|
||||
(mgcol/insert-batch collection batch)
|
||||
(is (= ["CA" "IL" "NY"] (sort (mgcol/distinct monger.core/*mongodb-database* collection :state {}))))
|
||||
(is (= ["CA" "NY"] (sort (mgcol/distinct collection :state { :price { $gt 100.00 } }))))))
|
||||
(mc/insert-batch collection batch)
|
||||
(is (= ["CA" "IL" "NY"] (sort (mc/distinct mg/*mongodb-database* collection :state {}))))
|
||||
(is (= ["CA" "NY"] (sort (mc/distinct collection :state {:price {$gt 100.00}}))))))
|
||||
|
|
|
|||
|
|
@ -4,13 +4,13 @@
|
|||
(:import [com.mongodb WriteResult WriteConcern DBCursor DBObject]
|
||||
org.bson.types.ObjectId
|
||||
java.util.Date)
|
||||
(:require [monger core util]
|
||||
[monger.collection :as mgcol]
|
||||
[monger.result :as mgres]
|
||||
[monger.conversion :as mgcnv]
|
||||
(:require [monger.core :as mg]
|
||||
[monger.util :as mu]
|
||||
[monger.collection :as mc]
|
||||
[monger.test.helper :as helper])
|
||||
(:use clojure.test
|
||||
monger.operators
|
||||
monger.conversion
|
||||
monger.test.fixtures))
|
||||
|
||||
(helper/connect!)
|
||||
|
|
@ -24,58 +24,58 @@
|
|||
|
||||
(deftest insert-a-basic-document-without-id-and-with-default-write-concern
|
||||
(let [collection "people"
|
||||
doc { :name "Joe", :age 30 }]
|
||||
(is (monger.result/ok? (mgcol/insert "people" doc)))
|
||||
(is (= 1 (mgcol/count collection)))))
|
||||
doc {:name "Joe" :age 30}]
|
||||
(is (monger.result/ok? (mc/insert "people" doc)))
|
||||
(is (= 1 (mc/count collection)))))
|
||||
|
||||
(deftest insert-a-basic-document-with-explicitly-passed-database-without-id-and-with-default-write-concern
|
||||
(let [collection "people"
|
||||
doc { :name "Joe", :age 30 }]
|
||||
doc {:name "Joe" :age 30}]
|
||||
(dotimes [n 5]
|
||||
(is (monger.result/ok? (mgcol/insert monger.core/*mongodb-database* "people" doc WriteConcern/SAFE))))
|
||||
(is (= 5 (mgcol/count collection)))))
|
||||
(is (monger.result/ok? (mc/insert monger.core/*mongodb-database* "people" doc WriteConcern/SAFE))))
|
||||
(is (= 5 (mc/count collection)))))
|
||||
|
||||
(deftest insert-a-basic-document-without-id-and-with-explicit-write-concern
|
||||
(let [collection "people"
|
||||
doc { :name "Joe", :age 30 }]
|
||||
(is (monger.result/ok? (mgcol/insert "people" doc WriteConcern/SAFE)))
|
||||
(is (= 1 (mgcol/count collection)))))
|
||||
doc {:name "Joe" :age 30}]
|
||||
(is (monger.result/ok? (mc/insert "people" doc WriteConcern/SAFE)))
|
||||
(is (= 1 (mc/count collection)))))
|
||||
|
||||
(deftest insert-a-basic-db-object-without-id-and-with-default-write-concern
|
||||
(let [collection "people"
|
||||
doc (mgcnv/to-db-object { :name "Joe", :age 30 })]
|
||||
doc (to-db-object {:name "Joe" :age 30})]
|
||||
(is (nil? (.get ^DBObject doc "_id")))
|
||||
(mgcol/insert "people" doc)
|
||||
(mc/insert "people" doc)
|
||||
(is (not (nil? (monger.util/get-id doc))))))
|
||||
|
||||
(deftest insert-a-map-with-id-and-with-default-write-concern
|
||||
(let [collection "people"
|
||||
id (ObjectId.)
|
||||
doc { :name "Joe", :age 30 "_id" id }
|
||||
result (mgcol/insert "people" doc)]
|
||||
doc {:name "Joe" :age 30 "_id" id}
|
||||
result (mc/insert "people" doc)]
|
||||
(is (= id (monger.util/get-id doc)))))
|
||||
|
||||
(deftest insert-a-document-with-clojure-ratio-in-it
|
||||
(let [collection "widgets"
|
||||
id (ObjectId.)
|
||||
doc {:ratio 11/2 "_id" id}
|
||||
result (mgcol/insert "widgets" doc)]
|
||||
(is (= 5.5 (:ratio (mgcol/find-map-by-id collection id))))))
|
||||
result (mc/insert "widgets" doc)]
|
||||
(is (= 5.5 (:ratio (mc/find-map-by-id collection id))))))
|
||||
|
||||
(deftest insert-a-document-with-clojure-keyword-in-it
|
||||
(let [collection "widgets"
|
||||
id (ObjectId.)
|
||||
doc {:keyword :kwd "_id" id}
|
||||
result (mgcol/insert "widgets" doc)]
|
||||
(is (= (name :kwd) (:keyword (mgcol/find-map-by-id collection id))))))
|
||||
result (mc/insert "widgets" doc)]
|
||||
(is (= (name :kwd) (:keyword (mc/find-map-by-id collection id))))))
|
||||
|
||||
(deftest insert-a-document-with-clojure-keyword-in-a-set-in-it
|
||||
(let [collection "widgets"
|
||||
id (ObjectId.)
|
||||
doc {:keyword1 {:keyword2 #{:kw1 :kw2}} "_id" id}
|
||||
result (mgcol/insert "widgets" doc)]
|
||||
result (mc/insert "widgets" doc)]
|
||||
(is (= (sort ["kw1" "kw2"])
|
||||
(sort (get-in (mgcol/find-map-by-id collection id) [:keyword1 :keyword2]))))))
|
||||
(sort (get-in (mc/find-map-by-id collection id) [:keyword1 :keyword2]))))))
|
||||
|
||||
|
||||
(defrecord Metrics
|
||||
|
|
@ -85,8 +85,8 @@
|
|||
(let [collection "widgets"
|
||||
id (ObjectId.)
|
||||
doc {:record (Metrics. 10 20) "_id" id}
|
||||
result (mgcol/insert "widgets" doc)]
|
||||
(is (= {:rps 10 :eps 20} (:record (mgcol/find-map-by-id collection id))))))
|
||||
result (mc/insert "widgets" doc)]
|
||||
(is (= {:rps 10 :eps 20} (:record (mc/find-map-by-id collection id))))))
|
||||
|
||||
|
||||
|
||||
|
|
@ -96,19 +96,19 @@
|
|||
|
||||
(deftest insert-a-batch-of-basic-documents-without-ids-and-with-default-write-concern
|
||||
(let [collection "people"
|
||||
docs [{ :name "Joe", :age 30 }, { :name "Paul", :age 27 }]]
|
||||
(is (monger.result/ok? (mgcol/insert-batch "people" docs)))
|
||||
(is (= 2 (mgcol/count collection)))))
|
||||
docs [{:name "Joe" :age 30} {:name "Paul" :age 27}]]
|
||||
(is (monger.result/ok? (mc/insert-batch "people" docs)))
|
||||
(is (= 2 (mc/count collection)))))
|
||||
|
||||
(deftest insert-a-batch-of-basic-documents-without-ids-and-with-explicit-write-concern
|
||||
(let [collection "people"
|
||||
docs [{ :name "Joe", :age 30 }, { :name "Paul", :age 27 }]]
|
||||
(is (monger.result/ok? (mgcol/insert-batch "people" docs WriteConcern/NORMAL)))
|
||||
(is (= 2 (mgcol/count collection)))))
|
||||
docs [{:name "Joe" :age 30} {:name "Paul" :age 27}]]
|
||||
(is (monger.result/ok? (mc/insert-batch "people" docs WriteConcern/NORMAL)))
|
||||
(is (= 2 (mc/count collection)))))
|
||||
|
||||
(deftest insert-a-batch-of-basic-documents-with-explicit-database-without-ids-and-with-explicit-write-concern
|
||||
(let [collection "people"
|
||||
docs [{ :name "Joe", :age 30 }, { :name "Paul", :age 27 }]]
|
||||
docs [{:name "Joe" :age 30} {:name "Paul" :age 27}]]
|
||||
(dotimes [n 44]
|
||||
(is (monger.result/ok? (mgcol/insert-batch monger.core/*mongodb-database* "people" docs WriteConcern/NORMAL))))
|
||||
(is (= 88 (mgcol/count collection)))))
|
||||
(is (monger.result/ok? (mc/insert-batch monger.core/*mongodb-database* "people" docs WriteConcern/NORMAL))))
|
||||
(is (= 88 (mc/count collection)))))
|
||||
|
|
|
|||
Loading…
Reference in a new issue