Example #1
0
    def test_resource_delete_raises_ClientError_if_status_code_is_wrong(
            self, session):
        when(session).raw_request('/users/user1', method='DELETE')\
            .thenReturn(Response(500, {}, 'internal server error'))

        with pytest.raises(ClientError):
            RestResources(session, '/users')['user1'].delete()
Example #2
0
    def test_passing_extra_params_to_resource_update(self, session):
        when(session).request('/users/user1', method='PUT',
                              data={'name': 'Jane'}, params={'foo': 'bar'})\
            .thenReturn({'id': 'user1', 'name': 'Jane'})

        assert RestResources(session, '/users')['user1']\
            .update({'name': 'Jane'}, params={'foo': 'bar'}) == {'id': 'user1', 'name': 'Jane'}
Example #3
0
    def test_resource_delete_ignores_404_response(self, session):
        when(session).raw_request('/users/user1', method='DELETE')\
            .thenReturn(Response(404, {}, 'user not found'))

        RestResources(session, '/users')['user1'].delete()

        verify(session).raw_request('/users/user1', method='DELETE')
Example #4
0
    def test_resource_delete(self, session):
        when(session).raw_request(m.any(), method='DELETE')\
            .thenReturn(Response(204, {}, ''))

        RestResources(session, '/users')['user1'].delete()

        verify(session).raw_request('/users/user1', method='DELETE')
Example #5
0
    def test_resources_create(self, session):
        when(session)\
            .request('/users', method='POST', data={'foo': 'bar', 'baz': 123})\
            .thenReturn({'id': 'id1'})

        assert RestResources(session, '/users')\
            .create({'foo': 'bar', 'baz': 123}) == {'id': 'id1'}
Example #6
0
    def test_passing_extra_params_to_resources_create(self, session):
        when(session)\
            .request('/users', method='POST', data={'foo': 'bar', 'baz': 123},
                     params={'bam': '123'})\
            .thenReturn({'id': 'id1'})

        assert RestResources(session, '/users')\
            .create({'foo': 'bar', 'baz': 123}, params={'bam': '123'}) == {'id': 'id1'}
Example #7
0
    def test_passing_extra_params_to_resource_delete(self, session):
        when(session).raw_request(m.any(), method='DELETE', params={'foo': 'bar'})\
            .thenReturn(Response(204, {}, ''))

        RestResources(session, '/users')['user1'].delete(params={'foo': 'bar'})

        verify(session).raw_request('/users/user1',
                                    method='DELETE',
                                    params={'foo': 'bar'})
Example #8
0
    def test_registering_cleanup_on_create(self, session):
        when(session).request('/users', method='POST', data=m.any())\
            .thenReturn({'id': 'john'})

        RestResources(session, '/users').create({'name': 'John Doe'})

        func_captor = m.captor(m.arg_that(callable))

        verify(session).add_cleanup('/users/john', func_captor)


        when(session).raw_request(m.any(), method='DELETE')\
            .thenReturn(Response(204, {}, ''))

        (func_captor.value)()

        verify(session).raw_request('/users/john', method='DELETE')
Example #9
0
    def test_unregistering_cleanup_on_delete(self, session):
        RestResources(session, '/users')['john'].delete()

        verify(session).remove_cleanup('/users/john')
Example #10
0
    def test_resource_update(self, session):
        when(session).request('/users/user1', method='PUT', data={'name': 'Jane'})\
            .thenReturn({'id': 'user1', 'name': 'Jane'})

        assert RestResources(session, '/users')['user1']\
            .update({'name': 'Jane'}) == {'id': 'user1', 'name': 'Jane'}
Example #11
0
    def test_passing_extra_params_to_resource_get(self, session):
        when(session).request('/users/user1', params={'foo': 'bar'})\
            .thenReturn({'id': 'user1', 'name': 'John'})

        assert RestResources(session, '/users')['user1']\
            .get(params={'foo': 'bar'}) == {'id': 'user1', 'name': 'John'}
Example #12
0
    def test_resource_get(self, session):
        when(session).request('/users/user1')\
            .thenReturn({'id': 'user1', 'name': 'John'})

        assert RestResources(session, '/users')['user1']\
            .get() == {'id': 'user1', 'name': 'John'}
Example #13
0
    def test_passing_extra_params_to_resources_list(self, session):
        when(session).request('/users', params={'baz': 'bam'})\
            .thenReturn(["foo", "bar"])

        assert RestResources(
            session, '/users').list(params={'baz': 'bam'}) == ['foo', 'bar']
Example #14
0
    def test_resources_list(self, session):
        when(session).request('/users').thenReturn(["foo", "bar"])

        assert RestResources(session, '/users').list() == ['foo', 'bar']