Beispiel #1
0
 def test_records_are_created(self, person_object: Object, client: Client):
     """
     Create two records and verify pk values are assigned
     :param person_object:
     :param client:
     """
     first_record = Record(obj=person_object,
                           **{
                               'name': 'Feodor',
                               'is_active': True,
                               'age': 23,
                               "street": "St"
                           })
     second_record = Record(obj=person_object,
                            **{
                                'name': 'Victor',
                                'is_active': False,
                                'age': 22,
                                "street": "St"
                            })
     first_record, second_record = client.records.bulk_create(
         first_record, second_record)
     assert_that(first_record.get_pk(), instance_of(int))
     assert_that(second_record.get_pk(), instance_of(int))
     self._created_records = (first_record, second_record)
Beispiel #2
0
def test_client_updates_record_with_partial_data(existing_person_object: Object, client: Client):
    record = Record(obj=existing_person_object, id=23, age=20, name='Ivan', is_active=True, street="Street")
    record = client.records.create(record=record)
    assert_that(record, instance_of(Record))

    # perform partial update
    record = client.records.partial_update(existing_person_object, record.get_pk(), {'name': 'Petr'})
    assert_that(record.name, equal_to('Petr'))

    # check that new data got stored in Custodian
    record = client.records.get(existing_person_object, record.get_pk())
    assert_that(record.name, equal_to('Petr'))
Beispiel #3
0
 def test_record_is_deleted(self, person_record: Record, client: Client):
     """
     Delete the record and verify it does not exist in the database
     :param person_record:
     :param client:
     """
     person_record = client.records.create(person_record)
     pk = person_record.get_pk()
     deleted_record = client.records.delete(person_record)
     assert_that(person_record.get_pk(), is_(None))
     assert_that(client.records.get(person_record.obj, pk), is_(None))
     assert_that(deleted_record, instance_of(Record))
Beispiel #4
0
def test_client_returns_none_for_nonexistent_record(person_record: Record,
                                                    client: Client):
    with requests_mock.Mocker() as mocker:
        mocker.get('/'.join([
            client.server_url,
            'data/single/{}/{}'.format(person_record.obj.name,
                                       person_record.get_pk())
        ]),
                   json={
                       'status': 'FAIL',
                       'data': {}
                   })
        record = client.records.get(person_record.obj, person_record.get_pk())
        assert_that(record, is_(None))
Beispiel #5
0
def test_client_retrieves_existing_record(person_record: Record,
                                          client: Client):
    with requests_mock.Mocker() as mocker:
        mocker.get('/'.join([
            client.server_url,
            'data/single/{}/{}'.format(person_record.obj.name,
                                       person_record.get_pk())
        ]),
                   json={
                       'status': 'OK',
                       'data': person_record.serialize()
                   })
        record = client.records.get(person_record.obj, person_record.get_pk())
        assert_that(record, is_(instance_of(Record)))
Beispiel #6
0
 def delete(self, record: Record):
     """
     Deletes the record from the Custodian
     :param record:
     :return:
             """
     self.client.execute(command=Command(name=self._get_record_command_name(
         record.obj, record.get_pk()),
                                         method=COMMAND_METHOD.DELETE))
     setattr(record, record.obj.key, None)
Beispiel #7
0
 def test_new_record_can_be_retrieved_by_pk(self, person_record: Record,
                                            client: Client):
     """
     Create a new record and check it has PK field assigned
     :param person_record:
     :param client:
     """
     person_record = client.records.create(person_record)
     assert_that(
         client.records.get(person_record.obj, person_record.get_pk()),
         instance_of(Record))
Beispiel #8
0
def test_client_deletes(person_record: Record, client: Client):
    assert_that(person_record.exists())
    record_data = person_record.serialize()
    with requests_mock.Mocker() as mocker:
        mocker.delete('/'.join([
            client.server_url,
            'data/single/{}/{}'.format(person_record.obj.name,
                                       person_record.get_pk())
        ]),
                      json={
                          'status': 'OK',
                          'data': record_data
                      })
        client.records.delete(person_record)
        assert_that(person_record.exists(), is_not(True))
Beispiel #9
0
 def update(self, record: Record, **kwargs):
     """
     Updates an existing record in the Custodian
     """
     data, ok = self.client.execute(command=Command(
         name=self._get_record_command_name(record.obj, record.get_pk()),
         method=COMMAND_METHOD.PATCH),
                                    data=record.serialize(),
                                    params=kwargs)
     if ok:
         return Record(obj=record.obj, **data)
     else:
         if data.get('code') == 'cas_failed':
             raise CasFailureException(data.get('Msg', ''))
         else:
             raise RecordUpdateException(data.get('Msg', ''))
Beispiel #10
0
def test_client_returns_updated_record_on_record_update(
        person_record: Record, client: Client):
    record_data = person_record.serialize()
    record_data['is_active'] = False
    with requests_mock.Mocker() as mocker:
        mocker.post('/'.join([
            client.server_url,
            'data/single/{}/{}'.format(person_record.obj.name,
                                       person_record.get_pk())
        ]),
                    json={
                        'status': 'OK',
                        'data': record_data
                    })
        record = client.records.update(person_record)
        assert_that(record, is_(instance_of(Record)))
        assert_that(record.exists())
        assert_that(record.is_active, is_(False))