Skip to content

Instantly share code, notes, and snippets.

View AdamSaleh's full-sized avatar

Adam Saleh AdamSaleh

View GitHub Profile
@AdamSaleh
AdamSaleh / gist:5347149
Created April 9, 2013 16:27
Two functions, create-records-list takes tree structure such as custom-provider, and returns list of records that can be passed to ui/create, prepare-org-custom-provider takes this list and executes it and syncs the repos.
(def custom-provider [{:name "fedorapeople"
:products [{:name "safari-1_0"
:repos [{:name "safari-x86_64"
:url "http://inecas.fedorapeople.org/fakerepos/cds/content/safari/1.0/x86_64/rpms/"}]}]}])
(defn create-records-list [list org & parent]
(into [] (flatten
(for [item list]
(if (contains? item :products)
(let [prov (kt/newProvider {:name (item :name) :org org})]
(rest/read (kt/newProvider {:name "Custom Provider8" :org "test-create3"}))
IllegalArgumentException No implementation of method: :id of protocol: #'katello.rest/CRUD found for class: java.lang.String clojure.core/-cache-protocol-fn (core_deftype.clj:541)
=> (clojure.repl/pst 100)
IllegalArgumentException No implementation of method: :id of protocol: #'katello.rest/CRUD found for class: java.lang.String
clojure.core/-cache-protocol-fn (core_deftype.clj:541)
katello.rest/eval5330/fn--5331/G--5313--5336 (rest.clj:69)
katello.rest/get-id (rest.clj:101)
katello.rest/url-maker/iter--5419--5423/fn--5424/fn--5425/iter--5427--5431/fn--5432/fn--5433 (rest.clj:109)
katello.rest/url-maker/iter--5419--5423/fn--5424/fn--5425/iter--5427--5431/fn--5432 (rest.clj:109)
clojure.lang.LazySeq.sval (LazySeq.java:42)
(fn []
(def ^:dynamic test-org-env (uniqueify (kt/newOrganization {:name "env-org"})))
(rest/create test-org-env)
(org/switch test-org-env)
(fake/prepare-org-custom-provider test-org-env fake/custom-env-test-provider)
(env/create {:name env-dev :org test-org-env :prior-env "Library"})
(env/create {:name env-qa :org test-org-env :prior-env env-dev})
(env/create {:name env-release :org test-org-env :prior-env env-qa})
(promote-delete-content (kt/newChangeset
{:env (kt/newEnvironment {:name env-dev :org test-org-env})
@AdamSaleh
AdamSaleh / menu.clj
Created May 22, 2013 11:00
So, I wanted to create tests for https://SERVER/katello/notices, but wasn't sure how to make (go-to katello.notices/page) to take me there. This is how I did it.
(ns katello.menu
(:require [com.redhat.qe.auto.selenium.selenium :refer [browser ->browser] :as sel]
[katello :as kt]
(katello [ui :as ui]
[navigation :refer [browser-fn] :as nav])))
(defn fmap "Passes all values of m through f." [f m]
(into {} (for [[k v] m] [k (f v)])))
;; Locators
@AdamSaleh
AdamSaleh / gist:5650339
Created May 25, 2013 19:03
naive implementation
(run 10 [knows]
(membero [:pk :a] knows)
(membero [:pk :b] knows)
(fresh [somebody]
(conde
[(nonmembero [:pk somebody] knows)]
[(membero [:pcrypted [:pk somebody] [:nonce somebody]] knows)]))))
(defn initiate [past-knowledge]
(->>
(run* [M A B]
(!= M B)
(!= A B)
(membero [:me M] past-knowledge)
(membero [:id A] past-knowledge)
(membero [:id B] past-knowledge)
(membero [:pk B] past-knowledge))
(map (partial apply (fn [M A B]
@AdamSaleh
AdamSaleh / gist:5685224
Created May 31, 2013 14:10
Macro-ing contracts
;lets say I have a constrained function like this:
(def constr-sqr
(contracts/with-constraints
sqr
(contracts/contract sqr-o "the only odd"
[n] [odd?])
(contracts/contract sqr-c "the constraining of sqr"
[n] [number? (not= 0 n) => pos? number?])
;works :
=>(->
(rpc/get [1234])
(map-project [:product_id :product_version_id])
(rename-keys {:product_id :product, :product_version_id :product_version}))
{:product 313, :product_version 1416}
;doesn't
=> (->
(rpc/get [1234])
➜ tcms-upload lein repl
REPL started; server listening on localhost port 44114
CompilerException java.lang.ClassNotFoundException: rpc.test-plan, compiling:(tcms_upload/core.clj:47:5)
clojure.core=> (use 'rpc.test-plan)
WARNING: get already refers to: #'clojure.core/get in namespace: rpc.test-plan, being replaced by: #'rpc.test-plan/get
nil
clojure.core=>
(defn single? [a]
(= 1 (count a)))
(defmacro map-check [map-features & predicates]
(let [symbols #(->> % (into []) flatten
(filter symbol?)
(into #{}))]
`(fn [m#]
(and (map? m#)
(<= 1 (count (l/run 1 [~@(symbols map-features)]