How to use the httpretty.PUT function in httpretty

To help you get started, we’ve selected a few httpretty examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github CenterForOpenScience / scrapi / tests / test_osf_processor.py View on Github external
def test_report_id_added_to_cmids(mock_detect_collisions, mock_already_processed):

    normed = deepcopy(NORMALIZED)
    resource = deepcopy(utils.RECORD)

    httpretty.register_uri(httpretty.POST, re.compile('{}/.*'.format(settings.OSF_PREFIX)), body=json.dumps(utils.RECORD))
    httpretty.register_uri(httpretty.PUT, re.compile('{}/.*'.format(settings.OSF_PREFIX)))

    mock_already_processed.return_value = False, md5().hexdigest()

    mock_detect_collisions.return_value = resource

    resource['meta'] = {}
    resource['attached'] = {}
    resource['attached']['cmids'] = ['some stuff']

    osf_processor = osf.OSFProcessor()
    osf_processor.process_normalized(utils.RAW_DOC, normed)

    assert len(resource['attached']['cmids']) > 1
    assert normed['_id'] in resource['attached']['cmids']
github openstack / python-keystoneclient / tests / v3 / test_roles.py View on Github external
def test_domain_group_role_grant(self):
        group_id = uuid.uuid4().hex
        domain_id = uuid.uuid4().hex
        ref = self.new_ref()

        self.stub_url(httpretty.PUT,
                      ['domains', domain_id, 'groups', group_id,
                       self.collection_key, ref['id']],
                      status=201)

        self.manager.grant(role=ref['id'], domain=domain_id, group=group_id)
github openstack / keystonemiddleware / v3 / test_oauth1.py View on Github external
def test_authorize_request_token(self):
        request_key = uuid.uuid4().hex
        info = {'id': request_key,
                'key': request_key,
                'secret': uuid.uuid4().hex}
        request_token = request_tokens.RequestToken(self.manager, info)

        verifier = uuid.uuid4().hex
        resp_ref = {'token': {'oauth_verifier': verifier}}
        self.stub_url(httpretty.PUT,
                      [self.path_prefix, 'authorize', request_key],
                      status=200, json=resp_ref)

        # Assert the manager is returning the expected data
        role_id = uuid.uuid4().hex
        token = request_token.authorize([role_id])
        self.assertEqual(verifier, token.oauth_verifier)

        # Assert that the request was sent in the expected structure
        exp_body = {'roles': [{'id': role_id}]}
        self.assertRequestBodyIs(json=exp_body)
github transcode-de / durga / tests / test_collection.py View on Github external
def test_update(fixture, resource, return_payload):
    httpretty.register_uri(httpretty.GET, resource.url, body=fixture('movies.json'),
        content_type='application/json')
    movies = resource.collection.all()
    httpretty.register_uri(httpretty.PUT, resource.url, body=return_payload,
        content_type='application/json')
    data = {
        'title': 'The Terminator',
        'director': 'James Cameron'
    }
    responses = movies.update(data)
    assert responses[0].status_code == 200
    for response in responses:
        movie = response.json()
        assert movie['title'] == data['title']
        assert movie['director'] == data['director']
    for movie in movies:
        assert movie.title == data['title']
        assert movie.director == data['director']
github CenterForOpenScience / scrapi / tests / test_osf_processor.py View on Github external
def test_has_properties(mock_already_processed):

    normed = deepcopy(NORMALIZED)

    httpretty.register_uri(httpretty.POST, re.compile('{}/.*'.format(settings.OSF_PREFIX)), body=json.dumps(utils.RECORD))
    httpretty.register_uri(httpretty.PUT, re.compile('{}/.*'.format(settings.OSF_PREFIX)))

    mock_already_processed.return_value = False, md5().hexdigest()

    osf_processor = osf.OSFProcessor()
    osf_processor.process_normalized(utils.RAW_DOC, normed)

    assert(normed['collisionCategory'])
    assert(normed['_id'])
github rapid7 / lecli / tests / test_log_api.py View on Github external
log_url.return_value = '', MOCK_API_URL
    logset_url.return_value = '', MOCK_API_URL

    mocked_rw_apikey.return_value = ID_WITH_VALID_LENGTH
    mocked_ro_apikey.return_value = ID_WITH_VALID_LENGTH

    request_body = '{"log": {"name": "test.log", "logsets_info": [], "source_type": "token"}}'
    expected_result = '{"log": {"name": "test.log", ' \
                      '"logsets_info": [{"id": "e227f890-7742-47b4-86b2-5ff1d345397e",' \
                      '"name": "test_logset"}], "source_type": "token"}}'

    httpretty.register_uri(httpretty.GET, MOCK_API_URL, status=200,
                           content_type='application/json', body=request_body)
    httpretty.register_uri(httpretty.GET, MOCK_API_URL, status=200,
                           content_type='application/json', body=request_body)
    httpretty.register_uri(httpretty.PUT, MOCK_API_URL, status=200,
                           content_type='application/json', body=expected_result)

    logset_info = {
        "logsets_info": [
            {
                "id": "e227f890-7742-47b4-86b2-5ff1d345397e",
                "name": "test_logset"
            }
        ]
    }

    api.update_log(test_log_id, logset_info)
    out, err = capsys.readouterr()

    assert "test_logset" in out
github opentok / Opentok-Python-SDK / tests / test_stream.py View on Github external
def test_set_stream_class_lists_throws_exception(self):
        """ Test invalid request in set stream class list """
        
        #invalid payload
        payload = [
            {'id': '7b09ec3c-26f9-43d7-8197-f608f13d4fb6'}
        ]

        httpretty.register_uri(
            httpretty.PUT,
            u('https://api.opentok.com/v2/project/{0}/session/{1}/stream').format(
                self.api_key,
                self.session_id
            ),
            status=400,
            content_type=u('application/json')
        )

        self.assertRaises(
            SetStreamClassError,
            self.opentok.set_stream_class_lists,
            self.session_id,
            payload
        )
github openstack / keystonemiddleware / v3 / test_roles.py View on Github external
def test_domain_group_role_grant(self):
        group_id = uuid.uuid4().hex
        domain_id = uuid.uuid4().hex
        ref = self.new_ref()

        self.stub_url(httpretty.PUT,
                      ['domains', domain_id, 'groups', group_id,
                       self.collection_key, ref['id']],
                      status=201)

        self.manager.grant(role=ref['id'], domain=domain_id, group=group_id)
github coinbase / coinbase-python / tests / test_client.py View on Github external
  @mock_response(hp.PUT, '/v2/accounts/foo', mock_item)
  def test_update_account(self):
    client = Client(api_key, api_secret)
    account = client.update_account('foo', name='New Account Name')
    self.assertIsInstance(account, Account)
    self.assertEqual(account, mock_item)
github transcode-de / durga / tests / test_element.py View on Github external
def test_save(fixture, resource, return_payload):
    """Tests saving an ``Element`` in different ways."""
    resource.url_attribute = 'resource_uri'
    httpretty.register_uri(httpretty.GET, resource.get_url(), body=fixture('movie.json'),
        content_type='application/json')
    movie = resource.collection.get(id=1)
    httpretty.register_uri(httpretty.PUT, movie.get_url(), body=return_payload,
        content_type='application/json')
    movie.runtime = 120
    assert movie.save().runtime == movie.runtime
    data = {'runtime': 90}
    movie.update(data)
    movie.save()
    assert movie.runtime == data['runtime']
    assert movie.get_raw()['runtime'] == 110