Exemple #1
0
    def Xtest_query_db_impact(self):
        self.assertNumQueries(0, lambda : mql.run("SELECT INSTANCES where name='GEP_DEV1_01_03'"))
        self.assertNumQueries(1, lambda : mql.run("SELECT INSTANCES where name='GEP_DEV1_01_03'").count())

        #self.assertNumQueries(2, lambda : mql.run("SELECT name FROM INSTANCES where name='GEP_DEV1_01_03'"))

        self.assertNumQueries(3, lambda : mql.run("SELECT name,group.name FROM INSTANCES where name='GEP_DEV1_01_03'"))
Exemple #2
0
    def test_pre_query(self):
        res = mql.run("SELECT offer 'soft1_webapp_ee6_jboss' INSTANCES")
        self.assertEqual(1, len(res))

        res2 = mql.run("SELECT lc 'web application EE6' INSTANCES")
        self.assertEqual(1, len(res2))

        self.assertEqual(res[0]['mage_id'], res2[0]['mage_id'])

        res3 = mql.run("SELECT lc 'web application EE6'  offer 'soft1_webapp_ee6_jboss' 'jbossapplication' INSTANCES")
        self.assertEqual(1, len(res3))
Exemple #3
0
    def Xtest_query_db_impact(self):
        self.assertNumQueries(
            0, lambda: mql.run("SELECT INSTANCES where name='GEP_DEV1_01_03'"))
        self.assertNumQueries(
            1, lambda: mql.run("SELECT INSTANCES where name='GEP_DEV1_01_03'").
            count())

        #self.assertNumQueries(2, lambda : mql.run("SELECT name FROM INSTANCES where name='GEP_DEV1_01_03'"))

        self.assertNumQueries(
            3, lambda: mql.
            run("SELECT name,group.name FROM INSTANCES where name='GEP_DEV1_01_03'"
                ))
Exemple #4
0
    def test_pre_query(self):
        res = mql.run("SELECT offer 'soft1_webapp_ee6_jboss' INSTANCES")
        self.assertEqual(1, len(res))

        res2 = mql.run("SELECT lc 'web application EE6' INSTANCES")
        self.assertEqual(1, len(res2))

        self.assertEqual(res[0]['mage_id'], res2[0]['mage_id'])

        res3 = mql.run(
            "SELECT lc 'web application EE6'  offer 'soft1_webapp_ee6_jboss' 'jbossapplication' INSTANCES"
        )
        self.assertEqual(1, len(res3))
Exemple #5
0
def mql_query(request, output_format, query):
    res = mql.run(query, return_sensitive_data = request.user.has_perm('ref.allfields_componentinstance'))

    if output_format == 'csv':
        response = HttpResponse(content_type='text/csv; charset=utf-8')
        response['Content-Disposition'] = 'attachment; filename="result.csv"'
        dd = {}
        for it in res:
            for k in it.keys():
                dd[k] = None
        wr = csv.DictWriter(response, fieldnames=dd.keys(), restval="", extrasaction='ignore', dialect='excel', delimiter=";")
        wr.writeheader()
        wr.writerows(res)
        return response
    
    if output_format == 'sh':
        return render(request, 'ref/mql_export_sh.html', {'instances': res}, content_type="text/plain")
    
    if output_format == 'bash4':
        return render(request, 'ref/mql_export_bash4.html', {'instances': res}, content_type="text/plain")
    
    if output_format == 'json':
        response = HttpResponse(content_type='text/json; charset=utf-8')
        json.dump(res, fp = response, ensure_ascii = False, indent= 4)
        return response
Exemple #6
0
def mql_tester(request):
    base = request.build_absolute_uri('/')[:-1]
    error = None
    if request.method == 'POST': # If the form has been submitted...
        form = MqlTesterForm(request.POST) # A form bound to the POST data
        if form.is_valid(): # All validation rules pass
            try:
                res = mql.run(form.cleaned_data['mql'], return_sensitive_data = request.user.has_perm('ref.allfields_componentinstance'))
                return render(request, 'ref/mql_tester.html', {'mql': form.cleaned_data['mql'], 'form': form, 'results': res, 'base': base})
            except Exception, e:
                error = e.__str__()
Exemple #7
0
def mql_tester(request):
    base = request.build_absolute_uri('/')[:-1]
    error = None
    if request.method == 'POST':  # If the form has been submitted...
        form = MqlTesterForm(request.POST)  # A form bound to the POST data
        if form.is_valid():  # All validation rules pass
            try:
                res = mql.run(form.cleaned_data['mql'],
                              return_sensitive_data=request.user.has_perm(
                                  'ref.allfields_componentinstance'))
                return render(
                    request, 'ref/mql_tester.html', {
                        'mql': form.cleaned_data['mql'],
                        'form': form,
                        'results': res,
                        'base': base
                    })
            except Exception, e:
                error = e.__str__()
Exemple #8
0
def mql_query(request, output_format, query):
    res = mql.run(query,
                  return_sensitive_data=request.user.has_perm(
                      'ref.allfields_componentinstance'))

    if output_format == 'csv':
        response = HttpResponse(content_type='text/csv; charset=utf-8')
        response['Content-Disposition'] = 'attachment; filename="result.csv"'
        dd = {}
        for it in res:
            for k in it.keys():
                dd[k] = None
        wr = csv.DictWriter(response,
                            fieldnames=dd.keys(),
                            restval="",
                            extrasaction='ignore',
                            dialect='excel',
                            delimiter=";")
        wr.writeheader()
        wr.writerows(res)
        return response

    if output_format == 'sh':
        return render(request,
                      'ref/mql_export_sh.html', {'instances': res},
                      content_type="text/plain")

    if output_format == 'bash4':
        return render(request,
                      'ref/mql_export_bash4.html', {'instances': res},
                      content_type="text/plain")

    if output_format == 'json':
        response = HttpResponse(content_type='text/json; charset=utf-8')
        json.dump(res, fp=response, ensure_ascii=False, indent=4)
        return response
Exemple #9
0
 def test_query_selector_simple(self):
     res = mql.run(
         "SELECT name,group.name,group.domain.name FROM 'jbossas' INSTANCES WHERE name='GEP_DEV1_01_03'"
     )
     self.assertEqual(1, len(res))
     self.assertEqual(res[0]['name'], 'GEP_DEV1_01_03')
Exemple #10
0
 def test_query_where_envt(self):
     res = mql.run("SELECT environment 'DEV1' 'jbossas' INSTANCES")
     self.assertEqual(1, len(res))
     self.assertEqual(self.i15_1_3._instance.id, res[0]['mage_id'])
Exemple #11
0
 def test_query_where_sub_id(self):
     res = mql.run("SELECT INSTANCES where group._id='%s'" %
                   self.i14_2._instance.id)
     self.assertEqual(1, len(res))
     self.assertEqual(self.i15_2_1._instance.id, res[0]['mage_id'])
Exemple #12
0
 def test_query_where_three_levels_two_predicates(self):
     res = mql.run(
         "SELECT 'jbossas' INSTANCES where group.domain.name='domain1' and name='GEP_DEV1_01_03'"
     )
     self.assertEqual(1, len(res))
Exemple #13
0
 def test_query_where_one_level_two_predicates(self):
     res = mql.run("SELECT INSTANCES where name='GEP_DEV1_01_03' and port_shift='0'")
     self.assertEqual(1, len(res))
Exemple #14
0
 def test_all_query(self):
     res = mql.run("SELECT instances")
     self.assertEqual(len(res), ComponentInstance.objects.all().count())
Exemple #15
0
 def test_query_where_subquery(self):
     res = mql.run("SELECT 'jbossas' INSTANCES where group.name=(SELECT name FROM INSTANCES WHERE name='GEP_DEV1_02')")
     self.assertEqual(1, len(res))
     self.assertEqual(self.i15_2_1._instance.id, res[0]['mage_id'])
Exemple #16
0
 def test_query_where_envt(self):
     res = mql.run("SELECT environment 'DEV1' 'jbossas' INSTANCES")
     self.assertEqual(1, len(res))
     self.assertEqual(self.i15_1_3._instance.id, res[0]['mage_id'])
Exemple #17
0
 def test_query_selector_simple(self):
     res = mql.run("SELECT name,group.name,group.domain.name FROM 'jbossas' INSTANCES WHERE name='GEP_DEV1_01_03'")
     self.assertEqual(1, len(res))
     self.assertEqual(res[0]['name'], 'GEP_DEV1_01_03')
Exemple #18
0
 def test_query_where_sub_id(self):
     res = mql.run("SELECT INSTANCES where group._id='%s'" % self.i14_2._instance.id)
     self.assertEqual(1, len(res))
     self.assertEqual(self.i15_2_1._instance.id, res[0]['mage_id'])
Exemple #19
0
 def test_query_where_three_levels_two_predicates(self):
     res = mql.run("SELECT 'jbossas' INSTANCES where group.domain.name='domain1' and name='GEP_DEV1_01_03'")
     self.assertEqual(1, len(res))
Exemple #20
0
 def test_query_where_two_levels_one_predicate(self):
     res = mql.run("SELECT 'jbossas' INSTANCES where group.name='GEP_DEV1_01'")
     self.assertEqual(3, len(res))
Exemple #21
0
 def test_query_where_subquery(self):
     res = mql.run(
         "SELECT 'jbossas' INSTANCES where group.name=(SELECT name FROM INSTANCES WHERE name='GEP_DEV1_02')"
     )
     self.assertEqual(1, len(res))
     self.assertEqual(self.i15_2_1._instance.id, res[0]['mage_id'])
Exemple #22
0
 def test_query_where_one_level_two_predicates(self):
     res = mql.run(
         "SELECT INSTANCES where name='GEP_DEV1_01_03' and port_shift='0'")
     self.assertEqual(1, len(res))
Exemple #23
0
 def test_all_query(self):
     res = mql.run("SELECT instances")
     self.assertEqual(len(res), ComponentInstance.objects.all().count())
Exemple #24
0
 def test_query_where_two_levels_one_predicate(self):
     res = mql.run(
         "SELECT 'jbossas' INSTANCES where group.name='GEP_DEV1_01'")
     self.assertEqual(3, len(res))
Exemple #25
0
 def test_query_where_one_level_one_predicate(self):
     res = mql.run("SELECT INSTANCES where name='GEP_DEV1_01_03'")
     self.assertEqual(1, len(res))
Exemple #26
0
 def test_query_where_one_level_one_predicate(self):
     res = mql.run("SELECT INSTANCES where name='GEP_DEV1_01_03'")
     self.assertEqual(1, len(res))