observer user test
diff --git a/xos/tosca/tests/allObserverTests.py b/xos/tosca/tests/allObserverTests.py
index 82bb10b..4f832f2 100644
--- a/xos/tosca/tests/allObserverTests.py
+++ b/xos/tosca/tests/allObserverTests.py
@@ -1,6 +1,10 @@
from observerComputeTest import ObserverComputeTest
from observerImageTest import ObserverImageTest
+from observerUserTest import ObserverUserTest
+from observerSiteTest import ObserverSiteTest
if __name__ == "__main__":
ObserverComputeTest()
ObserverImageTest()
+ ObserverSiteTest()
+ ObserverUserTest()
diff --git a/xos/tosca/tests/observerSiteTest.py b/xos/tosca/tests/observerSiteTest.py
index bc1efd4..0ebc8be 100644
--- a/xos/tosca/tests/observerSiteTest.py
+++ b/xos/tosca/tests/observerSiteTest.py
@@ -9,11 +9,11 @@
# hide_observer_output = False # uncomment to display lots of stuff to screen
def cleanup(self):
- # We don't want to leak resources, so we make sure to let the observer
+ # We don't want to leak rezsources, so we make sure to let the observer
# attempt to delete these objects.
- self.try_to_delete(Site, purge=False, name="testsite")
+ self.try_to_delete(Site, purge=False, login_base="testsite")
self.run_observer()
- self.try_to_delete(Site, purge=True, name="testsite")
+ self.try_to_delete(Site, purge=True, login_base="testsite")
def create_site(self):
self.assert_noobj(Site, "testsite")
@@ -23,7 +23,6 @@
testsite:
type: tosca.nodes.Site
properties:
- display_name: TestSite
site_url: http://opencloud.us/
requirements:
- deployment:
@@ -35,7 +34,7 @@
relationship: tosca.relationships.UsesController
""" % (self.get_usable_deployment(), self.get_usable_controller()))
- testsite = self.assert_obj(Site, "TestSite")
+ testsite = self.assert_obj(Site, "testsite")
self.run_model_policy(save_output="/tmp/sitetest:create_site:model_policy")
@@ -45,7 +44,7 @@
self.run_observer(save_output="/tmp/sitetest:create_site:observer")
- testsite = self.assert_obj(Site, "TestSite")
+ testsite = self.assert_obj(Site, "testsite")
cs = ControllerSite.objects.filter(site=testsite)
assert(len(cs) == 1)
diff --git a/xos/tosca/tests/observerUserTest.py b/xos/tosca/tests/observerUserTest.py
new file mode 100644
index 0000000..44b47d3
--- /dev/null
+++ b/xos/tosca/tests/observerUserTest.py
@@ -0,0 +1,82 @@
+from observertest import BaseObserverToscaTest
+
+from core.models import Site, Deployment, User, ControllerUser
+
+# Note that as a side effect, these tests will also create a Site
+
+class ObserverUserTest(BaseObserverToscaTest):
+ tests = ["create_user"]
+ # hide_observer_output = False # uncomment to display lots of stuff to screen
+
+ def cleanup(self):
+ # We don't want to leak resources, so we make sure to let the observer
+ # attempt to delete these objects.
+ self.try_to_delete(User, purge=False, email="johndoe@foo.bar")
+ self.try_to_delete(Site, purge=False, login_base="testsite")
+ self.run_observer()
+ self.try_to_delete(User, purge=True, email="johndoe@foo.bar")
+ self.try_to_delete(Site, purge=True, login_base="testsite")
+
+ def assert_nouser(self, email):
+ assert(not User.objects.filter(email=email))
+
+ def assert_user(self, email, **kwargs):
+ obj = User.objects.get(email=email)
+ assert(obj)
+ for (k,v) in kwargs.items():
+ if (getattr(obj,k,None) != v):
+ print "Object %s property '%s' is '%s' and should be '%s'" % (obj, k, getattr(obj,k,None), v)
+ assert(False)
+ return obj
+
+ def create_user(self):
+ self.assert_noobj(Site, "testsite")
+ self.assert_nouser("johndoe@foo.bar")
+ self.execute(self.make_nodetemplate(self.get_usable_deployment(), "tosca.nodes.Deployment",
+ props={"no-delete": True}) + \
+"""
+ testsite:
+ type: tosca.nodes.Site
+ properties:
+ site_url: http://opencloud.us/
+ requirements:
+ - deployment:
+ node: %s
+ relationship: tosca.relationships.SiteDeployment
+ requirements:
+ - controller:
+ node: %s
+ relationship: tosca.relationships.UsesController
+ johndoe@foo.bar:
+ type: tosca.nodes.User
+ properties:
+ password: letmein
+ firstname: john
+ lastname: doe
+ requirements:
+ - site:
+ node: testsite
+ relationship: tosca.relationships.MemberOfSite
+""" % (self.get_usable_deployment(), self.get_usable_controller()))
+
+ testsite = self.assert_obj(Site, "testsite")
+ testuser = self.assert_user("johndoe@foo.bar")
+
+ self.run_model_policy(save_output="/tmp/usertest:create_user:model_policy")
+
+ # make sure a ControllerSite object was created
+ cu = ControllerUser.objects.filter(user=testuser)
+ assert(len(cu) == 1)
+
+ self.run_observer(save_output="/tmp/usertest:create_user:observer")
+
+ testuser = self.assert_user("johndoe@foo.bar")
+
+ cu = ControllerUser.objects.filter(user=testuser)
+ assert(len(cu) == 1)
+ assert(cu[0].kuser_id is not None)
+ assert(cu[0].kuser_id != "")
+
+if __name__ == "__main__":
+ ObserverUserTest()
+