From af8d19ab60460162711a7c706f910de05c764db1 Mon Sep 17 00:00:00 2001 From: Andrey Antukh Date: Sat, 15 Jun 2019 18:20:36 +0200 Subject: [PATCH] test(backend): improve tests fixtures --- backend/test/uxbox/tests/helpers.clj | 32 ++++++++++------------ backend/test/uxbox/tests/main.clj | 4 +++ backend/test/uxbox/tests/test_icons.clj | 1 + backend/test/uxbox/tests/test_images.clj | 3 +- backend/test/uxbox/tests/test_pages.clj | 5 +--- backend/test/uxbox/tests/test_projects.clj | 7 +---- backend/test/uxbox/tests/test_users.clj | 1 + 7 files changed, 25 insertions(+), 28 deletions(-) diff --git a/backend/test/uxbox/tests/helpers.clj b/backend/test/uxbox/tests/helpers.clj index f7a1736c24..b6ac9ddc01 100644 --- a/backend/test/uxbox/tests/helpers.clj +++ b/backend/test/uxbox/tests/helpers.clj @@ -40,23 +40,21 @@ (defn database-reset [next] - (state-init - (fn [] - (with-open [conn (db/connection)] - (let [sql (str "SELECT table_name " - " FROM information_schema.tables " - " WHERE table_schema = 'public' " - " AND table_name != 'migrations';") - result (->> (sc/fetch conn sql) - (map :table_name))] - (sc/execute conn (str "TRUNCATE " - (apply str (interpose ", " result)) - " CASCADE;")))) - (try - (next) - (finally - (st/clear! uxbox.media/media-storage) - (st/clear! uxbox.media/assets-storage)))))) + (with-open [conn (db/connection)] + (let [sql (str "SELECT table_name " + " FROM information_schema.tables " + " WHERE table_schema = 'public' " + " AND table_name != 'migrations';") + result (->> (sc/fetch conn sql) + (map :table_name))] + (sc/execute conn (str "TRUNCATE " + (apply str (interpose ", " result)) + " CASCADE;")))) + (try + (next) + (finally + (st/clear! uxbox.media/media-storage) + (st/clear! uxbox.media/assets-storage)))) (defmacro await [expr] diff --git a/backend/test/uxbox/tests/main.clj b/backend/test/uxbox/tests/main.clj index 0d321ba5a7..60665eae6b 100644 --- a/backend/test/uxbox/tests/main.clj +++ b/backend/test/uxbox/tests/main.clj @@ -10,6 +10,10 @@ (defn -main [& args] (require 'uxbox.tests.test-projects) + (require 'uxbox.tests.test-pages) + (require 'uxbox.tests.test-images) + (require 'uxbox.tests.test-icons) + (require 'uxbox.tests.test-users) (let [{:keys [fail]} (test/run-all-tests #"^uxbox.tests.*")] (if (pos? fail) (System/exit fail) diff --git a/backend/test/uxbox/tests/test_icons.clj b/backend/test/uxbox/tests/test_icons.clj index c158f1c9d9..db9d90706c 100644 --- a/backend/test/uxbox/tests/test_icons.clj +++ b/backend/test/uxbox/tests/test_icons.clj @@ -9,6 +9,7 @@ [uxbox.services :as usv] [uxbox.tests.helpers :as th])) +(t/use-fixtures :once th/state-init) (t/use-fixtures :each th/database-reset) (t/deftest test-http-list-icon-collections diff --git a/backend/test/uxbox/tests/test_images.clj b/backend/test/uxbox/tests/test_images.clj index 4c7b8cd2a0..9f84850942 100644 --- a/backend/test/uxbox/tests/test_images.clj +++ b/backend/test/uxbox/tests/test_images.clj @@ -12,6 +12,7 @@ [uxbox.services :as usv] [uxbox.tests.helpers :as th])) +(t/use-fixtures :once th/state-init) (t/use-fixtures :each th/database-reset) (t/deftest test-http-list-image-collections @@ -166,6 +167,6 @@ (th/with-server {:handler uapi/app} (let [uri (str th/+base-url+ "/api/library/images") [status data] (th/http-get user uri)] - (println "RESPONSE:" status data) + ;; (println "RESPONSE:" status data) (t/is (= 200 status)) (t/is (= 1 (count data)))))))) diff --git a/backend/test/uxbox/tests/test_pages.clj b/backend/test/uxbox/tests/test_pages.clj index 6bb71ad7ad..f8d9036e23 100644 --- a/backend/test/uxbox/tests/test_pages.clj +++ b/backend/test/uxbox/tests/test_pages.clj @@ -10,12 +10,9 @@ [uxbox.services :as usv] [uxbox.tests.helpers :as th])) +(t/use-fixtures :once th/state-init) (t/use-fixtures :each th/database-reset) -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; -;; Frontend Test -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; - (t/deftest test-http-page-create (with-open [conn (db/connection)] (let [user (th/create-user conn 1) diff --git a/backend/test/uxbox/tests/test_projects.clj b/backend/test/uxbox/tests/test_projects.clj index edd66432e2..c0b909c5f7 100644 --- a/backend/test/uxbox/tests/test_projects.clj +++ b/backend/test/uxbox/tests/test_projects.clj @@ -3,8 +3,6 @@ [promesa.core :as p] [suricatta.core :as sc] [clj-uuid :as uuid] - [catacumba.testing :refer (with-server)] - [catacumba.serializers :as sz] [uxbox.db :as db] [uxbox.api :as uapi] [uxbox.services.projects :as uspr] @@ -12,12 +10,9 @@ [uxbox.services :as usv] [uxbox.tests.helpers :as th])) +(t/use-fixtures :once th/state-init) (t/use-fixtures :each th/database-reset) -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; -;; Frontend Test -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; - (t/deftest test-http-project-list (with-open [conn (db/connection)] (let [user (th/create-user conn 1) diff --git a/backend/test/uxbox/tests/test_users.clj b/backend/test/uxbox/tests/test_users.clj index 7f39acd040..f5c4e52b0b 100644 --- a/backend/test/uxbox/tests/test_users.clj +++ b/backend/test/uxbox/tests/test_users.clj @@ -11,6 +11,7 @@ [uxbox.services :as usv] [uxbox.tests.helpers :as th])) +(t/use-fixtures :once th/state-init) (t/use-fixtures :each th/database-reset) (t/deftest test-http-retrieve-profile