Пример #1
0
    def setup(self):
        super().setup()

        index = 'localities'
        if self.config_delete_indexes:
            self.es_client.delete_index(index, True)
            self.es_client.create_index(index)

        journal = geomodel.wrap_journal(self.es_client)

        def state(username, locs):
            return geomodel.State('locality', username, locs)

        def locality(cfg):
            return geomodel.Locality(**cfg)

        test_state = state('tester1', [
            locality({
                'sourceipaddress': '1.2.3.4',
                'city': 'Portland',
                'country': 'US',
                'lastaction': toUTC(datetime.now()),
                'latitude': 45.5234,
                'longitude': -122.6762,
                'radius': 50,
            })
        ])

        journal(geomodel.Entry.new(test_state), index)
        self.refresh(index)
Пример #2
0
    def test_journaling(self):
        journal = locality.wrap_journal(self.es_client)

        test_entry = locality.Entry(
            'testingid1',
            locality.State('locality', 't1', [
                locality.Locality(
                    sourceipaddress='1.2.3.4',
                    city='Toronto',
                    country='CA',
                    lastaction=toUTC(datetime.now()) - timedelta(days=3),
                    latitude=43.6529,
                    longitude=-79.3849,
                    radius=50),
                locality.Locality(
                    sourceipaddress='32.64.128.255',
                    city='Berlin',
                    country='DE',
                    lastaction=toUTC(datetime.now()) - timedelta(minutes=30),
                    latitude=52.520008,
                    longitude=13.404954,
                    radius=50)
            ]))

        journal(test_entry, self.event_index_name)

        self.refresh(self.event_index_name)

        query_iface = locality.wrap_query(self.es_client)
        loc_cfg = config.Localities(self.event_index_name, 30, 50.0)

        entry = locality.find(query_iface, 't1', loc_cfg.es_index)

        assert entry is not None
        assert entry.state.username == 't1'
Пример #3
0
    def setup(self):
        super().setup()

        index = 'localities'
        if self.config_delete_indexes:
            self.es_client.delete_index(index, True)
            self.es_client.create_index(index)

        journal = geomodel.wrap_journal(self.es_client)

        def state(username, locs):
            return geomodel.State('locality', username, locs)

        def locality(cfg):
            return geomodel.Locality(**cfg)

        test_states = [
            state(
                'tester1',
                [
                    locality({
                        'sourceipaddress':
                        '1.2.3.4',
                        'city':
                        'San Francisco',
                        'country':
                        'US',
                        'lastaction':
                        toUTC(datetime.now()) - timedelta(minutes=3),
                        'latitude':
                        37.773972,
                        'longitude':
                        -122.431297,
                        'radius':
                        50,
                    }),
                    locality({
                        'sourceipaddress':
                        '9.8.7.6',
                        'city':
                        'Toronto',
                        'country':
                        'CA',
                        'lastaction':
                        toUTC(datetime.now()) - timedelta(minutes=5),
                        'latitude':
                        43.6529,
                        'longitude':
                        -79.3849,
                        'radius':
                        50,
                    }),
                ],
            )
        ]

        for state in test_states:
            journal(geomodel.Entry.new(state), index)
        self.refresh(index)
Пример #4
0
    def setup(self):
        super().setup()

        if self.config_delete_indexes:
            self.es_client.delete_index(GeoModelTest.localities_index, True)
            self.es_client.create_index(GeoModelTest.localities_index)

        journal = geomodel.wrap_journal(self.es_client)

        states = self.test_states if hasattr(self, 'test_states') else []

        for state in states:
            journal(geomodel.Entry.new(state), GeoModelTest.localities_index)

        self.refresh(GeoModelTest.localities_index)