def test_default_replication(translator): """ By default there should be 2-all replicas https://crate.io/docs/crate/reference/en/latest/general/ddl/replication.html """ entities = create_random_entities(1, 2, 10) entity = entities[0] e_type = entity['type'] translator.insert(entities) et = '{}{}'.format(TYPE_PREFIX, e_type.lower()) # same as in translator._et2tn but without double quotes op = "select number_of_replicas from information_schema.tables where " \ "table_name = '{}'" translator.cursor.execute(op.format(et)) res = translator.cursor.fetchall() assert res[0] == ['2-all'] # Metadata table should also be replicated translator.cursor.execute(op.format(METADATA_TABLE_NAME)) res = translator.cursor.fetchall() assert res[0] == ['2-all'] translator.clean()
def test_auth_delete_entity_defaults(set_env_vars, translator): num_types = 2 num_ids_per_type = 2 num_updates = 5 entities = create_random_entities(num_types, num_ids_per_type, num_updates) translator.insert(entities) deleted_type = entities[0]['type'] deleted_id = entities[0]['id'] total, err = translator.query() assert len(total) == num_types * num_ids_per_type selected, err = translator.query(entity_type=deleted_type, entity_id=deleted_id) assert len(selected[0]['index']) == num_updates n_deleted = translator.delete_entity(deleted_id, entity_type=deleted_type) assert n_deleted == num_updates remaining, err = translator.query() assert len(remaining) == (len(total) - 1) survivors, err = translator.query(entity_type=deleted_type, entity_id=deleted_id) assert len(survivors) == 0 translator.clean()
def test_geo_point(translator): # Github issue #35: Support geo:point entity = { 'id': 'Room1', 'type': 'Room', TIME_INDEX_NAME: datetime.now(timezone.utc).isoformat(timespec='milliseconds'), 'location': { 'type': 'geo:point', 'value': "19.6389474, -98.9109537" # lat, long } } translator.insert([entity]) # Check location is saved as a geo_point column in crate op = "select latitude(_doc['location']), longitude(_doc['location']) " \ "from etroom " translator.cursor.execute(op) res = translator.cursor.fetchall() assert len(res) == 1 assert res[0] == [19.6389474, -98.9109537] entities = translator.query() assert len(entities) == 1 # Check entity is retrieved as it was inserted check_notifications_record([entity], entities) translator.clean()
def test_geo_point_null_values(translator): # Github PR #198: Support geo:point null values entity = { 'id': 'Room1', 'type': 'Room', TIME_INDEX_NAME: datetime.now(timezone.utc).isoformat(timespec='milliseconds'), 'location': { 'type': 'geo:point', 'value': "19.6389474, -98.9109537" # lat, long } } translator.insert([entity]) entities = translator.query() assert len(entities) == 1 check_notifications_record([entity], entities) entity_new = { 'id': 'Room1', 'type': 'Room', TIME_INDEX_NAME: datetime.now(timezone.utc).isoformat(timespec='milliseconds'), 'temperature': { 'type': 'Number', 'value': 19 } } translator.insert([entity_new]) entities = translator.query() assert len(entities) == 1 # Check location's None is saved as a geo_point column in crate op = "select latitude(_doc['location']), longitude(_doc['location']), temperature from " \ "etroom order by time_index ASC" translator.cursor.execute(op) res = translator.cursor.fetchall() assert len(res) == 2 assert res[0] == [19.6389474, -98.9109537, None] assert res[1] == [None, None, 19] translator.clean()
def test_auth_insert(set_env_vars, translator): entities = create_random_entities(1, 2, 3, use_time=True, use_geo=True) result = translator.insert(entities) assert result.rowcount > 0 translator.clean()