Example #1
0
def test_adding_affairs(elastic_repository: ElasticAffairRepository,
                        xml_affairs: List[AffairEntity]):
    elastic_repository.client.indices.delete(
        index=elastic_repository.index_name)
    for affair in xml_affairs:
        assert elastic_repository.add(affair=affair)
    with pytest.raises(AlreadyExistingAffairUuid):
        elastic_repository.add(affair=xml_affairs[0])
Example #2
0
def test_index_created_and_fetch_some_affairs(
        elastic_repository: ElasticAffairRepository,
        xml_affairs: List[AffairEntity]):
    elastic_repository.client.indices.delete(
        index=elastic_repository.index_name)
    elastic_repository.create_indice()

    for affair in xml_affairs:
        elastic_repository.add(affair=affair)

    all_affairs: List[AffairEntity] = elastic_repository.get_all()
    assert len(all_affairs) == len(xml_affairs)
Example #3
0
def test_location_query(elastic_repository: ElasticAffairRepository,
                        xml_affairs: List[AffairEntity]):
    p = Path(__file__).resolve().parent / "../../data/polygons/chelles.json"
    with p.open() as f:
        polygon_chelles = json.load(f)

    all_affairs: List[AffairEntity] = elastic_repository.get_from_polygon(
        multipolygon=polygon_chelles[0][0])
    assert len(all_affairs) == len([
        affair for affair in xml_affairs
        if affair.eventLocation["address"][0] == "Chelles"
    ])
Example #4
0
def elastic_repository(es_client,
                       affairs_index_name) -> ElasticAffairRepository:
    repo = ElasticAffairRepository(es_client, index_name=affairs_index_name)
    return repo
Example #5
0
 def __init__(self, config):
     super().__init__(config)
     self.client = Elasticsearch(config.ELASTIC_HOST,
                                 http_auth=(config.ELASTIC_USER,
                                            config.ELASTIC_PASSWORD))
     self.affair = ElasticAffairRepository(client=self.client)