Beispiel #1
0
    def test_publish_attachment(self, uuidmock):
        uuidmock.uuid4.return_value = 1234567890
        server = KintoServer('foo', 'baa')
        server._setup_done = True
        assert not server._changes
        url = (
            settings.REMOTE_SETTINGS_WRITER_URL +
            'buckets/foo/collections/baa/records/1234567890/attachment')
        responses.add(
            responses.POST,
            url,
            json={'data': {'id': '1234567890'}})

        with tempfile.TemporaryFile() as attachment:
            record = server.publish_attachment(
                {'something': 'somevalue'}, ('file', attachment))
        assert server._changes
        assert record == {'id': '1234567890'}

        url = (
            settings.REMOTE_SETTINGS_WRITER_URL +
            'buckets/foo/collections/baa/records/an-id/attachment')
        responses.add(
            responses.POST,
            url,
            json={'data': {'id': 'an-id'}})

        with tempfile.TemporaryFile() as attachment:
            record = server.publish_attachment(
                {'something': 'somevalue'}, ('otherfile', attachment), 'an-id')
        assert record == {'id': 'an-id'}
Beispiel #2
0
    def test_publish_record(self):
        server = KintoServer('foo', 'baa')
        server._setup_done = True
        assert not server._changes
        responses.add(
            responses.POST,
            settings.REMOTE_SETTINGS_WRITER_URL +
            'buckets/foo/collections/baa/records',
            content_type='application/json',
            json={'data': {'id': 'new!'}})

        record = server.publish_record({'something': 'somevalue'})
        assert server._changes
        assert record == {'id': 'new!'}

        url = (
            settings.REMOTE_SETTINGS_WRITER_URL +
            'buckets/foo/collections/baa/records/an-id')
        responses.add(
            responses.PUT,
            url,
            content_type='application/json',
            json={'data': {'id': 'updated'}})

        record = server.publish_record({'something': 'somevalue'}, 'an-id')
        assert record == {'id': 'updated'}
Beispiel #3
0
    def test_delete_all_records(self):
        server = KintoServer('foo', 'baa')
        server._setup_done = True
        assert not server._changes
        url = (settings.KINTO_API_URL + 'buckets/foo/collections/baa/records')
        responses.add(responses.DELETE, url, content_type='application/json')

        server.delete_all_records()
        assert server._changes
Beispiel #4
0
    def test_delete_record(self):
        server = KintoServer('foo', 'baa')
        server._setup_done = True
        assert not server._changes
        url = (
            settings.REMOTE_SETTINGS_WRITER_URL +
            'buckets/foo/collections/baa/records/an-id')
        responses.add(
            responses.DELETE,
            url,
            content_type='application/json')

        server.delete_record('an-id')
        assert server._changes
Beispiel #5
0
    def test_delete_record(self):
        server = KintoServer('foo', 'baa')
        server._setup_done = True
        assert not server._needs_signoff
        url = (
            settings.KINTO_API_URL +
            'buckets/foo/collections/baa/records/an-id')
        responses.add(
            responses.DELETE,
            url,
            content_type='application/json')

        server.delete_record('an-id')
        assert server._needs_signoff
Beispiel #6
0
    def test_signoff(self):
        server = KintoServer('foo', 'baa')
        server._setup_done = True
        # should return because nothing to signoff
        server.signoff_request()

        server._needs_signoff = True
        url = (
            settings.KINTO_API_URL +
            'buckets/foo/collections/baa')
        responses.add(
            responses.PATCH,
            url,
            content_type='application/json')
        server.signoff_request()
        assert not server._needs_signoff
Beispiel #7
0
    def test_complete_session_no_kinto_signoff(self):
        server = KintoServer('foo', 'baa', kinto_sign_off_needed=False)
        server._setup_done = True
        # should return because nothing to signoff
        server.complete_session()

        server._changes = True
        url = (settings.KINTO_API_URL + 'buckets/foo/collections/baa')
        responses.add(responses.PATCH, url, content_type='application/json')
        server.complete_session()
        assert not server._changes
        assert responses.calls[0].request.body == json.dumps({
            'data': {
                'status': 'to-sign'
            }
        }).encode()
Beispiel #8
0
    def test_complete_session(self):
        server = KintoServer('foo', 'baa')
        server._setup_done = True
        # should return because nothing to signoff
        server.complete_session()

        server._changes = True
        url = (
            settings.REMOTE_SETTINGS_WRITER_URL +
            'buckets/foo/collections/baa')
        responses.add(
            responses.PATCH,
            url,
            content_type='application/json')
        server.complete_session()
        assert not server._changes
        assert responses.calls[0].request.body == json.dumps(
            {'data': {'status': 'to-review'}}).encode()