Beispiel #1
0
    def test_cache_is_flushed_on_object_update(self,
                                               existing_person_object: Object):
        """
        Once meta retrieved from Custodian, it should be returned from cache
        """
        client = Client(server_url=os.environ['SERVER_URL'], use_cache=True)

        client.execute = call_counter(client.execute)
        initial_person_object = client.objects.get(existing_person_object.name)
        assert_that(initial_person_object, instance_of(Object))
        initial_call_count = client.execute.call_count

        updated_person_object = copy.deepcopy(existing_person_object)
        del updated_person_object._fields['street']

        # two calls of 'execute'(both for update and get operation) should be done
        client.objects.update(updated_person_object)
        re_retrieved_person_object = client.objects.get(
            existing_person_object.name)

        assert_that(initial_call_count + 2,
                    equal_to(client.execute.call_count))

        assert_that(re_retrieved_person_object.fields,
                    has_length(len(updated_person_object.fields)))
Beispiel #2
0
    def test_cache_is_flushed_on_object_remove(self,
                                               existing_person_object: Object):
        """
        Once meta retrieved from Custodian, it should be returned from cache
        """
        client = Client(server_url=os.environ['SERVER_URL'], use_cache=True)

        client.execute = call_counter(client.execute)
        initial_person_object = client.objects.get(existing_person_object.name)
        assert_that(initial_person_object, instance_of(Object))
        client.objects.delete(existing_person_object)
        assert_that(client.objects.get(existing_person_object.name), is_(None))
Beispiel #3
0
def test_query_resets_evaluated_result_on_query_modifications():
    client = Client(server_url='http://mocked/custodian')
    query = Query('person', client.records).filter(is_active__eq=True)
    query._is_evaluated = True
    assert_that(query._is_evaluated)
    query = query.filter(client__first_name__eq='Ivan')
    assert_that(not query._is_evaluated)
Beispiel #4
0
    def test_cache_works_for_get_operation(self,
                                           existing_person_object: Object):
        """
        Once meta retrieved from Custodian, it should be returned from cache
        """
        client = Client(server_url=os.environ['SERVER_URL'], use_cache=True)

        client.execute = call_counter(client.execute)

        person_object = client.objects.get(existing_person_object.name)
        assert_that(person_object, instance_of(Object))

        initial_call_count = client.execute.call_count
        re_retrieved_person_object = client.objects.get(
            existing_person_object.name)
        assert_that(person_object, is_(re_retrieved_person_object))
        assert_that(client.execute.call_count, equal_to(initial_call_count))
Beispiel #5
0
def test_client_makes_correct_request_on_object_delete(person_object: Object):
    client = Client(server_url='http://mocked/custodian')
    with requests_mock.Mocker() as mocker:
        mocker.delete('/'.join(
            [client.server_url, 'meta/{}'.format(person_object.name)]),
                      json={
                          'status': 'OK',
                          'data': person_object.serialize()
                      })
        obj = client.objects.delete(person_object)
        assert_that(obj, is_(instance_of(Object)))
Beispiel #6
0
def test_client_retrieves_existing_object(person_object: Object):
    client = Client(server_url='http://mocked/custodian')
    with requests_mock.Mocker() as mocker:
        mocker.get('http://mocked/custodian/meta/{}'.format(
            person_object.name),
                   json={
                       'status': 'OK',
                       'data': person_object.serialize()
                   })
        obj = client.objects.get(person_object.name)
        assert_that(obj, is_(instance_of(Object)))
        assert_that(person_object.serialize(), equal_to(obj.serialize()))
Beispiel #7
0
def client():
    return Client(server_url=os.environ.get('SERVER_URL',
                                            'http://localhost:8000/custodian'))
Beispiel #8
0
def client():
    return Client(server_url=os.environ['SERVER_URL'])