def test_textfield():
    """Test form rendering inside a request."""

    #form name is prepended to element ids only when running inside a request.
    class MyField(widgets.WidgetsList):
        blonk = widgets.TextField()

    tf = widgets.ListForm(fields=MyField())

    class MyFieldOverrideName(widgets.WidgetsList):
        blonk = widgets.TextField(name="blink")

    tf2 = widgets.ListForm(fields=MyFieldOverrideName())

    class MyRoot(controllers.RootController):
        [expose()]

        def fields(self):
            return tf.render(format='xhtml')

        [expose()]

        def override(self):
            return tf2.render(format='xhtml')

    root = MyRoot()
    d = call(root.fields)
    assert 'name="blonk"' in d
    assert 'id="form_blonk"' in d

    d = call(root.override)
    assert 'name="blink"' in d
    assert 'id="form_blink"' in d
Exemple #2
0
def test_textfield():
    """Test form rendering inside a request."""
    #form name is prepended to element ids only when running inside a request.
    class MyField(widgets.WidgetsList):
        blonk = widgets.TextField()
    tf = widgets.ListForm(fields=MyField())

    class MyFieldOverrideName(widgets.WidgetsList):
        blonk = widgets.TextField(name="blink")
    tf2 = widgets.ListForm(fields=MyFieldOverrideName())

    class MyRoot(controllers.RootController):
        [expose()]
        def fields(self):
            return tf.render(format='xhtml')

        [expose()]
        def override(self):
            return tf2.render(format='xhtml')

    root = MyRoot()
    d = call(root.fields)
    assert 'name="blonk"' in d
    assert 'id="form_blonk"' in d

    d = call(root.override)
    assert 'name="blink"' in d
    assert 'id="form_blink"' in d
Exemple #3
0
 def test_index(self):
     "Test that call_with_request is usable if controller uses redirect"
     try:
         testutil.call(self.root.redirect)
         self.fail("no redirect exception raised")
     except cherrypy.HTTPRedirect, e:
         assert e.status in [302, 303]
         self.assertEquals(1, len(e.urls))
         assert e.urls[0].endswith("foo")
Exemple #4
0
 def test_index(self):
     "Test that call_with_request is usable if controller uses redirect"
     try:
         testutil.call(self.root.redirect)
         self.fail("no redirect exception raised")
     except cherrypy.HTTPRedirect, e:
         assert e.status in [302, 303]
         self.assertEquals(1, len(e.urls))
         assert e.urls[0].endswith("foo")
Exemple #5
0
 def test_job_with_custom_distro_without_optional_attributes_can_be_roundtripped(
         self):
     complete_job_xml = '''
                 <job>
                     <whiteboard>
                         so pretty
                     </whiteboard>
                     <recipeSet>
                         <recipe>
                             <distro>
                                 <tree url="ftp://dummylab.example.com/distros/MyCustomLinux1.0/Server/i386/os/"/>
                                 <initrd url="pxeboot/initrd"/>
                                 <kernel url="pxeboot/vmlinuz"/>
                                 <arch value="i386"/>
                                 <osversion major="RedHatEnterpriseLinux7"/>
                             </distro>
                             <hostRequires/>
                             <task name="/distribution/install"/>
                         </recipe>
                     </recipeSet>
                 </job>
             '''
     xmljob = lxml.etree.fromstring(complete_job_xml)
     job = testutil.call(self.controller.process_xmljob, xmljob, self.user)
     roundtripped_xml = lxml.etree.tostring(job.to_xml(clone=True),
                                            pretty_print=True,
                                            encoding='utf8')
     self.assertIn(
         '<tree url="ftp://dummylab.example.com/distros/MyCustomLinux1.0/Server/i386/os/"/>',
         roundtripped_xml)
     self.assertIn('<initrd url="pxeboot/initrd"/>', roundtripped_xml)
     self.assertIn('<kernel url="pxeboot/vmlinuz"/>', roundtripped_xml)
     self.assertIn('<arch value="i386"/>', roundtripped_xml)
     self.assertIn('<osversion major="RedHatEnterpriseLinux7" minor="0"/>',
                   roundtripped_xml)
Exemple #6
0
 def test_job_with_custom_distro_without_optional_attributes_can_be_roundtripped(self):
     complete_job_xml = '''
                 <job>
                     <whiteboard>
                         so pretty
                     </whiteboard>
                     <recipeSet>
                         <recipe>
                             <distro>
                                 <tree url="ftp://dummylab.example.com/distros/MyCustomLinux1.0/Server/i386/os/"/>
                                 <initrd url="pxeboot/initrd"/>
                                 <kernel url="pxeboot/vmlinuz"/>
                                 <arch value="i386"/>
                                 <osversion major="RedHatEnterpriseLinux7"/>
                             </distro>
                             <hostRequires/>
                             <task name="/distribution/check-install"/>
                         </recipe>
                     </recipeSet>
                 </job>
             '''
     xmljob = lxml.etree.fromstring(complete_job_xml)
     job = testutil.call(self.controller.process_xmljob, xmljob, self.user)
     roundtripped_xml = lxml.etree.tostring(job.to_xml(clone=True), pretty_print=True, encoding='utf8')
     self.assertIn('<tree url="ftp://dummylab.example.com/distros/MyCustomLinux1.0/Server/i386/os/"/>', roundtripped_xml)
     self.assertIn('<initrd url="pxeboot/initrd"/>', roundtripped_xml)
     self.assertIn('<kernel url="pxeboot/vmlinuz"/>', roundtripped_xml)
     self.assertIn('<arch value="i386"/>', roundtripped_xml)
     self.assertIn('<osversion major="RedHatEnterpriseLinux7" minor="0"/>', roundtripped_xml)
Exemple #7
0
 def test_job_xml_can_be_roundtripped(self):
     # Ideally the logic for parsing job XML into a Job instance would live in model code,
     # so that this test doesn't have to go through the web layer...
     complete_job_xml = pkg_resources.resource_string('bkr.inttest', 'complete-job.xml')
     xmljob = lxml.etree.fromstring(complete_job_xml)
     job = testutil.call(self.controller.process_xmljob, xmljob, self.user)
     roundtripped_xml = lxml.etree.tostring(job.to_xml(clone=True), pretty_print=True, encoding='utf8')
     self.assertMultiLineEqual(roundtripped_xml, complete_job_xml)
Exemple #8
0
    def test_complete_job_results(self):
        complete_job_xml = pkg_resources.resource_string(
            'bkr.inttest', 'complete-job.xml')
        xmljob = lxml.etree.fromstring(complete_job_xml)
        job = testutil.call(self.controller.process_xmljob, xmljob, self.user)
        session.flush()

        # Complete the job, filling in values to match what's hardcoded in
        # complete-job-results.xml...
        recipe = job.recipesets[0].recipes[0]
        guestrecipe = recipe.guests[0]
        data_setup.mark_recipe_running(
            recipe,
            fqdn=u'system.test-complete-job-results',
            start_time=datetime.datetime(2016, 1, 31, 23, 0, 0),
            install_started=datetime.datetime(2016, 1, 31, 23, 0, 1),
            install_finished=datetime.datetime(2016, 1, 31, 23, 0, 2),
            postinstall_finished=datetime.datetime(2016, 1, 31, 23, 0, 3),
            task_start_time=datetime.datetime(2016, 1, 31, 23, 0, 4))
        data_setup.mark_recipe_complete(
            guestrecipe,
            fqdn=u'guest.test-complete-job-results',
            mac_address='ff:ff:ff:00:00:00',
            start_time=datetime.datetime(2016, 1, 31, 23, 30, 0),
            install_started=datetime.datetime(2016, 1, 31, 23, 30, 1),
            install_finished=datetime.datetime(2016, 1, 31, 23, 30, 2),
            postinstall_finished=datetime.datetime(2016, 1, 31, 23, 30, 3),
            finish_time=datetime.datetime(2016, 1, 31, 23, 30, 4))
        data_setup.mark_recipe_complete(
            recipe,
            only=True,
            start_time=datetime.datetime(2016, 1, 31, 23, 0, 4),
            finish_time=datetime.datetime(2016, 1, 31, 23, 59, 0))
        recipe.installation.rendered_kickstart.url = u'http://example.com/recipe.ks'
        guestrecipe.installation.rendered_kickstart.url = u'http://example.com/guest.ks'
        session.flush()
        # Hack up the database ids... This will fail if it's flushed, but it's
        # the easiest way to make them match the expected values.
        job.id = 1
        job.recipesets[0].id = 1
        recipe.id = 1
        guestrecipe.id = 2
        recipe.tasks[0].id = 1
        recipe.tasks[1].id = 2
        guestrecipe.tasks[0].id = 3
        guestrecipe.tasks[0].results[0].id = 1
        recipe.tasks[0].results[0].id = 2
        recipe.tasks[1].results[0].id = 3

        expected_results_xml = pkg_resources.resource_string(
            'bkr.inttest', 'complete-job-results.xml')
        expected_results_xml = expected_results_xml.replace(
            '${BEAKER_SERVER_BASE_URL}', get_server_base())
        actual_results_xml = lxml.etree.tostring(job.to_xml(clone=False),
                                                 pretty_print=True,
                                                 encoding='utf8')
        self.assertMultiLineEqual(expected_results_xml, actual_results_xml)
Exemple #9
0
 def test_job_xml_can_be_roundtripped(self):
     # Ideally the logic for parsing job XML into a Job instance would live in model code,
     # so that this test doesn't have to go through the web layer...
     complete_job_xml = pkg_resources.resource_string('bkr.inttest', 'complete-job.xml')
     xmljob = XmlJob(xmltramp.parse(complete_job_xml))
     with session.begin():
         job = testutil.call(self.controller.process_xmljob, xmljob, self.user)
     roundtripped_xml = job.to_xml(clone=True).toprettyxml(indent='    ')
     self.assertMultiLineEqual(roundtripped_xml, complete_job_xml)
Exemple #10
0
 def calldefault(self,*args,**kwargs):
     import urllib
     args = list(args)
     location = args[0]
     method = args[1]
     parameters=urllib.urlencode(kwargs)
     print parameters 
     url = 'URL: /%s/%s?%s' % (location,method,parameters)
     print url
     return testutil.call(cherrypy.root.default,*args,**kwargs)
Exemple #11
0
 def test_job_xml_can_be_roundtripped(self):
     # Ideally the logic for parsing job XML into a Job instance would live in model code,
     # so that this test doesn't have to go through the web layer...
     complete_job_xml = pkg_resources.resource_string(
         'bkr.inttest', 'complete-job.xml')
     xmljob = lxml.etree.fromstring(complete_job_xml)
     job = testutil.call(self.controller.process_xmljob, xmljob, self.user)
     roundtripped_xml = lxml.etree.tostring(job.to_xml(clone=True),
                                            pretty_print=True,
                                            encoding='utf8')
     self.assertMultiLineEqual(roundtripped_xml, complete_job_xml)
Exemple #12
0
 def test_job_xml_can_be_roundtripped(self):
     # Ideally the logic for parsing job XML into a Job instance would live in model code,
     # so that this test doesn't have to go through the web layer...
     complete_job_xml = pkg_resources.resource_string(
         'bkr.inttest', 'complete-job.xml')
     xmljob = XmlJob(xmltramp.parse(complete_job_xml))
     with session.begin():
         job = testutil.call(self.controller.process_xmljob, xmljob,
                             self.user)
     roundtripped_xml = job.to_xml(clone=True).toprettyxml(indent='    ')
     self.assertMultiLineEqual(roundtripped_xml, complete_job_xml)
Exemple #13
0
 def test_preserves_arbitrary_XML_elements_in_namespace(self):
     complete_job_xml = pkg_resources.resource_filename('bkr.inttest', 'complete-job.xml')
     with open(complete_job_xml, 'r') as f:
         contents = f.read()
         xmljob = lxml.etree.fromstring(contents)
     job = testutil.call(self.controller.process_xmljob, xmljob, self.user)
     tree = job.to_xml(clone=True)
     self.assertEqual(2, len(tree.xpath('*[namespace-uri()]')))
     self.assertEqual('<b:option xmlns:b="http://example.com/bar">--foobar arbitrary</b:option>',
                      lxml.etree.tostring(tree.xpath('*[namespace-uri()]')[0], encoding='utf8'))
     self.assertEqual(u'<f:test xmlns:f="http://example.com/foo">unicode text: heißer Шис</f:test>'.encode('utf8'),
                      lxml.etree.tostring(tree.xpath('*[namespace-uri()]')[1], encoding='utf8'))
Exemple #14
0
    def test_complete_job_results(self):
        complete_job_xml = pkg_resources.resource_string('bkr.inttest', 'complete-job.xml')
        xmljob = lxml.etree.fromstring(complete_job_xml)
        job = testutil.call(self.controller.process_xmljob, xmljob, self.user)
        session.flush()

        # Complete the job, filling in values to match what's hardcoded in 
        # complete-job-results.xml...
        recipe = job.recipesets[0].recipes[0]
        guestrecipe = recipe.guests[0]
        data_setup.mark_recipe_running(recipe, fqdn=u'system.test-complete-job-results',
                start_time=datetime.datetime(2016, 1, 31, 23, 0, 0),
                install_started=datetime.datetime(2016, 1, 31, 23, 0, 1),
                install_finished=datetime.datetime(2016, 1, 31, 23, 0, 2),
                postinstall_finished=datetime.datetime(2016, 1, 31, 23, 0, 3),
                task_start_time=datetime.datetime(2016, 1, 31, 23, 0, 4))
        data_setup.mark_recipe_complete(guestrecipe, fqdn=u'guest.test-complete-job-results',
                mac_address='ff:ff:ff:00:00:00',
                start_time=datetime.datetime(2016, 1, 31, 23, 30, 0),
                install_started=datetime.datetime(2016, 1, 31, 23, 30, 1),
                install_finished=datetime.datetime(2016, 1, 31, 23, 30, 2),
                postinstall_finished=datetime.datetime(2016, 1, 31, 23, 30, 3),
                finish_time=datetime.datetime(2016, 1, 31, 23, 30, 4))
        data_setup.mark_recipe_complete(recipe, only=True,
                start_time=datetime.datetime(2016, 1, 31, 23, 0, 4),
                finish_time=datetime.datetime(2016, 1, 31, 23, 59, 0))
        recipe.installation.rendered_kickstart.url = u'http://example.com/recipe.ks'
        guestrecipe.installation.rendered_kickstart.url = u'http://example.com/guest.ks'
        session.flush()
        # Hack up the database ids... This will fail if it's flushed, but it's 
        # the easiest way to make them match the expected values.
        job.id = 1
        job.recipesets[0].id = 1
        recipe.id = 1
        guestrecipe.id = 2
        recipe.tasks[0].id = 1
        recipe.tasks[1].id = 2
        guestrecipe.tasks[0].id = 3
        guestrecipe.tasks[0].results[0].id = 1
        recipe.tasks[0].results[0].id = 2
        recipe.tasks[1].results[0].id = 3

        expected_results_xml = pkg_resources.resource_string('bkr.inttest', 'complete-job-results.xml')
        expected_results_xml = expected_results_xml.replace(
                '${BEAKER_SERVER_BASE_URL}', get_server_base())
        actual_results_xml = lxml.etree.tostring(job.to_xml(clone=False),
                pretty_print=True, encoding='utf8')
        self.assertMultiLineEqual(expected_results_xml, actual_results_xml)
Exemple #15
0
 def test_preserves_arbitrary_XML_elements_in_namespace(self):
     complete_job_xml = pkg_resources.resource_filename(
         'bkr.inttest', 'complete-job.xml')
     with open(complete_job_xml, 'r') as f:
         contents = f.read()
         xmljob = lxml.etree.fromstring(contents)
     job = testutil.call(self.controller.process_xmljob, xmljob, self.user)
     tree = job.to_xml(clone=True)
     self.assertEqual(2, len(tree.xpath('*[namespace-uri()]')))
     self.assertEqual(
         '<b:option xmlns:b="http://example.com/bar">--foobar arbitrary</b:option>',
         lxml.etree.tostring(tree.xpath('*[namespace-uri()]')[0],
                             encoding='utf8'))
     self.assertEqual(
         u'<f:test xmlns:f="http://example.com/foo">unicode text: heißer Шис</f:test>'
         .encode('utf8'),
         lxml.etree.tostring(tree.xpath('*[namespace-uri()]')[1],
                             encoding='utf8'))
Exemple #16
0
 def test_retrieve_dict_directly(self):
     d = testutil.call(cherrypy.root.returnjson)
     assert d["title"] == "Foobar"
Exemple #17
0
def test_add_new():
    """Testing to make sure an add with the new protocol works"""
    smoltProtocol = "0.97"
    UUID = "sheep!"
    OS = "Wintendo"
    platform = "Super Mario"
    bogomips = 2
    systemMemory = 640
    systemSwap = 640
    CPUVendor = "Death"
    CPUModel = "F00F"
    numCPUs = 0
    CPUSpeed = 0
    language = "Newspeak"
    defaultRunlevel = 6
    vendor = "eMachines"
    system = "reboot O'Matic"
    lsbRelease = "OOXML"
    formfactor = "skinny"
    kernelVersion = "NT"
    selinux_enabled = False
    selinux_policy = "Security?"
    vendor_id = 42
    device_id = 42
    subsys_vendor_id = 43
    subsys_device_id = 44
    bus = "the short one"
    driver = "santaclause"
    cls = "HEGEMONIC"
    description = '"It\'s hot enough to boil a monkey\'s bum!", the Prime Minister said, and her majesty smiled to herself'
    #She's a good sheila, and not at all stuckup
    
    host = {'uuid' :            "sheep!",
            'os' :              "Wintendo",
            'default_runlevel': 6,
            'language' :        "Newspeak",
            'platform' :        "Super Mario",
            'bogomips' :        2,
            'cpu_vendor' :      "Death",
            'cpu_model' :       "F00F",
            'num_cpus':         0,
            'cpu_speed' :       0,
            'system_memory' :   640,
            'system_swap' :     640,
            'vendor' :          "eMachines",
            'system' :          "reboot O'Matic",
            'kernel_version' :  "NT",
            'formfactor' :      "skinny",
            'selinux_enabled':  False,
            'selinux_policy':  "Security?"}
    device = [{"vendor_id": 42,
               "device_id": 42,
               "subsys_vendor_id": 43,
               "subsys_device_id": 44,
               "bus": "the short one",
               "driver": "santaclause",
               "type": "HEGEMONIC",
               "description": '"It\'s hot enough to boil a monkey\'s bum!", the Prime Minister said, and her majesty smiled to herself'}]
    #She's a good sheila, and not at all stuckup
    host["devices"] = device
    host['smolt_protocol'] = smoltProtocol
    host_json = simplejson.dumps(host)
    

    
    token_result = testutil.call(root.token_json, uuid = UUID)
    assert token_result["prefered_protocol"] == "0.97"
    token =  token_result['token']
    
    add_result = testutil.call(root.add_json, uuid=host['uuid'],
                               smolt_protocol=smoltProtocol,
                               token=token, host=host_json)
    
    test_host = Query(Host).selectone_by(uuid=UUID)
    assert test_host.uuid == UUID
    assert test_host.os == OS
    assert test_host.platform == platform
    assert test_host.cpu_model == CPUModel
    assert test_host.num_cpus == numCPUs
    assert test_host.cpu_speed == CPUSpeed
    assert test_host.language == language
    assert test_host.default_runlevel == defaultRunlevel
    assert test_host.vendor == vendor
    assert test_host.system == system
    assert test_host.formfactor == formfactor
    assert test_host.kernel_version == kernelVersion
    assert test_host.selinux_enabled == selinux_enabled
    assert test_host.selinux_policy == selinux_policy
    
    test_device = Query(ComputerLogicalDevice).selectone_by(description=description)
    
    assert test_device.description == description
    assert test_device.vendor_id == vendor_id
    assert test_device.device_id == device_id
    assert test_device.subsys_vendor_id == subsys_vendor_id
    assert test_device.subsys_device_id == subsys_device_id
    assert test_device.bus == bus
    assert test_device.driver == driver
    assert test_device.hardware_class.cls == cls
    
    test_host_link = Query(HostLink).select_by(device_id=test_device.id)[0]
    
    assert test_host_link.device_id == test_device.id
    assert test_host_link.host_link_id == test_host.id
    
    print "device: %s" % test_device.host_links
    print "host: %s" % test_host.devices
    print "link: %s" % test_host_link
    
    session.delete(test_host)
    session.flush()
    session.refresh(test_device)
    print "new device: %s" % test_device
    print test_device.host_links
    print test_device.id
    print test_device.description
    session.delete(test_device)
    session.flush()
Exemple #18
0
 def test_method(self):
     "the welcome method returns an empty dict"
     import types
     result = testutil.call(cherrypy.root.welcome)
     assert type(result) == types.DictType
Exemple #19
0
def test_add_old():
    "testing to make sure an add via the 0.91 protocol completes"
    UUID = "sheep!"
    OS = "Wintendo"
    platform = "Super Mario"
    bogomips = 2
    systemMemory = 640
    systemSwap = 640
    CPUVendor = "Death"
    CPUModel = "F00F"
    numCPUs = 0
    CPUSpeed = 0
    language = "Newspeak"
    defaultRunlevel = 6
    vendor = "eMachines"
    system = "reboot O'Matic"
    lsbRelease = "OOXML"
    formfactor = "Sparta!"
    kernelVersion = "NT"
    selinux_enabled = False
    selinux_policy = "Security?"
    smoltProtocol = ".91"
    
    token_result = testutil.call(root.token, uuid = UUID)
    assert token_result["prefered_protocol"] == ".91"
    token =  token_result['token']
    
    add_result = testutil.call(root.add, uuid = UUID, OS = OS, \
                               platform = platform, \
                               bogomips = bogomips, \
                               systemMemory = systemMemory, \
                               systemSwap = systemSwap, \
                               CPUVendor = CPUVendor, \
                               CPUModel = CPUModel, \
                               numCPUs = numCPUs, \
                               CPUSpeed = CPUSpeed, \
                               language = language, \
                               defaultRunlevel = defaultRunlevel, \
                               vendor = vendor, \
                               system = system, \
                               token = token, \
                               lsbRelease = lsbRelease, \
                               formfactor = formfactor, \
                               kernelVersion = kernelVersion, \
                               selinux_enabled = selinux_enabled, \
                               selinux_policy = selinux_policy, \
                               smoltProtocol = smoltProtocol)
    
    test_host = Query(Host).selectone_by(uuid=UUID)
    assert test_host.uuid == UUID
    assert test_host.os == OS
    assert test_host.platform == platform
    assert test_host.cpu_model == CPUModel
    assert test_host.num_cpus == numCPUs
    assert test_host.cpu_speed == CPUSpeed
    assert test_host.language == language
    assert test_host.default_runlevel == defaultRunlevel
    assert test_host.vendor == vendor
    assert test_host.system == system
    assert test_host.formfactor == formfactor
    assert test_host.kernel_version == kernelVersion
    assert test_host.selinux_enabled == selinux_enabled
    assert test_host.selinux_policy == selinux_policy
    
    vendor_id = 42
    device_id = 42
    subsys_vendor_id = 43
    subsys_device_id = 44
    bus = "the short one"
    driver = "santaclause"
    cls = "HEGEMONIC"
    description = '"It\'s hot enough to boil a monkey\'s bum!", the Prime Minister said, and her majesty smiled to herself'
    #She's a good sheila, and not at all stuckup
    device = "%s|%s|%s|%s|%s|%s|%s|%s" % (vendor_id,
                                          device_id,
                                          subsys_vendor_id,
                                          subsys_device_id,
                                          bus,
                                          driver,
                                          cls,
                                          description)
    device = "%s\n%s" % (device, device)
    addDevice_result = testutil.call(root.addDevices, uuid=UUID, Devices=device)
    
    test_device = Query(ComputerLogicalDevice).selectone_by(description=description)
    
    assert test_device.description == description
    assert test_device.vendor_id == vendor_id
    assert test_device.device_id == device_id
    assert test_device.subsys_vendor_id == subsys_vendor_id
    assert test_device.subsys_device_id == subsys_device_id
    assert test_device.bus == bus
    assert test_device.driver == driver
    assert test_device.hardware_class.cls == cls
    
    test_host_link = Query(HostLink).select_by(device_id=test_device.id)[0]
    
    assert test_host_link.device_id == test_device.id
    assert test_host_link.host_link_id == test_host.id
    
#    session.delete(test_host)
#    session.delete(test_device)
    session.flush()
Exemple #20
0
    def test_yyy(self):
        '''Running the whole application. The output can be found in devdata.sqlite for 
        further use'''

        #create Location
        result = self.calldefault('london','create_location',name='dublin')
        assert 'dublin' in testutil.call(cherrypy.root.listlocations)
        
        dublin = Location.byName('dublin')

        #create Groups
        for g in ['member','host','director']:
            result = self.calldefault('dublin',
                                      'create_group',
                                      group_name='dublin_' + g,
                                      display_name='Dublin ' +g,
                                      place=dublin.id,
                                      level = g)

        assert 'dublin_host' in  [l.group_name for l in Group.select()]
        
        #create Users
        users = ['host1','host2','member1','member2','director1','director2']
        for name in users:
            level = name[:-1]
            result = self.calldefault('dublin',
                                      'create_user',
                                      user_name=name,
                                      email_address='*****@*****.**' % name,
                                      display_name=name,
                                      password = '******',
                                      #groups = [Group.by_group_name('dublin_' + level).id],
                                      homeplace=dublin.id,
                                      billto=None)
            user = User.by_user_name(name)
            user.addGroup(Group.by_group_name('dublin_'+level))
        print 'Groups: ',user.groups
        assert 'member1' in [r.user_name for r in User.select()]

        

        #create Tariffs

        tariffs = ['tariff1000','tariff2000','tariff3000']
        for tariff in tariffs:
            result = self.calldefault('dublin',
                                      'create_resource',
                                      place = dublin.id,
                                      name=tariff,
                                      description='Tariff %s in dublin' % tariff,
                                      type='tariff')
         
        assert 'tariff2000' in [r.name for r in Resource.select()]


        #create Resources

        resources = ['printer1','printer2','hotdesk1','hotdesk2','room1','room2']
        for resource in resources:
            result = self.calldefault('dublin',
                                      'create_resource',
                                      place = dublin.id,
                                      name=resource,
                                      description='Resource %s in dublin' % resource,
                                      type=resource[:-1])
        assert 'printer2' in [r.name for r in Resource.select()]

        #create Prices
        
        pricestructure = [[3,2,1],[4,3,2],[5,4,3],[5,4,3],[10,9,8],[13,12,11]]
        
        for i in range(0,6):
            resourcename = resources[i]
            resource=Resource.selectBy(name=resourcename)[0]
            for j in range(0,3):
                self.calldefault('dublin',
                                 'create_pricing',
                                 tariff=Resource.selectBy(name=tariffs[j])[0].id,
                                 cost = pricestructure[i][j],
                                 resources=resource.id,
                                 time_based=resourcename.startswith('room'))


        #create Prices for tariffs

        for tariffname in tariffs:
            tariff = Resource.selectBy(name=tariffname)[0]
            self.calldefault('dublin',
                             'create_pricing',
                             tariff=tariff.id,
                             cost = int(tariffname[-4:-1])/3,
                             resources=tariff.id)

        #We are working with this user only at this time
        user = User.selectBy(user_name='member1')[0]


        from datetime import datetime
        now = datetime.now()
        #Book a tariff
        tariff = Resource.selectBy(name='tariff1000',place=dublin)[0]
        print 'Book a tariff for ', `user`
        print `tariff`
        result = self.calldefault('dublin',
                                 'book_tariff',
                                 userid=user.id,
                                 tariffid=tariff.id,
                                 year=now.year,
                                 month=now.month)


        #create Usage
       
        resource = Resource.selectBy(name='room1')[0]
        fmt = '%m/%d/%Y %H:%M:%S'
        result = self.calldefault('dublin',
                                    'create_rusage',
                                    user = user.id,
                                    resource=resource.id,
                                    start = datetime(now.year,now.month,20,10).strftime(fmt),
                                    end = datetime(now.year,now.month,20,12,30).strftime(fmt))

        resource = Resource.selectBy(name='printer1')[0]
        result = self.calldefault('dublin',
                                    'create_rusage',
                                    user = user.id,
                                    resource=resource.id,
                                    start = datetime(now.year,now.month,20,10).strftime(fmt),
                                    end = datetime(now.year,now.month,20,12,30).strftime(fmt))
        result = self.calldefault('dublin',
                                  'create_rusage',
                                  user = user.id,
                                  resource=resource.id,
                                  start = datetime(now.year,now.month,20,10).strftime(fmt),
                                  end = datetime(now.year, now.month,20,12,30).strftime(fmt))
        
        rusage = RUsage.get(result['id'])
        #rusage.cost = calculate_cost('dublin',rusage)
        #print `rusage`



        #result = self.calldefault('dublin',
        #                          'create_rusage',
        #                          user = user.id,
        #                          resource=tariff.id)

        


        #create new Invoice with unbilled invoices

        result = self.calldefault('dublin',
                                  'create_invoice',
                                  user = user.id,
                                  autocollect=True)

        invoice = Invoice.get(result['id'])
        
        print 'Invoice', `invoice.rusages`
        
        #Remove an rusage from an invoice

        result = self.calldefault('dublin',
                                  'remove_rusage_from_invoice',
                                  invoiceid=invoice.id,
                                  rusageid=rusage.id)

        print 'Invoice2', `invoice.rusages`

        #Add an rusage directly to the invoice

        result = self.calldefault('dublin',
                                  'create_rusage',
                                  user = user.id,
                                  resource = resource.id,
                                  invoice = invoice.id)
        print invoice.id
        print `RUsage.get(result['id'])`

        print 'Invoice3', `invoice.rusages`

        #create Todos
        result = self.calldefault('dublin',
                                  'create_todo',
                                  createdby=user.id,
                                  subject='Travel to Dublin')
        print `Todo.get(result['id'])`
Exemple #21
0
 def xtest_00010_setup_location(self):
     'Set up location Dublin'
     result = self.calldefault('london','create_location',name='dublin',currency='EUR')
     assert 'dublin' in testutil.call(cherrypy.root.listlocations)
Exemple #22
0
 def test_retrieveDictDirectly(self):
     d = testutil.call(cherrypy.root.returnjson)
     assert d["title"] == "Foobar"
Exemple #23
0
 def test_vienna3(self):
     'Test within test'
     self.test_vienna2()
     locations = testutil.call(cherrypy.root.listlocations)
     print locations
     assert 1
Exemple #24
0
 def test_vienna2(self):
     "Create vienna2"
     result = self.calldefault('london','create_location',name='vienna2')
     locations = testutil.call(cherrypy.root.listlocations)
     assert 'vienna2' in locations
Exemple #25
0
 def test_method(self):
     "the index method should return a string called now"
     import types
     result = testutil.call(cherrypy.root.index)
     assert type(result["now"]) == types.StringType
def test_method():
    "the index method should return a string called now"
    import types
    result = testutil.call(cherrypy.root.index)
    assert type(result["now"]) == types.StringType
Exemple #27
0
def test_list_controller():
    """list method should return a set of bookmark objects called bookmark."""
    cherrypy.root = Root()
    output=testutil.call(cherrypy.root.list)
    assert output.has_key('bookmark')