Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

-

  • Loading branch information...
commit b00c8162de5b65b41ef823244961cf433180e6df 1 parent 863c8e7
@szymong authored
View
5 Makefile
@@ -13,4 +13,7 @@ doc:
@echo
@echo
-.PHONY: test debug doc
+prepare_tests:
+ pip install -r tests/requirements.txt
+
+.PHONY: test debug doc prepare_tests
View
10 sconfig/sconfig.py
@@ -76,14 +76,17 @@ def get_apps(self):
"""
return self._call_as_list("get_apps")
- def create_app(self, name):
+ def create_app(self, name, inherits_from=None):
"""
Creates application with given name.
:param name: application name
:returns: nothing
"""
- self._call("create_app", [name])
+ if inherits_from:
+ self._call("create_app", [name])
+ else:
+ self._call("create_app", [name, inherits_from])
def delete_app(self, name):
"""
@@ -161,3 +164,6 @@ def get_settings_names(self, appname):
:rtype: list of str
"""
return self._call_as_list("get_settings_names", [appname])
+
+ def inherits_from(self, appname, inherits_from):
+ return self._call_as_list("inherits_from", [appname, inherits_from])
View
37 sql/install_sconfig.sql
@@ -84,7 +84,6 @@ BEGIN
END;
$$ LANGUAGE PLPGSQL;
-
-- ============================================================================
CREATE FUNCTION sconfig.set_value(appname_ TEXT, settingname_ TEXT, value_ TEXT) RETURNS VOID AS $$
@@ -209,37 +208,17 @@ COMMENT ON FUNCTION sconfig.app_exists(TEXT) IS
-- ============================================================================
-CREATE FUNCTION sconfig.create_app(appname_ TEXT) RETURNS VOID AS $$
-DECLARE
- c int;
-BEGIN
- INSERT INTO sconfig.apps(appname)
- SELECT appname_
- WHERE NOT EXISTS (SELECT 42 FROM sconfig.apps WHERE appname = appname_);
-
- GET DIAGNOSTICS c = ROW_COUNT;
-
- IF c = 0 THEN
- RAISE EXCEPTION 'App with name % already exists', appname_;
- END IF;
-
-END;
-$$ LANGUAGE PLPGSQL;
-
-COMMENT ON FUNCTION sconfig.create_app(TEXT) IS
-'Procedure creates a new application with given name ($1). Throws exception if such an app exists.';
-
--- ============================================================================
-
-CREATE FUNCTION sconfig.create_app(appname_1 TEXT, inherits_from_app TEXT)
+CREATE FUNCTION sconfig.create_app(appname_ TEXT, inherits_from_app TEXT = NULL)
RETURNS VOID
AS $$
DECLARE
e BOOLEAN;
BEGIN
- EXECUTE sconfig.assert_app_exists(inherits_from_app);
+ IF inherits_from_app IS NOT NULL THEN
+ EXECUTE sconfig.assert_app_exists(inherits_from_app);
+ END IF;
- INSERT INTO sconfig.apps(appname, inherits_from) VALUES (appname_1, inherits_from_app);
+ INSERT INTO sconfig.apps(appname, inherits_from) VALUES (appname_, inherits_from_app);
END;
$$ LANGUAGE PLPGSQL;
@@ -248,20 +227,20 @@ COMMENT ON FUNCTION sconfig.create_app(TEXT, TEXT) IS
-- ============================================================================
-CREATE FUNCTION sconfig.inherits_from(appname_1 TEXT, inherits_from_app TEXT)
+CREATE FUNCTION sconfig.inherits_from(appname_ TEXT, inherits_from_app TEXT)
RETURNS BOOLEAN
AS $$
DECLARE
e BOOLEAN;
BEGIN
- EXECUTE sconfig.assert_app_exists(appname_1);
+ EXECUTE sconfig.assert_app_exists(appname_);
EXECUTE sconfig.assert_app_exists(inherits_from_app);
SELECT EXISTS(
SELECT 42
FROM sconfig.apps
- WHERE (appname, inherits_from) = (appname_1, inherits_from_app)
+ WHERE (appname, inherits_from) = (appname_, inherits_from_app)
)
INTO e;
View
8 tests/helpers.py
@@ -55,8 +55,8 @@ def setup(self):
def teardown(self):
self.db.rollback()
- def cr_app(self, name):
- self.sconfig.create_app(name)
+ def cr_app(self, name, inherits_from=None):
+ self.sconfig.create_app(name, inherits_from)
def cr_apps(self, *names):
for name in names:
@@ -89,5 +89,5 @@ def delete_settings(self, appname):
def get_settings_names(self, appname):
return self.sconfig.get_settings_names(appname)
-
-
+ def inherits_from(self, appname1, appname2):
+ return self.sconfig.inherits_from(appname1, appname2)
View
1  tests/inheritance/__init__.py
@@ -0,0 +1 @@
+from tests import *
View
43 tests/inheritance/simple_app_test.py
@@ -0,0 +1,43 @@
+from . import *
+
+
+class CreateApp_Test(TransactionalTest):
+
+ @expectedFailure
+ def test_adding_app_inheritings_from_non_existing_app(self):
+ self.cr_app("aaaaaa", "bbbbbb")
+
+ def test_adding_one_app(self):
+ self.cr_app("app2")
+ self.cr_app("app1", "app2")
+ assert self.app_exists("app1")
+ assert self.app_exists("app2")
+ assert self.apps() == ["app1", "app2"]
+ assert self.inherits_from("app1", "app2")
+ assert not self.inherits_from("app2", "app1")
+ assert not self.inherits_from("app1", "app1")
+ assert not self.inherits_from("app2", "app2")
+
+ def test_adding_two_apps(self):
+ self.cr_app("app1")
+ self.cr_app("app2")
+ assert self.apps() == ["app1", "app2"]
+
+ @expectedFailure
+ def test_adding_existing_app(self):
+ self.cr_app("app1")
+ self.cr_app("app1")
+
+ @expectedFailure
+ def test_deleting_app_which_doesnt_exist(self):
+ self.del_app("x")
+
+ def test_deleting_existing_app(self):
+ self.cr_app("app1")
+ self.del_app("app1")
+ assert self.apps() == []
+
+ def test_adding_apps_and_deleting_one(self):
+ self.cr_apps("app1", "app2", "app3")
+ self.del_app("app2")
+ assert self.apps() == ["app1", "app3"]
View
0  requirements.txt → tests/requirements.txt
File renamed without changes
Please sign in to comment.
Something went wrong with that request. Please try again.