# Path: f8a_worker/workers/new_graph_importer.py
# class NewPackageAnalysisGraphImporterTask(BaseTask):
#     """Ingest to graph node."""
# 
#     def execute(self, arguments):
#         """Task code.
# 
#         :param arguments: dictionary with task arguments
#         :return: {}, results
#         """
#         self._strict_assert(arguments.get('ecosystem'))
#         self._strict_assert(arguments.get('name'))
# 
#         package_list = [
#             {
#                         'ecosystem': arguments.get('ecosystem'),
#                         'name': arguments['name'],
#                         'version': '',
#                         'source_repo': arguments.get('ecosystem')
#             }
#         ]
# 
#         param = {
#             'select_ingest': ['github_details'],
#             'package_list': package_list
#         }
# 
#         logger.info("v2_:_Invoke graph importer at url: '%s' for %s",
#                     _SELECTIVE_API_URL, param)
#         # Calling Data Importer API end point to ingest data into graph db.
#         response = requests.post(_SELECTIVE_API_URL, json=param)
# 
#         if response.status_code != 200:
#             raise RuntimeError("v2_:_Failed to invoke graph import at '%s' for %s" %
#                                (_SELECTIVE_API_URL, param))
# 
#         logger.info("v2_:_Graph import succeeded with response: %s", response.text)
# 
# class NewPackageGraphImporterTask(BaseTask):
#     """Ingest to graph node."""
# 
#     def execute(self, arguments):
#         """Task code.
# 
#         :param arguments: dictionary with task arguments
#         :return: {}, results
#         """
#         self._strict_assert(arguments.get('ecosystem'))
#         self._strict_assert(arguments.get('name'))
# 
#         package_list = [{
#                 'ecosystem': arguments.get('ecosystem'),
#                 'name': arguments['name'],
#                 'version': arguments.get('version'),
#                 'source_repo': arguments.get('ecosystem')
#             }]
# 
#         param = {
#             'select_ingest': ['metadata'],
#             'package_list': package_list
#         }
# 
#         logger.info("v2_:_Invoke graph importer at url: '%s' for %s",
#                     _SELECTIVE_API_URL, param)
#         # Calling Data Importer API end point to ingest data into graph db.
#         response = requests.post(_SELECTIVE_API_URL, json=param)
# 
#         if response.status_code != 200:
#             raise RuntimeError("v2_:_Failed to invoke graph import at '%s' for %s" %
#                                (_SELECTIVE_API_URL, param))
# 
#         logger.info("v2_:_Graph import succeeded with response: %s", response.text)


from unittest import TestCase, mock
from f8a_worker.workers.new_graph_importer import \
    NewPackageAnalysisGraphImporterTask, \
    NewPackageGraphImporterTask

class Response:
    """Custom response class."""

    status_code = 200
    text = 'dummy_data'


class ErrorResponse:
    """Custom response class for error."""

    status_code = 404
    text = 'dummy_data'


class TestNewPackageAnalysisGraphImporterTask(TestCase):
    """Tests for the NewGraphImporterTask task."""

    def _strict_assert(self, assert_cond):
        if not assert_cond:
            False

    @mock.patch('f8a_worker.workers.new_graph_importer.requests.post', return_value=ErrorResponse())
    def test_execute(self, _mock1):
        """Tests for 'execute'."""
        self.assertRaises(RuntimeError, NewPackageAnalysisGraphImporterTask.execute, self, data)

    @mock.patch('f8a_worker.workers.new_graph_importer.requests.post', return_value=Response())
    def test_execute1(self, _mock1):
        """Tests for 'execute'."""

# Path: f8a_worker/workers/new_graph_importer.py
# class NewPackageAnalysisGraphImporterTask(BaseTask):
#     """Ingest to graph node."""
# 
#     def execute(self, arguments):
#         """Task code.
# 
#         :param arguments: dictionary with task arguments
#         :return: {}, results
#         """
#         self._strict_assert(arguments.get('ecosystem'))
#         self._strict_assert(arguments.get('name'))
# 
#         package_list = [
#             {
#                         'ecosystem': arguments.get('ecosystem'),
#                         'name': arguments['name'],
#                         'version': '',
#                         'source_repo': arguments.get('ecosystem')
#             }
#         ]
# 
#         param = {
#             'select_ingest': ['github_details'],
#             'package_list': package_list
#         }
# 
#         logger.info("v2_:_Invoke graph importer at url: '%s' for %s",
#                     _SELECTIVE_API_URL, param)
#         # Calling Data Importer API end point to ingest data into graph db.
#         response = requests.post(_SELECTIVE_API_URL, json=param)
# 
#         if response.status_code != 200:
#             raise RuntimeError("v2_:_Failed to invoke graph import at '%s' for %s" %
#                                (_SELECTIVE_API_URL, param))
# 
#         logger.info("v2_:_Graph import succeeded with response: %s", response.text)
# 
# class NewPackageGraphImporterTask(BaseTask):
#     """Ingest to graph node."""
# 
#     def execute(self, arguments):
#         """Task code.
# 
#         :param arguments: dictionary with task arguments
#         :return: {}, results
#         """
#         self._strict_assert(arguments.get('ecosystem'))
#         self._strict_assert(arguments.get('name'))
# 
#         package_list = [{
#                 'ecosystem': arguments.get('ecosystem'),
#                 'name': arguments['name'],
#                 'version': arguments.get('version'),
#                 'source_repo': arguments.get('ecosystem')
#             }]
# 
#         param = {
#             'select_ingest': ['metadata'],
#             'package_list': package_list
#         }
# 
#         logger.info("v2_:_Invoke graph importer at url: '%s' for %s",
#                     _SELECTIVE_API_URL, param)
#         # Calling Data Importer API end point to ingest data into graph db.
#         response = requests.post(_SELECTIVE_API_URL, json=param)
# 
#         if response.status_code != 200:
#             raise RuntimeError("v2_:_Failed to invoke graph import at '%s' for %s" %
#                                (_SELECTIVE_API_URL, param))
# 
#         logger.info("v2_:_Graph import succeeded with response: %s", response.text)


# Path: tests/workers/test_new_graph_importer.py
from unittest import TestCase, mock
from f8a_worker.workers.new_graph_importer import \
    NewPackageAnalysisGraphImporterTask, \
    NewPackageGraphImporterTask


class Response:
    """Custom response class."""

    status_code = 200
    text = 'dummy_data'


class ErrorResponse:
    """Custom response class for error."""

    status_code = 404
    text = 'dummy_data'


class TestNewPackageAnalysisGraphImporterTask(TestCase):
    """Tests for the NewGraphImporterTask task."""

    def _strict_assert(self, assert_cond):
        if not assert_cond:
            False

    @mock.patch('f8a_worker.workers.new_graph_importer.requests.post', return_value=ErrorResponse())
    def test_execute(self, _mock1):
        """Tests for 'execute'."""
        self.assertRaises(RuntimeError, NewPackageAnalysisGraphImporterTask.execute, self, data)

    @mock.patch('f8a_worker.workers.new_graph_importer.requests.post', return_value=Response())
    def test_execute1(self, _mock1):
        """Tests for 'execute'."""

        NewPackageAnalysisGraphImporterTask.execute(self, data)