Beispiel #1
0
    def test_remove_ok(self):
        test_id = db.all()[0].id
        # verify we get it
        rv = self.client.get(f'/spots/{test_id}')
        self.assertEqual(rv.status_code, 200)

        # remove it
        rv = self.client.delete(f'/spots/{test_id}')
        self.assertEqual(rv.status_code, 204)

        # verify the 404
        rv = self.client.get(f'/spots/{test_id}')
        self.assertEqual(rv.status_code, 404)
Beispiel #2
0
 def test_create_ok(self):
     payload = {
         'data': {
             'type': 'spots',
             'attributes': {
                 'description': 'Rincon',
                 'spot_id': '278'
             }
         }
     }
     headers = {'Content-Type': 'application/vnd.api+json'}
     rv = self.client.post('/spots', data=json.dumps(payload), headers=headers)
     data = json.loads(rv.data.decode('utf-8'))
     self.assertEqual(rv.status_code, 201)
     self.assertEqual(data['data']['id'], db.all()[-1].id)
Beispiel #3
0
    def test_create_with_id_conflict(self):
        payload = {
            'data': {
                'id': db.all()[0].id, # this id will conflict
                'type': 'spots',
                'attributes': {
                    'description': 'Rincon',
                    'spot_id': '300' # spot_id won't conflict
                }
            }
        }
        headers = {'Content-Type': 'application/vnd.api+json'}
        rv = self.client.post('/spots', data=json.dumps(payload), headers=headers)

        data = json.loads(rv.data.decode('utf-8'))
        self.assertEqual(rv.status_code, 409)
Beispiel #4
0
def get_reports():

    #TODO: extract params processing to clean things up.
    fields = None
    errs = None
    if 'fields[reports]' in request.args:
        fields, errs = prepare_params(request.args['fields[reports]'])
    if errs:
        return cant_process([f'field=({field}) is invalid' for field in errs])

    # override the groupings with actual lists of fields if necessary
    if fields is None:
        fields = FIELDS_FULL
    elif 'basic' in fields:
        fields = FIELDS_BASIC

    spot_ids = [spot.spot_id for spot in spots_db.all()]
    results = surfline.fetch_spots(spot_ids)
    parsed = [{'type': 'reports', 'attributes': r.json()} for r in results]

    schema = ReportSchema(many=True, only=fields)
    data, _ = schema.load({'data': parsed})

    return ok(schema.dump(data).data)
Beispiel #5
0
 def test_get_one_ok(self):
     test_id = db.all()[0].id
     rv = self.client.get('/spots/{}'.format(test_id))
     self.assertEqual(rv.status_code, 200)
     data = json.loads(rv.data.decode('utf-8'))
     self.assertEqual(data['data']['id'], test_id)