Beispiel #1
0
 def test_get_sites(self):
     # Get Site objects array, [Site, Site, Site...]
     dao = SiteDAO()
     self._register_node(dao)
     
     sites = dao.get_sites()
     self.assertEqual(len(sites), 1)
     self.assertEqual(len(sites['site1'].nodes.keys()), 1)
Beispiel #2
0
def show_site(request):
    dao = SiteDAO()
    site = dao.get_site(request.matchdict['site'])
    
    if not site:
        msg = 'Unable to find site "{0}"'.format(request.matchdict['site'])
        raise HTTPNotFound(msg)

    return { 'site': site, 'site_json': dumps(site) }
Beispiel #3
0
def deploy_application(request):
    try:
        dao = SiteDAO()
        site = dao.get_site(request.POST['site'])
        app = site.applications[request.POST['application']]
        app.deploy_application(site)

        return dumps({ 'success': True, 'app': app })
    except KeyError as e:
        msg = 'Unable to deploy application under "{0}"'
        msg = msg.format(request.POST['site'], request.POST['application'])
        
        return dumps({ 'success': False, 'msg': msg })
Beispiel #4
0
def tag_application(request):
    try:
        dao = SiteDAO()
        site = dao.get_site(request.POST['site'])
        app = site.applications[request.POST['application']]
        app.tag(request.POST['tag'], request.POST['msg'])
        
        return dumps({ 'success': True, 'app': app })
    except KeyError as e:
        msg = 'Unable to tag site and application under "{0}" and "{1}"'
        msg = msg.format(request.POST['site'], request.POST['application'])
        
        return dumps({ 'success': False, 'msg': msg })
Beispiel #5
0
 def test_all_site_keys(self):
     dao = SiteDAO()
     
     node = {
         'name': 'node1',
         'site': 'site1',
         'url' : 'http://node1'
     }
     
     dao.register_node(node)
     keys = dao._all_site_keys()
     
     self.assertEqual(keys[0], 'site:site1')
Beispiel #6
0
 def test_register_node(self):
     site = 'site1'
     
     node1 = {
         'name': 'node1',
         'site': site,
         'url' : 'http://node1'
     }
     
     node2 = {
         'name': 'node2',
         'site': site,
         'url' : 'http://node2'
     }
     
     dao = SiteDAO()
     dao.register_node(node1)
     dao.register_node(node2)
     
     self.assertEqual(len(dao.nodes(site).keys()), 2)
     
     node3 = {
         'name': 'node3',
         'site': site,
         'url' : 'http://node3'
     }
     
     dao.register_node(node3)
     
     self.assertEqual(len(dao.nodes(site).keys()), 3)
Beispiel #7
0
def show_application(request):
    try:
        dao = SiteDAO()
        site = dao.get_site(request.matchdict['site'])
        app = site.applications[request.matchdict['application']]

        if take_note(request, app):
            app.add_note(request.POST['note'])

    except:
        if 'note' in request.POST:
            msg = 'Unable to add note to "{0}"'
            msg = msg.format(request.matchdict['application'])
        else:
            msg = 'Unable to find site and application under "{0}" and "{1}"'
            msg = msg.format(request.matchdict['site'], request.matchdict['application'])

        raise HTTPNotFound(msg)
    

    return { 'site': site, 'app': app }
Beispiel #8
0
    def test_unregister_node(self):
        node1 = {
            'name': 'node1',
            'site': 'site1',
            'url' : 'http://node1'
        }

        dao = SiteDAO()
        dao.register_node(node1)

        self.assertEqual(len(dao.nodes('site1').keys()), 1)

        dao.unregister_node(node1)
        self.assertEqual(len(dao.nodes('site1').keys()), 0)

        sites = dao.get_sites()
        self.assertEqual(len(sites.keys()), 0)
Beispiel #9
0
def show_sites(request):
    dao = SiteDAO()
    
    return { 'sites': dao.get_sites() }
Beispiel #10
0
 def test_register_node_two(self):
     # Make sure we don't return an unknown site
     dao = SiteDAO()
     nodes = dao.nodes('unknown site')
     self.assertEqual(len(nodes), 0)