# Path: tests/context.py

# 
# Path: pydatajson/helpers.py
# def is_local_andino_resource(catalog, distribution):
#     dist_type = distribution.get('type')
#     if dist_type is not None:
#         return dist_type == 'file.upload'
#     homepage = catalog.get('homepage')
#     if homepage is not None:
#         return distribution.get('downloadURL', '').startswith(homepage)
#     return False


import unittest
import os
import re
import json
    from mock import patch, MagicMock, ANY
    from unittest.mock import patch, MagicMock, ANY
from .context import pydatajson
from pydatajson.federation import *
from pydatajson.helpers import is_local_andino_resource
from ckanapi.errors import NotFound, CKANAPIError
            else:
                return []
        mock_portal.return_value.call_action = mock_call_action
        push_dataset_to_ckan(
            self.catalog,
            'owner',
            self.dataset_id,
            'portal',
            'key',
            download_strategy=(lambda _, x: x['identifier'] == '1.1'))
        _, _, kwargs = \
            mock_portal.return_value.action.resource_patch.mock_calls[0]
        self.assertEqual('1.1', kwargs['id'])
        self.assertEqual('Convocatorias abiertas durante el año 2015',
                         kwargs['name'])
        self.assertEqual('file.upload', kwargs['resource_type'])

    def test_push_dataset_upload_empty_strategy(self, mock_portal):
        def mock_call_action(action, data_dict=None):
            if action == 'package_update':
                return data_dict
            else:
                return []
        mock_portal.return_value.call_action = mock_call_action
        push_dataset_to_ckan(
            self.minimum_catalog,
            'owner',
            self.dataset_id,
            'portal',
            'key',

# Path: tests/context.py

# 
# Path: pydatajson/helpers.py
# def is_local_andino_resource(catalog, distribution):
#     dist_type = distribution.get('type')
#     if dist_type is not None:
#         return dist_type == 'file.upload'
#     homepage = catalog.get('homepage')
#     if homepage is not None:
#         return distribution.get('downloadURL', '').startswith(homepage)
#     return False


# Path: tests/test_federation.py
import unittest
import os
import re
import json
    from mock import patch, MagicMock, ANY
    from unittest.mock import patch, MagicMock, ANY
from .context import pydatajson
from pydatajson.federation import *
from pydatajson.helpers import is_local_andino_resource
from ckanapi.errors import NotFound, CKANAPIError

            else:
                return []
        mock_portal.return_value.call_action = mock_call_action
        push_dataset_to_ckan(
            self.catalog,
            'owner',
            self.dataset_id,
            'portal',
            'key',
            download_strategy=(lambda _, x: x['identifier'] == '1.1'))
        _, _, kwargs = \
            mock_portal.return_value.action.resource_patch.mock_calls[0]
        self.assertEqual('1.1', kwargs['id'])
        self.assertEqual('Convocatorias abiertas durante el año 2015',
                         kwargs['name'])
        self.assertEqual('file.upload', kwargs['resource_type'])

    def test_push_dataset_upload_empty_strategy(self, mock_portal):
        def mock_call_action(action, data_dict=None):
            if action == 'package_update':
                return data_dict
            else:
                return []
        mock_portal.return_value.call_action = mock_call_action
        push_dataset_to_ckan(
            self.minimum_catalog,
            'owner',
            self.dataset_id,
            'portal',
            'key',

            download_strategy=is_local_andino_resource)