Пример #1
0
    def test_changesets(self, mock_get_osm_api):
        mock_osm = mock_get_osm_api.return_value
        client = self.app.test_client()
        p1_id = database.add_point(46.06, 24.10, 'Eau de Web',
                                   'link1', 'pub', 'my-open-id')
        p2_id = database.add_point(46.07, 24.11, 'blabla',
                                   '', 'bar', 'my-open-id')
        values = [13, 45]
        mock_osm.ChangesetCreate.return_value = 13
        mock_osm.NodeCreate.side_effect = lambda *args, **kwargs: {'id': values.pop(0)}

        database.submit_points_to_osm([p1_id, p2_id])
        self.db.session.commit()

        rdb = flask.current_app.rdb
        p1 = rdb.get_object('point', p1_id)
        p2 = rdb.get_object('point', p2_id)
        self.assertEquals(p1['osm_id'], 13)
        self.assertEquals(p2['osm_id'], 45)
        self.assertEquals(mock_osm.ChangesetCreate.call_count, 1)
        tags1 = {'name': 'Eau de Web', 'website': 'link1',
                 'amenity': 'pub', 'source': 'poi.grep.ro'}
        tags2 = {'name': 'blabla', 'amenity': 'bar', 'source': 'poi.grep.ro'}
        self.assertEquals(mock_osm.NodeCreate.call_args_list, [
            (({u'lat': 46.06, u'lon': 24.1, u'tag': tags1},), {}),
            (({u'lat': 46.07, u'lon': 24.11, u'tag': tags2},), {})])
        self.assertEquals(mock_osm.ChangesetClose.call_count, 1)
Пример #2
0
    def test_show_map(self):
        client = self.app.test_client()

        database.add_point(45, 25, 'name', 'url', 'type', 'admin-user')

        response = client.get('/points/1')
        self.assertEqual(response.status_code, 200)
Пример #3
0
 def test_homepage_points(self):
     database.add_point(13, 22, 'zebar', '', 'bar', 'contrib')
     from osmpoint.frontend import points_for_homepage
     for p in points_for_homepage():
         if p['name'] == 'zebar':
             break
     else:
         self.fail('point "zebar" not found')
     self.assertEqual(p['lat'], 13)
     self.assertEqual(p['lon'], 22)
Пример #4
0
    def test_point_is_stored(self):
        database.add_point(46.06, 24.10, 'Eau de Web',
                           'website', 'business', 'my-open-id')

        points = self.get_all_points()
        self.assertEquals(len(points), 1)

        point = points[0]
        self.assertEquals(point['lat'], 46.06)
        self.assertEquals(point['lon'], 24.10)
        self.assertEquals(point['name'], 'Eau de Web')
        self.assertEquals(point['url'], 'website')
        self.assertEquals(point['amenity'], 'business')
        self.assertEquals(point['user_open_id'], 'my-open-id')
Пример #5
0
 def test_homepage_marker_balloon(self):
     point_id = database.add_point(44.4324, 26.1020, 'S.A.L.T.',
                                   None, 'pub', 'my-open-id')
     browser.get('http://127.0.0.1:57909/')
     js("$('img', M.collections['Locations'].layer.markers[0]"
        ".icon.imageDiv)[0]").click()
     self.assertIn("S.A.L.T. (pub)", js("$('.olPopupContent').text()"))
Пример #6
0
    def test_del_point(self):
        p_id = database.add_point(1, 2, 'X', 'Y', 'Z', 'W')

        database.del_point(p_id)

        points = self.get_all_points()
        self.assertEquals(len(points), 0)
Пример #7
0
 def test_log_insert(self):
     point = database.add_point(45, 25, 'name', 'url', 'type', 'user')
     self.assertEqual(len(self.log_records), 1)
     msg = self.log_records[0]
     self.assertTrue(msg.startswith("INSERT INTO point "))
     self.assertTrue(msg.endswith("(45.0, 25.0, 'name', 'url', 'type', "
                                  "None, 'user')"))
Пример #8
0
    def test_submit_points_log_records(self, mock_get_osm_api):
        import logging
        self.log_records = log_records = []
        class TestingHandler(logging.Handler):
            def emit(self, record):
                log_records.append(self.format(record))
        self.log_handler = TestingHandler()
        self.db_logger = logging.getLogger('osmpoint.database.osm')
        self.db_logger.addHandler(self.log_handler)
        self.addCleanup(self.db_logger.removeHandler, self.log_handler)

        mock_osm = mock_get_osm_api.return_value
        mock_osm.ChangesetCreate.return_value = 999
        mock_osm.NodeCreate.return_value = {'a': 'b', 'id': 13}

        client = self.app.test_client()
        p_id = database.add_point(46.06, 24.10, 'Eau de Web',
                                  'link1', 'pub', 'my-open-id')
        log_records[:] = []

        database.submit_points_to_osm([p_id])

        self.assertEqual(self.log_records, [
            "Begin OSM changeset 999",
            "OSM point: {'a': 'b', 'id': 13}",
            "OSM changeset committed",
        ])
Пример #9
0
    def test_cancel_deletion(self):
        client = self.app.test_client()
        client.post('/test_login', data={'user_id': 'admin-user'})

        p_id = database.add_point(45, 25, 'name', 'url', 'type', 'admin-user')

        address = flask.url_for('.delete_point', point_id=p_id)
        response = client.post(address)

        points = self.get_all_points()
        self.assertEqual(len(points), 1)
Пример #10
0
    def test_submitted_point_url(self):
        self.app.config['OSM_API'] = 'fake.api.example.com'

        p_id = database.add_point(46.06, 24.10, 'EdW', '', 'pub', 'my-open-id')
        database.set_point_field(p_id, 'osm_id', 1234)

        client = self.app.test_client()
        client.post('/test_login', data={'user_id': 'admin-user'})
        response = client.get('/points/%d' % p_id)
        url = 'http://fake.api.example.com/browse/node/1234'
        self.assertIn('<a href="%s">' % url, response.data)
Пример #11
0
    def test_edit_point_with_no_name(self):
        client = self.app.test_client()
        client.post('/test_login', data={'user_id': 'admin-user'})

        p_id = database.add_point(45, 25, 'old_name', 'url', 'type', 'admin-user')

        point_data = {'lat': 45, 'lon': 25, 'amenity': 'new_type',
                      'name': '', 'url': 'url', 'id': p_id}
        address = flask.url_for('.edit_point', point_id=p_id)
        response = client.post(address, data=point_data)
        point = self.get_all_points()[0]
        self.assertEqual(point['name'], 'old_name')
Пример #12
0
    def test_confirm_delete_point(self):
        client = self.app.test_client()
        client.post('/test_login', data={'user_id': 'admin-user'})

        p_id = database.add_point(45, 25, 'name', 'url', 'type', 'admin-user')

        address = flask.url_for('.delete_point', point_id=p_id)
        response = client.post(address, data={'confirm': 'true'})

        self.assertEqual(response.status_code, 200)
        points = self.get_all_points()
        self.assertEqual(len(points), 0)
Пример #13
0
    def test_submit_already_submitted_point(self, mock_get_osm_api):
        client = self.app.test_client()
        client.post('/test_login', data={'user_id': 'admin-user'})

        p_id = database.add_point(45, 25, 'name', 'url', 'type', 'admin-user')
        database.set_point_field(p_id, 'osm_id', 100)

        address = flask.url_for('.send_point', point_id=p_id)
        response = client.post(address)

        self.assertFalse(mock_get_osm_api.called)
        self.assertEqual(response.status_code, 400)
Пример #14
0
    def test_edit_point_by_non_admin(self):
        client = self.app.test_client()
        self.app.config['OSMPOINT_ADMINS'] = []
        client.post('/test_login', data={'user_id': 'non-admin-user'})

        p_id = database.add_point(45, 25, 'name', 'url',
                                  'type', 'non-admin-user')

        point_data = {'lat': 40, 'lon': 20, 'name': 'wrong',
                      'url': 'url', 'type': 'type', 'id': p_id}
        address = flask.url_for('.edit_point', point_id=p_id)
        response = client.post(address, data=point_data)
        self.assertEqual(response.status_code, 403)
Пример #15
0
    def test_edit_point_with_wrong_coords(self):
        client = self.app.test_client()
        client.post('/test_login', data={'user_id': 'admin-user'})

        p_id = database.add_point(45, 25, 'name', 'url', 'type', 'admin-user')

        point_data = {'lat': 91, 'lon': 181, 'name': 'wrong',
                      'url': 'url', 'type': 'pub', 'id': p_id}
        address = flask.url_for('.edit_point', point_id=p_id)
        response = client.post(address, data=point_data)
        point = self.get_all_points()[0]
        self.assertEqual(point['lat'], 45)
        self.assertEqual(point['lon'], 25)
Пример #16
0
    def test_show_points(self):
        point_id = database.add_point(1, 2, 'location_name',
                                      'link', 'bar', 'user_name')

        client = self.app.test_client()

        response = client.get('/points')
        self.assertEquals(response.status_code, 200)
        self.assertIn('location_name', response.data)

        database.del_point(point_id)

        response = client.get('/points')
        self.assertNotIn('location_name', response.data)
Пример #17
0
    def test_submit_by_non_admin(self, mock_get_osm_api):
        self.app.config['OSMPOINT_ADMINS'] = []
        client = self.app.test_client()

        client.post('/test_login', data={'user_id': 'non-admin'})

        p_id = database.add_point(45, 25, 'name', 'url', 'type', 'non-admin')

        address = flask.url_for('.send_point', point_id=p_id)
        response = client.post(address)

        self.assertFalse(mock_get_osm_api.called)
        points = self.get_all_points()
        self.assertEqual(points[0]['osm_id'], None)
        self.assertEqual(response.status_code, 403)
Пример #18
0
    def test_submit_points_to_osm(self, mock_get_osm_api):
        mock_osm = mock_get_osm_api.return_value

        client = self.app.test_client()
        client.post('/test_login', data={'user_id': 'admin-user'})

        p_id = database.add_point(46.06, 24.10, 'Eau de Web',
                                  'link1', 'pub', 'admin-user')

        mock_osm.ChangesetCreate.return_value = 13
        mock_osm.NodeCreate.return_value = {'id': 50}

        address = flask.url_for('.send_point', point_id=p_id)
        response = client.post(address)

        self.assertEqual(response.status_code, 200)

        tags = {'name': 'Eau de Web',
                'website': 'link1',
                'amenity': 'pub',
                'source': 'poi.grep.ro'}
        ok_data = {u'lat': 46.06, u'lon': 24.1, u'tag': tags}
        mock_osm.NodeCreate.assert_called_once_with(ok_data)
Пример #19
0
 def _point_fixture(self, *args, **kwargs):
     point_id = database.add_point(*args, **kwargs)
     self.log_records[:] = []
     return point_id
Пример #20
0
 def setUp(self):
     super(ModerationPageTest, self).setUp()
     self.p1_id = database.add_point(10., 10., 'NameOne', '', 'pub', 'user1')
     self.p2_id = database.add_point(20., 20., 'NameTwo', '', 'pub', 'user2')
     self.client = self.app.test_client()
     self.client.post('/test_login', data={'user_id': 'admin-user'})