예제 #1
0
    def test_pull_repo(self):

        from pyramid.events import subscriber
        from unicore.webhooks.events import WebhookEvent

        mock = Mock()
        subscriber(WebhookEvent)(mock)

        request = Request.blank('/', base_url='http://example.org')

        tmp_ini_file = self.mk_inifile({
            'app:main': {
                'use': 'egg:unicore.distribute',
                'repo.storage_path': self.WORKING_DIR
            }
        })
        env = bootstrap(tmp_ini_file, request=request)

        mock = Mock()
        poll_repos = PollRepositories()
        poll_repos.notify = mock
        poll_repos.pull_repo(env, self.workspace.repo)

        mock.assert_not_called()

        self.remote_workspace.save(TestPerson({
            'age': 2,
            'name': 'Foo'
        }), 'Saving person2')

        poll_repos.pull_repo(env, self.workspace.repo)
        mock.assert_called()
        (call, ) = mock.call_args_list
        (args, kwargs) = call
        (event, ) = args
        name = os.path.basename(self.workspace.working_dir)
        url = env['request'].route_url('repositoryresource', name=name)
        self.assertTrue('http://example.org' in url)
        self.assertEqual(event.owner, None)
        self.assertEqual(event.event_type, 'repo.push')
        self.assertEqual(event.payload, {
            'repo': name,
            'url': url,
        })
예제 #2
0
from pyramid.events import subscriber
from openprocurement.tender.core.events import TenderInitializeEvent
from openprocurement.tender.core.utils import get_now


def tender_init_handler_base(event):
    tender = event.tender
    tender.date = get_now()
    if tender.lots:
        for lot in tender.lots:
            lot.date = get_now()


@subscriber(TenderInitializeEvent, procurementMethodType="reporting")
def tender_init_handler_reporting(event):
    """ initialization handler for tenders 'reporting'"""
    event.tender.date = get_now()


# initialization handler for tenders 'negotiation'
tender_init_handler_negotiation = subscriber(
    TenderInitializeEvent,
    procurementMethodType="negotiation")(tender_init_handler_base)

# initialization handler for tenders 'negotiation.quick'
tender_init_handler_negotiation_quick = subscriber(
    TenderInitializeEvent,
    procurementMethodType="negotiation.quick")(tender_init_handler_base)
예제 #3
0
 def _makeOne(self, *ifaces):
     from pyramid.events import subscriber
     return subscriber(*ifaces)
예제 #4
0
    def _makeOne(self, *ifaces, **predicates):
        from pyramid.events import subscriber

        return subscriber(*ifaces, **predicates)