create random datasets from schema
TODO: cleanup/refactoring
This commit is contained in:
parent
e95311318e
commit
bcaa84c11c
|
@ -0,0 +1,10 @@
|
|||
({:accessible false, :note ""}
|
||||
{:accessible false, :note "y"}
|
||||
{:accessible true, :note "74"}
|
||||
{:accessible nil, :note "B0"}
|
||||
{:accessible false, :note "20D"}
|
||||
{:accessible false, :note ""}
|
||||
{:accessible false, :note "R5nb"}
|
||||
{:accessible true, :note "hkUGJ8"}
|
||||
{:accessible true, :note "01pd"}
|
||||
{:accessible false, :note ""})
|
|
@ -36,6 +36,8 @@
|
|||
[org.clojure/tools.logging "1.2.4"]
|
||||
[org.slf4j/slf4j-api "2.0.0-alpha6"]
|
||||
[org.slf4j/slf4j-simple "2.0.0-alpha6"]
|
||||
;; testing
|
||||
[org.clojure/test.check "0.9.0"]
|
||||
]
|
||||
:main beherbergung.webserver.state
|
||||
:profiles {:dev {:dependencies [;; helpers for testing
|
||||
|
|
|
@ -5,13 +5,17 @@
|
|||
[beherbergung.config.state :refer [env]]
|
||||
[beherbergung.model.auth :as auth]
|
||||
[beherbergung.model.ngo :as ngo]
|
||||
[clojure.edn]))
|
||||
[clojure.edn]
|
||||
[clojure.spec.gen.alpha :as gen]
|
||||
[beherbergung.db.export :refer [write-edn]]))
|
||||
|
||||
(defn JaNein->bool [JaNein]
|
||||
({"Ja" true "Nein" false} JaNein))
|
||||
|
||||
(def mapping {:accessible #(JaNein->bool (get % "Ist die Unterkunft rollstuhlgerecht?"))
|
||||
#_(def mapping {:accessible #(JaNein->bool (get % "Ist die Unterkunft rollstuhlgerecht?"))
|
||||
:note "Nachricht"})
|
||||
(def mapping {:accessible :accessible
|
||||
:note :note})
|
||||
|
||||
(defn unify
|
||||
[offers]
|
||||
|
@ -25,14 +29,21 @@
|
|||
(into {}))))]
|
||||
(map (mapping->fn mapping) offers)))
|
||||
|
||||
(s/def ::accessible (s/nilable t/boolean))
|
||||
(s/def ::note (s/nilable t/string))
|
||||
(s/def ::offer (s/keys :opt-un [::accessible ::note]))
|
||||
(def t_boolean (s/with-gen t/boolean #(s/gen boolean?)))
|
||||
(def t_string (s/with-gen t/string #(s/gen string?)))
|
||||
(s/def ::accessible (s/nilable t_boolean))
|
||||
(s/def ::note (s/nilable t_string))
|
||||
(s/def ::offer (s/keys :req-un [::accessible ::note]))
|
||||
|
||||
(comment
|
||||
(write-edn "./data/sample-data/example.edn"
|
||||
(gen/sample (s/gen ::offer))))
|
||||
|
||||
(s/fdef get_offers
|
||||
:args (s/tuple map? (s/keys :req-un [::auth/auth]) map? map?)
|
||||
:ret (s/nilable (s/* ::offer)))
|
||||
|
||||
|
||||
(defn get_offers
|
||||
"The offers that are visible for the ngo, belonging to the login"
|
||||
[_node opt ctx _info]
|
||||
|
@ -40,6 +51,8 @@
|
|||
[ngo:id] (auth+role->entity ctx (:auth opt) ::ngo/record)]
|
||||
(when ngo:id
|
||||
;; TODO: take it from the db and filter it by visibility to the ngo
|
||||
(unify (clojure.edn/read-string (slurp (:import-file env)))))))
|
||||
(if (:import-file env)
|
||||
(unify (clojure.edn/read-string (slurp (:import-file env))))
|
||||
(gen/sample (s/gen ::offer))))))
|
||||
|
||||
(s/def ::get_offers (t/resolver #'get_offers))
|
||||
|
|
|
@ -10,7 +10,7 @@
|
|||
:db-export-prefix "./data/export/"
|
||||
:db-validate true
|
||||
|
||||
:import-file nil
|
||||
:import-file "./data/sample-data/example.edn"
|
||||
|
||||
;:mail-host ""
|
||||
;:mail-user ""
|
||||
|
|
|
@ -16,10 +16,9 @@
|
|||
|
||||
(deftest correct-login
|
||||
(let [offers (get_offers {:auth {:mail mail :password password}})]
|
||||
(is (= 110 (count offers))) ;; TODO: we need a test dataset that can be published (generated)
|
||||
(is (= {:accessible true
|
||||
:note "füg"}
|
||||
(first offers)))))
|
||||
(is (= 10 (count offers))) ;; 10 is the default sample size of gen/sample
|
||||
(is (= {:accessible true, :note "hkUGJ8"}
|
||||
(nth offers 7))))) ;; picked one of the random generated datasets that contains not so many trivial values
|
||||
|
||||
(deftest wrong-login
|
||||
(let [offers (get_offers {:auth {:mail mail :password "wrong"}})]
|
||||
|
|
Loading…
Reference in New Issue