Example #1
0
    def return_root_id_for_vcs_root_name(self, name):
        """ Return the vcs root ID given its name.
        INPUT
            name: name of the vcs root.
        OUTPUT
            id: the id of the vcs root.
        """

        self.log.debug('Returning root id for vcs root %s ...' % name)
        result = {'successful': False, 'id': None}

        try:
            # determine module id
            table = DB_TABLES['modules']
            return_field = MODULE_FIELDS['name']
            known_field = MODULE_FIELDS['id']
            known_value = name
            result['name'] = self.query_database_table_for_single_value(self.db_handle,
                                                                        table, return_field, known_field, known_value)['value']

            self.log.trace("Returned module name.")
            result['successful'] = True
        except BaseException, e:
            self.log.error("Failed to return module name.")
            self.log.error(str(e))
            self.log.error("Error: %s." % return_execution_error()['error'])
Example #2
0
    def return_feature_id(self, name):
        """ Return the feature id given its name.
        INPUT
            name: the name of the feature.
        OUTPUT
            id: id of the feature.
        """

        self.log.debug('Returning ID for feature "%s" ...' % name)
        result = {'successful': False, 'id': None}

        try:
            # determine feature id
            table = DB_TABLES['features']
            return_field = FEATURE_FIELDS['id']
            known_field = FEATURE_FIELDS['name']
            known_value = name
            result['id'] = self.query_database_table_for_single_value(self.db_handle,
                table, return_field, known_field, known_value)['value']

            self.log.trace("Returned feature ID.")
            result['successful'] = True
        except BaseException, e:
            self.log.error("Failed to return feature ID.")
            self.log.error(str(e))
            self.log.error("Error: %s." % return_execution_error()['error'])
Example #3
0
    def return_testcase_id(self, name, test_id):
        """ Return the test case id given its name and test id.
        INPUT
            name: the name of the test case.
            test ID: the id of the parent test.
        OUTPUT
            id: id of the test case.
        """

        self.log.debug('Returning ID for test case "%s" ...' % name)
        result = {'successful': False, 'id': None}

        try:
            # determine test case id
            table = DB_TABLES['testcases']
            return_field = TESTCASE_FIELDS['id']
            addendum = 'WHERE %s = "%s" AND %s = "%s"' % (TESTCASE_FIELDS['name'], name,
                                                          TESTCASE_FIELDS['test'], test_id)
            response =\
            result['id'] = self.query_database_table(self.db_handle, table, return_field=return_field,
                addendum=addendum)['response'][0][0]

            self.log.trace("Returned test case ID.")
            result['successful'] = True
        except BaseException, e:
            self.log.error("Failed to return test case ID.")
            self.log.error(str(e))
            self.log.error("Error: %s." % return_execution_error()['error'])
Example #4
0
    def return_user_story_id(self, action):
        """ Return the story id given its action.
        INPUT
            name: the action of the user story.
        OUTPUT
            id: id of the user story.
        """

        self.log.debug('Returning user story ID for user story "%s" ...' % action)
        result = {'successful': False, 'id': None}

        try:
            # determine user story id
            table = DB_TABLES['user stories']
            return_field = USERSTORY_FIELDS['id']
            known_field = USERSTORY_FIELDS['action']
            known_value = action
            result['id'] = self.query_database_table_for_single_value(self.db_handle,
                table, return_field, known_field, known_value)['value']

            self.log.trace("Returned story ID.")
            result['successful'] = True
        except BaseException, e:
            self.log.error("Failed to return story ID.")
            self.log.error(str(e))
            self.log.error("Error: %s." % return_execution_error()['error'])
Example #5
0
    def return_submodule_data(self, id):
        """ Return the submodule data given its id.
        INPUT
            id: id of the module.
        OUTPUT
            data: data dict of the submodule.
        """

        self.log.debug('Returning data for submodule %s ...' % id)
        result = {'successful': False, 'data': None}

        try:
            # determine module id
            table = DB_TABLES['submodules']
            known_field = SUBMODULE_FIELDS['id']
            known_value = id
            addendum = "WHERE %s = '%s'" % (known_field, known_value)
            result['data'] = self.query_database_table(self.db_handle,
                table, addendum=addendum)['value']

            self.log.trace("Returned submodule data.")
            result['successful'] = True
        except BaseException, e:
            self.log.error("Failed to return submodule data.")
            self.log.error(str(e))
            self.log.error("Error: %s." % return_execution_error()['error'])
Example #6
0
    def return_submodule_for_module(self, module_id):
        """ Return the module id given its name.
        INPUT
            module id: the id of the module.
        OUTPUT
            id: id of the submodule.
        """

        self.log.debug('Returning submodule ID for module %s ...' % module_id)
        result = {'successful': False, 'id': None}

        try:
            # determine module id
            table = DB_TABLES['modules']
            return_field = MODULE_FIELDS['submodule']
            known_field = MODULE_FIELDS['id']
            known_value = module_id
            result['id'] = self.query_database_table_for_single_value(self.db_handle,
                table, return_field, known_field, known_value)['value']

            self.log.trace("Returned submodule ID.")
            result['successful'] = True
        except BaseException, e:
            self.log.error("Failed to return submodule ID.")
            self.log.error(str(e))
            self.log.error("Error: %s." % return_execution_error()['error'])
Example #7
0
    def return_dvr_data(self, dvr_id, testcase=None):
        """
        INPUT
            dvr id: the id of the DVR.
            testcase: a testcase object supplied when executing function as part of a testcase step.
        OUPUT
            successful: whether the function executed successfully or not.
            dvr data: the data returned for the site.
        """

        self.log.debug("Returning DVR data for %s ..." % dvr_id)
        result = {'successful': False, 'dvr data': {}}

        try:
            # query database for site data
            table = DB_TABLES['dvrs']
            addendum = 'WHERE %s = "%s"' % (DVR_FIELDS['id'], dvr_id)
            response =\
            self.query_database_table(self.db_handle, table, addendum=addendum)['response']
            # parse response into data dictionary for configuration
            dvr_data = {}
            fields = DVR_FIELDS.keys()
            values = list(response[0])
            for i in range(len(values)):
                try: dvr_data[fields[i]] = int(values[i])
                except ValueError: dvr_data[fields[i]] = str(values[i])
                except TypeError: dvr_data[fields[i]] = None
            result['dvr data'] = dvr_data

            self.log.trace("Returned DVR data for %s." % dvr_id)
            result['successful'] = True
        except BaseException, e:
            self.log.error("Failed to return DVR data for %s." % dvr_id)
            self.log.error(str(e))
            self.log.error("Error: %s." % return_execution_error()['error'])
Example #8
0
    def return_license_configuration(self, name, testcase=None):
        """
        INPUT
            name: the name of the license configuration.
            testcase: a testcase object supplied when executing function as part of a testcase step.
        OUPUT
            successful: whether the function executed successfully or not.
            configuration: the configuration data returned.
        """

        self.log.debug("Returning license configuration for %s license ..." % name)
        result = {'successful': False, 'configuration': {}}

        try:
            # query database for license configuration
            table = DB_TABLES['licenses']
            addendum = 'WHERE %s = "%s"' % (LICENSE_FIELDS['name'], name)
            response =\
            self.query_database_table(self.db_handle, table, addendum=addendum)['response']
            # parse response into data dictionary for configuration
            license_data = {}
            fields = LICENSE_FIELDS.keys()
            values = list(response[0])
            for i in range(len(values)):
                try: license_data[fields[i]] = int(values[i])
                except ValueError: license_data[fields[i]] = str(values[i])
            result['configuration'] = license_data

            self.log.trace("Returned license configuration for %s license." % name)
            result['successful'] = True
        except BaseException, e:
            self.log.error("Failed to return license configuration for %s license." % name)
            self.log.error(str(e))
            self.log.error("Error: %s." % return_execution_error()['error'])
Example #9
0
    def return_module_for_test(self, test_id):
        """ Return the module id of a test given its id.
        INPUT
            test ID: the id of the test.
        OUTPUT
            id: id of the parent module.
        """

        self.log.debug('Returning module ID for test %s ...' % test_id)
        result = {'successful': False, 'id': None}

        try:
            # determine user story
            story_id = self.return_user_story_for_test(test_id)['id']

            # determine module
            module_id = self.return_module_for_user_story(story_id)['id']

            result['id'] = module_id

            self.log.trace("Returned module ID.")
            result['successful'] = True
        except BaseException, e:
            self.log.error("Failed to return module ID.")
            self.log.error(str(e))
            self.log.error("Error: %s." % return_execution_error()['error'])
Example #10
0
    def return_user_story_for_test(self, test_id):
        """ Return the user story id of a test given its id.
        INPUT
            test ID: the id of the test.
        OUTPUT
            id: id of the parent user story.
        """

        self.log.debug('Returning user story ID for test %s ...' % test_id)
        result = {'successful': False, 'id': None}

        try:
            # determine module id
            table = DB_TABLES['tests']
            return_field = TEST_FIELDS['user story']
            known_field = TEST_FIELDS['id']
            known_value = test_id
            result['id'] = self.query_database_table_for_single_value(self.db_handle,
                table, return_field, known_field, known_value)['value']

            self.log.trace("Returned user story ID.")
            result['successful'] = True
        except BaseException, e:
            self.log.error("Failed to return user story ID.")
            self.log.error(str(e))
            self.log.error("Error: %s." % return_execution_error()['error'])
Example #11
0
    def return_feature_for_user_story(self, story_id):
        """ Return the feature id of a user story given its id.
        INPUT
            story ID: the id of the user story.
        OUTPUT
            id: id of the parent feature.
        """

        self.log.debug('Returning feature ID for user story %s ...' % story_id)
        result = {'successful': False, 'id': None}

        try:
            # determine module id
            table = DB_TABLES['user stories']
            return_field = USERSTORY_FIELDS['feature']
            known_field = USERSTORY_FIELDS['id']
            known_value = story_id
            result['id'] = self.query_database_table_for_single_value(self.db_handle,
                table, return_field, known_field, known_value)['value']

            self.log.trace("Returned feature ID.")
            result['successful'] = True
        except BaseException, e:
            self.log.error("Failed to return feature ID.")
            self.log.error(str(e))
            self.log.error("Error: %s." % return_execution_error()['error'])
Example #12
0
    def return_features_for_submodule(self, submodule_id):
        """ Return all features.
        OUTPUT
            features: list of features {id, name}.
        """

        self.log.debug("Returning features for submodule %s ..." % submodule_id)
        result = {'successful': False, 'features': []}

        try:
            # query database for all features
            table = DB_TABLES['features']
            addendum = 'WHERE %s = "%s"' % (FEATURE_FIELDS['submodule'], submodule_id)
            response =\
            self.query_database_table(self.db_handle, table, addendum=addendum)['response']

            # add response items to modules list
            for item in response:
                result['features'].append({'id': item[0], 'name': str(item[1])})

            self.log.trace("Returned features.")
            result['successful'] = True
        except BaseException, e:
            self.log.error("Failed to return features.")
            self.log.error(str(e))
            self.log.error("Error: %s." % return_execution_error()['error'])
            result['successful'] = False
Example #13
0
    def return_procedure_step_data(self, procedure_step_id):
        """ Return data for procedure step with given ID.
        INPUT
            procedure_step_id: the id of the procedure step for which to return data.
        OUTPUT
            data: dictionary of data returned for procedure step from database.
        """

        self.log.debug("Returning data for procedure step %s ..." % procedure_step_id)
        result = {'successful': False, 'step data': {}, 'function data': {},
                  'submodule data': {}}

        try:
            # query database for procedure step
            table = DB_TABLES['procedure steps']
            addendum = 'WHERE %s = "%s"' % (STEP_FIELDS['id'], procedure_step_id)
            response =\
            self.query_database_table(self.db_handle, table, addendum=addendum)['response']
            # parse response into data dictionary for procedure step
            step_data = {}
            fields = STEP_FIELDS.keys()
            values = list(response[0])
            for i in range(len(values)):
                step_data[fields[i]] = values[i]
            result['step data'] = step_data

            # query database for procedure step
            table = DB_TABLES['functions']
            addendum = 'WHERE %s = "%s"' % (FUNCTION_FIELDS['id'], step_data['function'])
            response =\
            self.query_database_table(self.db_handle, table, addendum=addendum)['response']
            # parse response into data dictionary for procedure step
            function_data = {}
            fields = FUNCTION_FIELDS.keys()
            values = list(response[0])
            for i in range(len(values)):
                function_data[fields[i]] = values[i]
            result['function data'] = function_data

            # query database for procedure step
            table = DB_TABLES['submodules']
            addendum = 'WHERE %s = "%s"' % (SUBMODULE_FIELDS['id'], function_data['submodule id'])
            response =\
            self.query_database_table(self.db_handle, table, addendum=addendum)['response']
            # parse response into data dictionary for procedure step
            submodule_data = {}
            fields = SUBMODULE_FIELDS.keys()
            values = list(response[0])
            for i in range(len(values)):
                submodule_data[fields[i]] = values[i]
            result['submodule data'] = submodule_data

            self.log.trace("Returned procedure step data.")
            result['successful'] = True
        except BaseException, e:
            self.log.error("Failed to return procedure step data.")
            self.log.error(str(e))
            self.log.error("Error: %s." % return_execution_error()['error'])
            result['successful'] = False
Example #14
0
    def handle_exception(self, e, operation=None):
        """ Handle an exception.
        INPUT
            e: the exception (from BaseException, e).
            operation: the action being attempted (that failed).
        """

        if operation is not None: self.log.error("Failed to %s." % operation)
        self.log.error(str(e))
        self.log.error("Error: %s." % return_execution_error()['error'])
Example #15
0
def handle_exception(log, e, operation=None):
        """ Handle an exception.
        INPUT
            e: the exception (from BaseException, e).
            operation: the action being attempted (that failed).
        """

        if operation is not None: log.error("Failed to %s." % operation)
        log.error(str(e))
        for error in e:
            log.error(str(error))
        exception = return_execution_error()['error']
        log.error("Error: %s." % exception)
Example #16
0
    def return_testcases_for_test(self, test, story_id=None):
        """ Return all testcases for given test.
        INPUT
            test_id: the id of the test for which to return all testcases.
            story_id: the id of the parent story (needed if using test name).
        OUTPUT
            testcases: list of testcases {id, name, test id}.
        """

        self.log.debug("Returning testcases for test %s ..." % test)
        result = {'successful': False, 'testcases': []}

        # determine if test name or id given
        try:
            test_id = int(test)
            test_name = None
        except BaseException:
            test_name = str(test)
            test_id = None

        # determine test id if needed
        if test_id is None:
            test_id = self.return_test_id(test_name, story_id)

        try:
            # query database for all testcases associated with test
            table = DB_TABLES['testcases']
            addendum = 'WHERE %s = "%s"' % (TESTCASE_FIELDS['test'], test_id)
            response =\
            self.query_database_table(self.db_handle, table, addendum=addendum)['response']

            # parse response into data dictionary for testcase
            for i in range(len(response)):
                testcase_data = {}
                fields = TESTCASE_FIELDS.keys()
                values = list(response[i])
                for j in range(len(values)):
                    testcase_data[fields[j]] = values[j]
                testcase_data['test id'] = testcase_data['test']
                # add response items to modules list
                result['testcases'].append(testcase_data)

            self.log.trace("Returned testcases.")
            result['successful'] = True
        except BaseException, e:
            self.log.error("Failed to return testcases.")
            self.log.error(str(e))
            self.log.error("Error: %s." % return_execution_error()['error'])
            result['successful'] = False
Example #17
0
    def return_modules_for_submodule(self, submodule):
        """ Return all modules for submodule.
        INPUT:
            submodule: either the name or id of the submodule.
        OUTPUT
            modules: list of modules {id, name}.
        """

        self.log.debug("Returning modules for submodule %s ..." % submodule)
        result = {'successful': False, 'modules': []}

        # determine if submodule name or id given
        try:
            submodule_id = int(submodule)
            submodule_name = None
        except BaseException:
            submodule_name = str(submodule)
            submodule_id = None


        # determine submodule id if needed
        if submodule_id is None:
            table = DB_TABLES['submodules']
            return_field = SUBMODULE_FIELDS['id']
            known_field = SUBMODULE_FIELDS['name']
            known_value = submodule_name
            module_id = self.query_database_table_for_single_value(self.db_handle,
                table, return_field, known_field, known_value)['value']

        try:
            # query database for all modules associated with submodule
            table = DB_TABLES['modules']
            addendum = 'WHERE %s = "%s"' % (MODULE_FIELDS['submodule'], submodule_id)
            response =\
            self.query_database_table(self.db_handle, table, addendum=addendum)['response']

            # add response items to modules list
            for item in response:
                result['modules'].append({'id': item[0], 'name': str(item[1]), 'submodule id': item[2]})

            self.log.trace("Returned modules.")
            result['successful'] = True
        except BaseException, e:
            self.log.error("Failed to return modules.")
            self.log.error(str(e))
            self.log.error("Error: %s." % return_execution_error()['error'])
            result['successful'] = False
Example #18
0
    def return_tests_for_user_story(self, story):
        """ Return all tests for given user story.
        INPUT
            story: either the id or name of the user story for which to return all tests.
        OUTPUT
            tests: list of tests {id, name, user story id}.
        """

        self.log.debug("Returning tests for user story %s ..." % story)
        result = {'successful': False, 'tests': []}

        # determine if user story name or id given
        try:
            story_id = int(story)
            story_name = None
        except BaseException:
            story_name = str(story)
            story_id = None

        # determine user story id if needed
        if story_id is None:
            story_id = self.return_user_story_id(story_name)['id']

        try:
            # query database for all tests associated with user story
            table = DB_TABLES['tests']
            addendum = 'WHERE %s = "%s"' % (TEST_FIELDS['user story'], story_id)
            response =\
            self.query_database_table(self.db_handle, table, addendum=addendum)['response']

            # add response items to modules list
            for item in response:
                result['tests'].append({'id': item[0], 'name': str(item[1]),
                                        'user story id': item[2]})

            self.log.trace("Returned tests.")
            result['successful'] = True
        except BaseException, e:
            self.log.error("Failed to return tests.")
            self.log.error(str(e))
            self.log.error("Error: %s." % return_execution_error()['error'])
            result['successful'] = False
Example #19
0
    def get_http_request(self, url, testcase=None):
        """
        INPUT
            url: the full url to make the get request from.
            testcase: a testcase object supplied when executing function as part of a testcase step.
        OUPUT
            successful: whether the function executed successfully or not.
        """

        self.log.debug("Making GET request to server:\t%s ..." % url)
        result = {'successful': False, 'response': None, 'time': None}

        try:
            # begin timing
            t0 = clock()

            attempt = 1
            max_attempts = 5
            while result['response'] is None and attempt <= max_attempts:
                # make the request (and strip of whispace)
                try: result['response'] = urlopen(url).read().strip()
                except HTTPError, e:
                    self.log.trace("Failed to make GET request to server due to HTTP error.")
                    self.log.trace(str(e))
                    # check for 404 Not Found error
                    if str(e).split(':')[0] == 'HTTP Error 404':
                        result['response'] = 'HTTP Error 404'
                    else:
                        for error in e:
                            self.log.trace(str(error))
                    exception = return_execution_error()['error']
                    self.log.trace("Error: %s." % exception)
                    break
                except URLError, e:
                    self.log.trace(e)
                    self.log.trace("Server may have crashed or failed to start. Checking ...")
                    running = self.check_if_vim_server_is_running()
                    if running['service'] or running['process']:
                        self.start_vim_server()
                        self.log_in_to_vim()
                    attempt += 1
Example #20
0
    def return_functions(self):
        """ Return all functions.
        OUTPUT
            functions: list of functions {id, name, submodule id}.
        """

        self.log.debug("Returning functions ...")
        result = {'successful': False, 'functions': []}

        try:
            # query database for all Functions table entries
            table = DB_TABLES['functions']
            response = self.query_database_table(self.db_handle, table)['response']

            # add response items to modules list
            for item in response:
                result['functions'].append({'id': item[0], 'name': str(item[1]),
                                            'submodule id': str(item[2])})
        except BaseException, e:
            self.log.error("Failed to return functions.")
            self.log.error(str(e))
            self.log.error("Error: %s." % return_execution_error()['error'])
Example #21
0
    def on_add_lic_testcases_button_click(self, event):
        """ Action performed when user clicks the add licensing testcases button.
        NOTE: Only handles procedures with configure licensing step as
            second step. Template procedure must be established in UI, as well as
            results ID (can update results ID from a previously added validation test).
        """

        LICENSE_TYPES = ['Demo', 'Basic', 'Full', 'Autoclip', 'Health', 'Clip management', 'Location']

        self.log.trace("Handling add licensing testcase button click by user ...")
        result = {'successful': False}

        # flag for adding licensing tests
        self.add_lic = True

        try:
            # determine results ID from input field
            self.log.trace("Getting string from testcase results ID input field ...")
            results_id = self.determine_results_id_from_input_field()['results id']

            # determine test path from input fields
            data = self.determine_test_path_from_input_fields()
            module_name = data['module']
            feature_name = data['feature']
            story_name = data['user story']
            test_name = 'Licensing'

            # determine the test id from test path
            test_id = self.determine_test_id_from_test_path(module_name, feature_name, story_name,
                test_name, results_id)['test id']

            # hard-coded class
            testcase_class = '4'

            # determine minimum version
            minversion = self.input_minversion.GetString(0, -1)

            # determine template procedure
            procedure = self.determine_procedure_from_inputs()['procedure']

            for lic_type in LICENSE_TYPES:
                # case name per license type
                case_name = lic_type

                # rebuild procedure
                procedure = self.rebuild_procedure_with_lic_config(procedure, lic_type)['procedure']

                # evaluate mimimum version
                if lic_type.lower() == 'location' and float(minversion) < 3.4:
                    minversion = 3.4

                self.modify_testcase(case_name, test_id, procedure, minversion, testcase_class)

                self.log.trace("Handled add licensing testcases button click by user.")
            result['successful'] = True
        except BaseException, e:
            self.log.error("Failed to handle add licensing testcases button click by user.")
            self.log.error(str(e))
            for error in e:
                self.log.error(str(error))
            exception = return_execution_error()['error']
            self.log.error("Error: %s." % exception)
Example #22
0
    def return_user_stories_for_feature(self, feature, module=None):
        """ Return all user stories for given feature.
        INPUT
            feature: either the id or name of the feature for which to return all user stories.
            module: optional name of the module of the feature (for multi-module features).
        OUTPUT
            user stories: list of user stories {id, name, feature id}.
        """

        self.log.debug("Returning user stories for feature %s ..." % feature)
        result = {'successful': False, 'user stories': []}

        # determine if feature name or id given
        try:
            feature_id = int(feature)
            feature_name = None
        except BaseException:
            feature_name = str(feature)
            feature_id = None

        # return module id for name (if given)
        try:
            module_id = int(module)
        except BaseException:
            module_id = None

        if module is not None and module_id is None:
            table = DB_TABLES['modules']
            return_field = MODULE_FIELDS['id']
            known_field = MODULE_FIELDS['name']
            known_value = module
            module_id = self.query_database_table_for_single_value(self.db_handle,
                table, return_field, known_field, known_value)['value']

        # determine feature id if needed
        if feature_id is None:
            table = DB_TABLES['features']
            return_field = FEATURE_FIELDS['id']
            known_field = FEATURE_FIELDS['name']
            known_value = feature_name

            feature_id = self.query_database_table_for_single_value(self.db_handle,
                table, return_field, known_field, known_value)['value']

        try:
            # query database for all user stories associated with feature
            table = DB_TABLES['user stories']
            if module_id is not None:
                addendum = 'WHERE %s = "%s" AND %s = "%s"' % (USERSTORY_FIELDS['feature'],
                                                              feature_id, USERSTORY_FIELDS['module'],
                                                              module_id)
            else:
                addendum = 'WHERE %s = "%s"' % (USERSTORY_FIELDS['feature'], feature_id)

            response =\
            self.query_database_table(self.db_handle, table, addendum=addendum)['response']

            # add response items to modules list
            for item in response:
                result['user stories'].append({'id': item[0], 'action': str(item[3]),
                                               'module id': item[2], 'feature id': item[1],
                                               'user type': str(item[4])})

            self.log.trace("Returned user stories.")
            result['successful'] = True
        except BaseException, e:
            self.log.error("Failed to return user stories.")
            self.log.error(str(e))
            self.log.error("Error: %s." % return_execution_error()['error'])
            result['successful'] = False
Example #23
0
    def return_features_for_module(self, module):
        """ Return all features for given module.
        INPUT
            module: either the id or name of the module for which to return all features.
        OUTPUT
            features: list of features {id, name, module id}.
        """

        self.log.debug("Returning features for module %s ..." % module)
        result = {'successful': False, 'features': []}

        # determine if module name or id given
        try:
            module_id = int(module)
            module_name = None
        except BaseException:
            module_name = str(module)
            module_id = None

        # determine module id if needed
        if module_id is None:
            table = DB_TABLES['modules']
            return_field = MODULE_FIELDS['id']
            known_field = MODULE_FIELDS['name']
            known_value = module_name
            module_id = self.query_database_table_for_single_value(self.db_handle,
                table, return_field, known_field, known_value)['value']

        try:
            # query database for all features that share a user story with the module
            table = DB_TABLES['user stories']
            addendum = 'WHERE %s = "%s"' % (USERSTORY_FIELDS['module'], module_id)
            response =\
                self.query_database_table(self.db_handle, table, addendum=addendum)['response']

            # create a list of unique feature ids from query response
            feature_ids = []
            for item in response:
                feature_id = item[1]
                if feature_id not in feature_ids:
                    feature_ids.append(feature_id)

            # query database for all features for the module and build list of feature data
            for feature_id in feature_ids:
                table = DB_TABLES['features']
                addendum = 'WHERE %s = "%s"' % (FEATURE_FIELDS['id'], feature_id)
                response =\
                    self.query_database_table(self.db_handle, table, addendum=addendum)['response']

                # add response items to features list
                if len(response) > 0:
                    result['features'].append({'id': response[0][0], 'name': str(response[0][1]),
                                               'submodule': response[0][2]})

            self.log.trace("Returned features.")
            result['successful'] = True
        except BaseException, e:
            self.log.error("Failed to return features.")
            self.log.error(str(e))
            self.log.error("Error: %s." % return_execution_error()['error'])
            result['successful'] = False
Example #24
0
    def return_testcase_data(self, testcase_id):
        """ Return data for testcase with given ID.
        INPUT
            testcase_id: the id of the testcase for which to return data.
        OUTPUT
            testcase data: dictionary of data returned for testcase from database.
            test data: dictionary of data returned for test from database.
            user story data: dictionary of data returned for user story from database.
            feature data: dictionary of data returned for feature from database.
            module data: dictionary of data returned for module from database.
        """

        self.log.debug("Returning data for testcase %s ..." % testcase_id)
        result = {'successful': False, 'testcase data': {}, 'test data': {}, 'user story data': {},
                  'feature data': {}, 'module data': {}}

        try:
            # query database for testcase
            table = DB_TABLES['testcases']
            addendum = 'WHERE %s = "%s"' % (TESTCASE_FIELDS['id'], testcase_id)
            response =\
            self.query_database_table(self.db_handle, table, addendum=addendum)['response']
            # parse response into data dictionary for testcase
            testcase_data = {}
            fields = TESTCASE_FIELDS.keys()
            values = list(response[0])
            for i in range(len(values)):
                testcase_data[fields[i]] = values[i]
            result['testcase data'] = testcase_data

            # query database for test
            test_id = testcase_data['test']
            table = DB_TABLES['tests']
            addendum = 'WHERE %s = "%s"' % (TEST_FIELDS['id'], test_id)
            response =\
            self.query_database_table(self.db_handle, table, addendum=addendum)['response']
            # parse response into data dictionary for test
            test_data = {}
            fields = TEST_FIELDS.keys()
            values = list(response[0])
            for i in range(len(values)):
                test_data[fields[i]] = values[i]
            result['test data'] = test_data

            # query database for user story
            story_id = test_data['user story']
            table = DB_TABLES['user stories']
            addendum = 'WHERE %s = "%s"' % (USERSTORY_FIELDS['id'], story_id)
            response =\
            self.query_database_table(self.db_handle, table, addendum=addendum)['response']
            # parse response into data dictionary for user story
            story_data = {}
            fields = USERSTORY_FIELDS.keys()
            values = list(response[0])
            for i in range(len(values)):
                story_data[fields[i]] = values[i]
            result['user story data'] = story_data

            # query database for feature
            feature_id = story_data['feature']
            table = DB_TABLES['features']
            addendum = 'WHERE %s = "%s"' % (FEATURE_FIELDS['id'], feature_id)
            response =\
            self.query_database_table(self.db_handle, table, addendum=addendum)['response']
            # parse response into data dictionary for feature
            feature_data = {}
            fields = FEATURE_FIELDS.keys()
            values = list(response[0])
            for i in range(len(values)):
                feature_data[fields[i]] = values[i]
            result['feature data'] = feature_data

            # query database for module
            module_id = story_data['module']
            table = DB_TABLES['modules']
            addendum = 'WHERE %s = "%s"' % (MODULE_FIELDS['id'], module_id)
            response =\
            self.query_database_table(self.db_handle, table, addendum=addendum)['response']
            # parse response into data dictionary for module
            module_data = {}
            fields = MODULE_FIELDS.keys()
            values = list(response[0])
            for i in range(len(values)):
                module_data[fields[i]] = values[i]
            result['module data'] = module_data

            self.log.trace("Returned testcase data.")
            result['successful'] = True
        except BaseException, e:
            self.log.error("Failed to return testcase data.")
            self.log.error(str(e))
            self.log.error("Error: %s." % return_execution_error()['error'])
            result['successful'] = False
Example #25
0
                    self.log.trace(e)
                    self.log.trace("Server may have crashed or failed to start. Checking ...")
                    running = self.check_if_vim_server_is_running()
                    if running['service'] or running['process']:
                        self.start_vim_server()
                        self.log_in_to_vim()
                    attempt += 1
                except BaseException, e:
                    if attempt == max_attempts: result['response'] = {}
                    else:
                        self.log.trace("Failed to make GET request to server (attempt %d). "
                                       "Re-attempting in 5 seconds ..." % attempt)
                        self.log.trace(str(e))
                        for error in e:
                            self.log.trace(str(error))
                        exception = return_execution_error()['error']
                        self.log.trace("Error: %s." % exception)
                        sleep(5)

                    # increment
                    attempt += 1

            # end timing
            t = clock()
            # calculate total time
            result['time'] = t - t0

            self.log.trace("Made GET request to server.")
            self.log.trace("Response:\t%s" %result['response'])
            result['successful'] = True
        except BaseException, e: