Exemple #1
0
    def test_request_odes_extract(self):

        extract_id = str(uuid4())
        extract_name = str(uuid4())
        wof_name = str(uuid4())
        created = datetime.now()
        extract_path = '/path/to/extracts/' + extract_id

        def response_content(url, request):
            '''
            '''
            MHP = request.method, url.hostname, url.path
            response_headers = {
                'Content-Type': 'application/json; charset=utf-8'
            }

            if MHP == ('POST', 'odes.mapzen.com', '/extracts'):
                if url.query == 'api_key=odes-xxxxxxx':
                    body = dict(parse_qsl(request.body))
                    self.assertIn('ready', body['email_subject'])
                    self.assertIn(extract_name, body['email_body_text'])
                    self.assertIn(created.strftime('%b %d, %Y'),
                                  body['email_body_text'])
                    self.assertIn(extract_path, body['email_body_text'])
                    self.assertIn(extract_name, body['email_body_html'])
                    self.assertIn(created.strftime('%b %d, %Y'),
                                  body['email_body_html'])
                    self.assertIn(extract_path, body['email_body_html'])

                    data = u'''{\r  "id": 999,\r  "status": "created",\r  "created_at": "2016-06-02T03:29:25.233Z",\r  "processed_at": "2016-06-02T04:20:11.000Z",\r  "bbox": {\r    "e": -122.24825,\r    "n": 37.81230,\r    "s": 37.79724,\r    "w": -122.26447\r  }\r}'''
                    return response(200,
                                    data.encode('utf8'),
                                    headers=response_headers)

            raise Exception(request.method, url, request.headers, request.body)

        url_for, request = Mock(), Mock()
        url_for.return_value = '/path/to/extracts/' + extract_id
        request.headers.get.return_value = 'nothing'

        with HTTMock(response_content):
            bbox = (-122.26447, 37.79724, -122.24825, 37.81230)
            envelope = data.Envelope(None, bbox)
            wof = data.WoF(None, wof_name)
            extract = data.Extract(extract_id, extract_name, envelope, None,
                                   None, created, wof)
            o = odes.request_odes_extract(extract, request, url_for,
                                          'odes-xxxxxxx')

        self.assertEqual(o.id, str(999))
        self.assertEqual(url_for.mock_calls[0],
                         mock.call('ODES.get_extract', extract_id=extract_id))
        self.assertEqual(url_for.mock_calls[1], mock.call('ODES.get_extracts'))
Exemple #2
0
    def test_add_extract_envelope(self):
        db, name = Mock(), str(uuid4())
        envelope = data.Envelope('xyz',
                                 [-122.26447, 37.79724, -122.24825, 37.81230])
        wof = data.WoF(85921881, 'Oakland')
        extract_id = data.add_extract_envelope(db, name, envelope, wof)

        self.assertEqual(db.mock_calls[0][0], 'execute')
        self.assertEqual(
            db.mock_calls[0][1][1],
            (extract_id, name, envelope.id, envelope.bbox, wof.name, wof.id))
        self.assertEqual(
            db.mock_calls[0][1][0], '''
        INSERT INTO extracts
        (id, name, envelope_id, envelope_bbox, wof_name, wof_id, created)
        VALUES (%s, %s, %s, %s, %s, %s, NOW())
        ''')
Exemple #3
0
    def test_set_extract(self):
        db, name = Mock(), str(uuid4())
        envelope = data.Envelope('xyz',
                                 [-122.26447, 37.79724, -122.24825, 37.81230])
        wof = data.WoF(85921881, 'Oakland')
        odes = data.ODES('4')
        extract = data.Extract('123', name, envelope, odes, 5, None, wof)
        data.set_extract(db, extract)

        self.assertEqual(db.mock_calls[0][0], 'execute')
        self.assertEqual(
            db.mock_calls[0][1][1],
            (name, 'xyz', [-122.26447, 37.79724, -122.24825, 37.8123
                           ], '4', 5, 'Oakland', 85921881, '123'))
        self.assertEqual(
            db.mock_calls[0][1][0], '''
        UPDATE extracts
        SET name = %s, envelope_id = %s, envelope_bbox = %s, odes_id = %s,
            user_id = %s, wof_name = %s, wof_id = %s
        WHERE id = %s
        ''')