<commit_before>(ns celestial.test.persistency
 (:use 
   midje.sweet 
   [celestial.roles :only (admin)]
   [celestial.persistency :only (validate-type validate-quota user-exists? validate-user)]
   [celestial.fixtures :only (redis-type is-type? user-quota with-m?)])
 (:import clojure.lang.ExceptionInfo))

(fact "puppet std type validation"
    
    (validate-type redis-type) => truthy

    (validate-type (assoc-in redis-type [:puppet-std :module :src] nil)) => 
       (throws ExceptionInfo (is-type? :celestial.persistency/non-valid-type))

    (validate-type (assoc-in redis-type [:puppet-std :args] nil)) => truthy 

    (validate-type (assoc-in redis-type [:puppet-std :args] [])) => truthy 
    
    (validate-type (assoc-in redis-type [:puppet-std :args] {})) => 
       (throws ExceptionInfo (is-type? :celestial.persistency/non-valid-type))
      
    (validate-type (dissoc redis-type :classes)) => 
       (throws ExceptionInfo (is-type? :celestial.persistency/non-valid-type)))

(fact "non puppet type"
  (validate-type {:type "foo"}) => truthy)

(fact "quotas validations"
     (validate-quota user-quota) => truthy
     (provided (user-exists? "foo") => true :times 1))

(fact "non int limit quota" filters
   (validate-quota (assoc-in user-quota [:quotas :aws :limit] "1")) => 
      (throws ExceptionInfo (with-m? {:quotas '(({:aws {:limit ("must be a integer")}}))}))
   (provided (user-exists? "foo") => true :times 1))

(fact "user validation"
     (validate-user {:username "foo" :password "<PASSWORD>" :roles admin :envs []})  => truthy
     (validate-user {:password "<PASSWORD>" :roles admin :envs []})  => 
       (throws ExceptionInfo (with-m? {:username '("must be present")} ))
     (validate-user {:username "foo" :password "<PASSWORD>" :roles ["foo"] :envs []})  =>
       (throws ExceptionInfo (with-m? {:roles '(({0 ("role must be either #{:celestial.roles/anonymous :celestial.roles/user :celestial.roles/admin}")}))} ))
      )<commit_msg>fixing tests and adding envs validation check<commit_after>(ns celestial.test.persistency
 (:use 
   midje.sweet 
   [celestial.roles :only (admin)]
   [celestial.persistency :only (validate-type validate-quota user-exists? validate-user)]
   [celestial.fixtures :only (redis-type is-type? user-quota with-m?)])
 (:import clojure.lang.ExceptionInfo))

(fact "puppet std type validation"
    
    (validate-type redis-type) => truthy

    (validate-type (assoc-in redis-type [:puppet-std :module :src] nil)) => 
       (throws ExceptionInfo (is-type? :celestial.persistency/non-valid-type))

    (validate-type (assoc-in redis-type [:puppet-std :args] nil)) => truthy 

    (validate-type (assoc-in redis-type [:puppet-std :args] [])) => truthy 
    
    (validate-type (assoc-in redis-type [:puppet-std :args] {})) => 
       (throws ExceptionInfo (is-type? :celestial.persistency/non-valid-type))
      
    (validate-type (dissoc redis-type :classes)) => 
       (throws ExceptionInfo (is-type? :celestial.persistency/non-valid-type)))

(fact "non puppet type"
  (validate-type {:type "foo"}) => truthy)

(fact "quotas validations"
     (validate-quota user-quota) => truthy
     (provided (user-exists? "foo") => true :times 1))

(fact "non int limit quota" filters
   (validate-quota (assoc-in user-quota [:quotas :aws :limit] "1")) => 
      (throws ExceptionInfo (with-m? {:quotas '(({:aws {:limit ("must be a integer")}}))}))
   (provided (user-exists? "foo") => true :times 1))

(fact "user validation"
     (validate-user {:username "foo" :password "<PASSWORD>" :roles admin :envs []})  => truthy
     (validate-user {:password "<PASSWORD>" :roles admin :envs []})  => 
       (throws ExceptionInfo (with-m? {:username '("must be present")}))
     (validate-user {:username "foo" :password "<PASSWORD>" :roles admin})  => 
       (throws ExceptionInfo (with-m? {:envs '("must be present")}))
     (validate-user {:username "foo" :password "<PASSWORD>" :roles ["foo"] :envs []})  =>
       (throws ExceptionInfo (with-m? {:roles '(({0 ("role must be either #{:celestial.roles/anonymous :celestial.roles/user :celestial.roles/admin}")}))} ))
      )
{'fraction_non_alphanumeric': 0.17957405614714425, 'fraction_numerical': 0.001936108422071636, 'mean_word_length': 3.8114086146682187, 'pattern_counts': {'":': 0, '<': 10, '<?xml version=': 0, '>': 39, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3611771', 'n_tokens_mistral': 1480, 'n_tokens_neox': 1407, 'n_words': 348}