コード例 #1
0
    def test_fetch_empty(self):
        """Test whether it works when no items are fetched"""

        HTTPServer.routes(empty=True)

        scava = Scava(CROSSMINER_API_REST_URL)
        events = [event for event in scava.fetch()]

        self.assertEqual(len(events), 0)
コード例 #2
0
    def tests_wrong_metadata_category(self):

        HTTPServer.routes()
        prev_requests_http = len(HTTPServer.requests_http)

        # Test fetch events with their reviews
        scava = Scava(CROSSMINER_API_REST_URL, project='perceval')

        items = [page for page in scava.fetch(category="metric")]
        item = items[0]['data']

        item.pop('datatable', None)

        with self.assertRaises(TypeError):
            scava.metadata_category(item)
コード例 #3
0
    def tests_wrong_metadata_updated_on(self):

        HTTPServer.routes()
        prev_requests_http = len(HTTPServer.requests_http)

        # Test fetch events with their reviews
        scava = Scava(CROSSMINER_API_REST_URL)

        items = [page for page in scava.fetch(category="project")]
        item = items[0]

        item.pop('executionInformation', None)

        with self.assertRaises(TypeError):
            scava.metadata_updated_on(item)
コード例 #4
0
    def test_initialization(self):
        """Test whether attributes are initializated"""

        scava = Scava(CROSSMINER_API_REST_URL, tag='test')

        self.assertEqual(scava.url, CROSSMINER_API_REST_URL)
        self.assertEqual(scava.origin, CROSSMINER_API_REST_URL)
        self.assertEqual(scava.tag, 'test')
        self.assertIsNone(scava.client)

        # When tag is empty or None it will be set to
        # the value in url
        scava = Scava(CROSSMINER_API_REST_URL)
        self.assertEqual(scava.url, CROSSMINER_API_REST_URL)
        self.assertEqual(scava.origin, CROSSMINER_API_REST_URL)
        self.assertEqual(scava.tag, CROSSMINER_API_REST_URL)

        scava = Scava(CROSSMINER_API_REST_URL, tag='')
        self.assertEqual(scava.url, CROSSMINER_API_REST_URL)
        self.assertEqual(scava.origin, CROSSMINER_API_REST_URL)
        self.assertEqual(scava.tag, CROSSMINER_API_REST_URL)
コード例 #5
0
    def __test_fetch(self, category='project'):
        """Test whether the metrics are returned"""

        project_items = 2
        metrics_items = 2

        HTTPServer.routes()
        prev_requests_http = len(HTTPServer.requests_http)

        project = None

        if category == 'metric':
            project = 'perceval'

        # Test fetch events with their reviews
        scava = Scava(CROSSMINER_API_REST_URL, project=project)

        items = [item for item in scava.fetch(category=category)]

        if category == 'metric':
            self.assertEqual(len(items), metrics_items)
            self.__check_metric_contents(items)
        elif category == 'project':
            self.assertEqual(len(items), project_items)
            self.__check_project_contents(items)

        # Check requests
        if category == 'metric':
            expected = [{}, {}, {}, {}]  # for getting a metric we need 4 calls
        else:
            expected = [{}]  # for getting the projects we need 1 call

        self.assertEqual(
            len(HTTPServer.requests_http) - prev_requests_http, len(expected))

        for i in range(len(expected)):
            self.assertDictEqual(HTTPServer.requests_http[i].querystring,
                                 expected[i])
コード例 #6
0
def fetch_scava(url_api_rest,
                project=None,
                category=CATEGORY_METRIC,
                recommendation_url=None):
    """
    Fetch the metrics from a Scava project using the Scava API REST

    :param project: name of the Scava project to get the metrics from
    :param url_api_rest: URL for the Scava API REST
    :param category: category of the items to fetch
    :param recommendation_url: URL for the Recommendation API REST

    :return: a metrics generator
    """
    scava = Scava(url=url_api_rest,
                  project=project,
                  recommendation_url=recommendation_url)

    if not project:
        # Get the list of projects and get the metrics for all of them
        for project_scava in scava.fetch():

            project_shortname = project_scava['data']['shortName']
            scavaProject = Scava(url=url_api_rest,
                                 project=project_shortname,
                                 recommendation_url=recommendation_url)

            prj_descr = project_scava['data'][
                'description'] if 'description' in project_scava[
                    'data'] else None
            meta = extract_meta(prj_descr, project_shortname)

            if category == CATEGORY_METRIC:
                logging.debug("Start fetch metrics for %s" %
                              project_scava['data']['shortName'])

                for enriched_metric in enrich_metrics(
                        scavaProject.fetch(CATEGORY_METRIC), meta):
                    yield enriched_metric

                logging.debug("End fetch metrics for %s" %
                              project_scava['data']['shortName'])
            elif category == CATEGORY_FACTOID:
                logging.debug("Start fetch factoids for %s" %
                              project_scava['data']['shortName'])

                for enriched_factoid in enrich_factoids(
                        scavaProject.fetch(CATEGORY_FACTOID), meta):
                    yield enriched_factoid

                logging.debug("End fetch factoids for %s" %
                              project_scava['data']['shortName'])
            elif category == CATEGORY_DEV_DEPENDENCY:
                logging.debug("Start fetch dev dependencies for %s" %
                              project_scava['data']['shortName'])

                for enriched_dep in enrich_dependencies(
                        scavaProject.fetch(CATEGORY_DEV_DEPENDENCY), meta):
                    yield enriched_dep

                logging.debug("End fetch dev dependencies for %s" %
                              project_scava['data']['shortName'])
            elif category == CATEGORY_CONF_DEPENDENCY:
                logging.debug("Start fetch conf dependencies for %s" %
                              project_scava['data']['shortName'])

                for enriched_dep in enrich_dependencies(
                        scavaProject.fetch(CATEGORY_CONF_DEPENDENCY), meta):
                    yield enriched_dep

                logging.debug("End fetch conf dependencies for %s" %
                              project_scava['data']['shortName'])
            elif category == CATEGORY_DEPENDENCY_OLD_NEW_VERSIONS:
                logging.debug("Start fetch version dependencies for %s" %
                              project_scava['data']['shortName'])

                for enriched_dep in enrich_version_dependencies(
                        scavaProject.fetch(
                            CATEGORY_DEPENDENCY_OLD_NEW_VERSIONS), meta):
                    yield enriched_dep

                logging.debug("End fetch version dependencies for %s" %
                              project_scava['data']['shortName'])
            elif category == CATEGORY_USER:
                logging.debug("Start fetch user data for %s" % project)

                for enriched_user in enrich_users(
                        scavaProject.fetch(CATEGORY_USER), meta):
                    yield enriched_user

                logging.debug("End fetch user data for %s" % project)
            elif category == CATEGORY_RECOMMENDATION:
                logging.debug("Start fetch recommendation data for %s" %
                              project)

                for enriched_recommendation in enrich_recommendations(
                        scavaProject.fetch(CATEGORY_RECOMMENDATION), meta):
                    yield enriched_recommendation

                logging.debug("End fetch recommendation data for %s" % project)
            elif category == CATEGORY_CONF_SMELL:
                logging.debug("Start fetch configuration smells data for %s" %
                              project)

                for enriched_conf_smell in enrich_conf_smells(
                        scavaProject.fetch(CATEGORY_CONF_SMELL), meta):
                    yield enriched_conf_smell

                logging.debug("End fetch configuration smells data for %s" %
                              project)

            elif category == CATEGORY_PROJECT_RELATION:
                logging.debug("Start fetch project relations for %s" % project)

                for enriched_project_relation in enrich_project_relations(
                        scavaProject.fetch(CATEGORY_PROJECT_RELATION), meta):
                    yield enriched_project_relation

                logging.debug("End fetch project relations for %s" % project)

            elif category == CATEGORY_TOPIC:
                logging.debug("Start fetch comments topics for %s" % project)

                for enriched_comment_topic in enrich_comments_topics(
                        scavaProject.fetch(CATEGORY_TOPIC), meta):
                    yield enriched_comment_topic

                logging.debug("End fetch comments topics for %s" % project)

            else:
                msg = "category %s not handled" % category
                raise Exception(msg)
    else:
        if category == CATEGORY_METRIC:
            logging.debug("Start fetch metrics for %s" % project)

            for enriched_metric in enrich_metrics(
                    scava.fetch(CATEGORY_METRIC)):
                yield enriched_metric

            logging.debug("End fetch metrics for %s" % project)
        elif category == CATEGORY_FACTOID:
            logging.debug("Start fetch factoids for %s" % project)

            for enriched_factoid in enrich_factoids(
                    scava.fetch(CATEGORY_FACTOID)):
                yield enriched_factoid

            logging.debug("End fetch factoids for %s" % project)
        elif category == CATEGORY_DEV_DEPENDENCY:
            logging.debug("Start fetch dev dependencies for %s" % project)

            for enriched_dep in enrich_dependencies(
                    scava.fetch(CATEGORY_DEV_DEPENDENCY)):
                yield enriched_dep

            logging.debug("End fetch dev dependencies for %s" % project)
        elif category == CATEGORY_CONF_DEPENDENCY:
            logging.debug("Start fetch conf dependencies for %s" % project)

            for enriched_dep in enrich_dependencies(
                    scava.fetch(CATEGORY_CONF_DEPENDENCY)):
                yield enriched_dep

            logging.debug("End fetch conf dependencies for %s" % project)
        elif category == CATEGORY_DEPENDENCY_OLD_NEW_VERSIONS:
            logging.debug("Start fetch version dependencies for %s" % project)

            for enriched_dep in enrich_version_dependencies(
                    scava.fetch(CATEGORY_DEV_DEPENDENCY)):
                yield enriched_dep

            logging.debug("End fetch version dependencies for %s" % project)
        elif category == CATEGORY_USER:
            logging.debug("Start fetch user data for %s" % project)

            for enriched_user in enrich_users(scava.fetch(CATEGORY_USER)):
                yield enriched_user

            logging.debug("End fetch user data for %s" % project)
        elif category == CATEGORY_RECOMMENDATION:
            logging.debug("Start fetch recommendation data for %s" % project)

            for enriched_recommendation in enrich_recommendations(
                    scava.fetch(CATEGORY_RECOMMENDATION)):
                yield enriched_recommendation

            logging.debug("End fetch recommendation data for %s" % project)
        elif category == CATEGORY_CONF_SMELL:
            logging.debug("Start fetch configuration smells data for %s" %
                          project)

            for enriched_conf_smell in enrich_conf_smells(
                    scava.fetch(CATEGORY_CONF_SMELL)):
                yield enriched_conf_smell

            logging.debug("End fetch configuration smells data for %s" %
                          project)

        elif category == CATEGORY_PROJECT_RELATION:
            logging.debug("Start fetch project relations for %s" % project)

            for enriched_project_relation in enrich_project_relations(
                    scava.fetch(CATEGORY_PROJECT_RELATION)):
                yield enriched_project_relation

            logging.debug("End fetch project relations for %s" % project)

        elif category == CATEGORY_TOPIC:
            logging.debug("Start fetch comments topics for %s" % project)

            for enriched_comment_topic in enrich_comments_topics(
                    scava.fetch(CATEGORY_TOPIC)):
                yield enriched_comment_topic

            logging.debug("End fetch comments topics for %s" % project)
        else:
            msg = "category %s not handled" % category
            raise Exception(msg)
コード例 #7
0
 def setUp(self):
     super().setUp()
     self.backend_write_archive = Scava(CROSSMINER_API_REST_URL,
                                        archive=self.archive)
     self.backend_read_archive = Scava(CROSSMINER_API_REST_URL,
                                       archive=self.archive)
コード例 #8
0
    def test_has_resuming(self):
        """Test if it returns True when has_resuming is called"""

        self.assertEqual(Scava.has_resuming(), True)