Beispiel #1
0
    def respond(cls, subject):
        """
        PUT subject score to Caesar
        """
        c = config.online_swap

        address = Address.reducer()

        body = {
            'reduction': {
                'subject_id': subject.id,
                'data': {
                    c.caesar.field: subject.score
                }
            }
        }

        # address='http://httpbin.org/put'
        logger.info('PUT to %s subject %d score %.4f to caesar',
                    address, subject.id, subject.score)

        headers = cls.headers()
        logger.debug('headers %s', str(headers))

        r = requests.put(address, headers=headers, json=body)
        logger.debug('done')

        return r
Beispiel #2
0
    def test_config_caesar(self, put):
        addr = Address.swap_classify()
        data = {
            'extractors_config': {
                'name': {
                    'type': 'external',
                    'url': addr
                }
            },
            'reducers_config': {
                'name': {
                    'type': 'external'
                }
            },
        }

        mock = MagicMock()
        mock.text = json.dumps({
            'extractors_config': {
                'name': {
                    'type': 'external',
                    'url': addr
                }
            },
            'reducers_config': {
                'name': {
                    'type': 'external'
                }
            },
        })
        with patch.object(Requests, 'fetch_caesar_config',
                          MagicMock(return_value=mock)):
            CaesarConfig.register()

        put.assert_called_with(data)
Beispiel #3
0
    def generate_scores(cls, user, key):
        address = Address.swap_scores(auth=False)
        auth = requests.auth.HTTPBasicAuth(user, key)

        r = requests.get(address, auth=auth)
        logger.debug('done')

        return  r
    def register(cls):
        config = cls.get_config()

        name = Address.config.caesar.reducer
        addr = Address.swap_classify()

        config['extractors_config'][name] = {'type': 'external', 'url': addr}
        config['reducers_config'][name] = {'type': 'external'}

        return config
Beispiel #5
0
    def put_caesar_config(cls, data):
        """
        Update caesar config data
        """
        address = Address.root()
        headers = cls.headers()

        logger.info('PUT to %s config %s', address, data)

        print(headers)
        r = requests.put(address, headers=headers, json=data)
        logger.info('done')

        return r
Beispiel #6
0
    def fetch_caesar_config(cls):
        """
        Fetch the current config stored in caesar
        """
        address = Address.root()

        logger.info('Fetching current config in caesar')
        logger.info('GET to %s', address)

        headers = cls.headers()
        print(headers)

        r = requests.get(address, headers=headers)
        logger.debug('done')

        return r
Beispiel #7
0
 def test_classify_address(self):
     address = \
         'https://*****:*****@northdown.spa.umn.edu:443/project/classify'
     assert Address.swap_classify() == address
Beispiel #8
0
 def test_root_address(self):
     address = 'https://example.zooniverse.org:2000/' \
               'workflows/1234'
     assert Address.root() == address
Beispiel #9
0
 def test_reducer_address(self):
     address = 'https://example.zooniverse.org:2000/' \
               'workflows/1234/reducers/swap/reductions'
     assert Address.reducer() == address