Beispiel #1
0
 def test_objectid_fail(self):
     schema = {'id': {'type': 'objectid'}}
     doc = {'id': 'not_an_object_id'}
     v = Validator(schema, None)
     self.assertFalse(v.validate(doc))
     self.assertTrue('id' in v.errors)
     self.assertTrue('ObjectId' in v.errors['id'])
Beispiel #2
0
 def test_linestring_success(self):
     schema = {'location': {'type': 'linestring'}}
     doc = {'location': {"type": "LineString",
                         "coordinates": [[100.0, 0.0], [101.0, 1.0]]
                         }}
     v = Validator(schema)
     self.assertTrue(v.validate(doc))
Beispiel #3
0
 def test_geometry_not_compilant(self):
     schema = {'location': {'type': 'point'}}
     doc = {'location': {"type": "Point", "geometries": [10.0, 123.0]}}
     v = Validator(schema)
     self.assertFalse(v.validate(doc))
     self.assertTrue('location' in v.errors)
     self.assertTrue('point' in v.errors['location'])
Beispiel #4
0
 def test_point_coordinates_fail(self):
     schema = {'location': {'type': 'point'}}
     doc = {'location': {'type': "Point", 'coordinates': [123.0]}}
     v = Validator(schema)
     self.assertFalse(v.validate(doc))
     self.assertTrue('location' in v.errors)
     self.assertTrue('point' in v.errors['location'])
Beispiel #5
0
 def test_dbref_success(self):
     schema = {'id': {'type': 'dbref'}}
     doc = {
         'id': DBRef("SomeCollection", ObjectId("50656e4538345b39dd0414f0"))
     }
     v = Validator(schema, None)
     self.assertTrue(v.validate(doc))
Beispiel #6
0
 def test_geojson_not_compilant(self):
     schema = {'location': {'type': 'point'}}
     doc = {'location': [10.0, 123.0]}
     v = Validator(schema)
     self.assertFalse(v.validate(doc))
     self.assertTrue('location' in v.errors)
     self.assertTrue('Point' in v.errors['location'])
Beispiel #7
0
 def test_decimal_fail(self):
     schema = {'decimal': {'type': 'decimal'}}
     doc = {'decimal': 'not_a_decimal'}
     v = Validator(schema, None)
     self.assertFalse(v.validate(doc))
     self.assertTrue('decimal' in v.errors)
     self.assertTrue('decimal' in v.errors['decimal'])
 def test_multipolygon_success(self):
     schema = {"location": {"type": "multipolygon"}}
     doc = {
         "location": {
             "type":
             "MultiPolygon",
             "coordinates": [
                 [[
                     [102.0, 2.0],
                     [103.0, 2.0],
                     [103.0, 3.0],
                     [102.0, 3.0],
                     [102.0, 2.0],
                 ]],
                 [
                     [
                         [100.0, 0.0],
                         [101.0, 0.0],
                         [101.0, 1.0],
                         [100.0, 1.0],
                         [100.0, 0.0],
                     ],
                     [
                         [100.2, 0.2],
                         [100.8, 0.2],
                         [100.8, 0.8],
                         [100.2, 0.8],
                         [100.2, 0.2],
                     ],
                 ],
             ],
         }
     }
     v = Validator(schema)
     self.assertTrue(v.validate(doc))
 def test_point_coordinates_fail(self):
     schema = {"location": {"type": "point"}}
     doc = {"location": {"type": "Point", "coordinates": [123.0]}}
     v = Validator(schema)
     self.assertFalse(v.validate(doc))
     self.assertTrue("location" in v.errors)
     self.assertTrue("point" in v.errors["location"])
 def test_geometry_not_compilant(self):
     schema = {"location": {"type": "point"}}
     doc = {"location": {"type": "Point", "geometries": [10.0, 123.0]}}
     v = Validator(schema)
     self.assertFalse(v.validate(doc))
     self.assertTrue("location" in v.errors)
     self.assertTrue("point" in v.errors["location"])
 def test_dbref_fail(self):
     schema = {"id": {"type": "dbref"}}
     doc = {"id": "not_an_object_id"}
     v = Validator(schema, None)
     self.assertFalse(v.validate(doc))
     self.assertTrue("id" in v.errors)
     self.assertTrue("dbref" in v.errors["id"])
 def test_decimal_fail(self):
     schema = {"decimal": {"type": "decimal"}}
     doc = {"decimal": "not_a_decimal"}
     v = Validator(schema, None)
     self.assertFalse(v.validate(doc))
     self.assertTrue("decimal" in v.errors)
     self.assertTrue("decimal" in v.errors["decimal"])
Beispiel #13
0
def admin_apps_do(app_name):
    apps_path = Path(settings.config.APPS_PATH)

    action = request.json.get('action')
    if not action in ['enable', 'disable']:
        abort(400)

    app_path = apps_path / app_name

    # Check if app is under apps_path
    try:
        app_path.relative_to(apps_path)
    except ValueError:
        abort(404)

    if not app_path.exists():
        abort(404)

    app_db = app.data.pymongo('app').db['app']
    if action == 'disable':
        app_db.remove(dict(name=app_name))
        return Response(status=204)
    elif action == 'enable':
        schema = settings.config.DOMAIN['app']['schema']
        validator = Validator(schema=schema, resource='app')

        with (app_path / 'manifest.json').open('r') as ifile:
            data = ifile.read()
            manifest = json.loads(data)
            app_config = manifest['app_config']

            logo = app_config.pop('logo')

            existing = app_db.find_one(dict(uappid=app_config['uappid']))
            if existing:
                app_db.remove(dict(uappid=app_config['uappid']))

            if not validator.validate(app_config):
                print("Validation error: ", validator.errors)
                abort(422, "Invalid app data")

            app_item = App(**app_config)

            app_config['logo'] = logo

            if app_config.get('logo'):
                try:
                    logofile = (app_path / app_config.get('logo')).open('rb')
                    app_item.logo = logofile
                except:
                    pass
            app_item.prepare_data()

            app_item.save()
        return Response(status=201)
    else:
        abort(404, 'Invalid action')
Beispiel #14
0
 def test_featurecollection_fail(self):
     schema = {'locations': {'type': 'featurecollection'}}
     doc = {"locations": {"type": "FeatureCollection",
                          "geometry": {"type": "Point",
                                       "coordinates": [100.0, 0.0]}
                          }
            }
     v = Validator(schema)
     self.assertFalse(v.validate(doc))
     self.assertTrue('locations' in v.errors)
     self.assertTrue('featurecollection' in v.errors['locations'])
Beispiel #15
0
 def test_featurecollection_success(self):
     schema = {'locations': {'type': 'featurecollection'}}
     doc = {"locations": {"type": "FeatureCollection",
                          "features": [
                              {"type": "Feature",
                               "geometry": {"type": "Point",
                                            "coordinates": [102.0, 0.5]}
                               }]
                          }
            }
     v = Validator(schema)
     self.assertTrue(v.validate(doc))
Beispiel #16
0
 def test_feature_success(self):
     schema = {'locations': {'type': 'feature'}}
     doc = {"locations": {"type": "Feature",
                          "geometry": {"type": "Polygon",
                                       "coordinates": [[[100.0, 0.0],
                                                        [101.0, 0.0],
                                                        [101.0, 1.0],
                                                        [100.0, 1.0],
                                                        [100.0, 0.0]]]}
                          }
            }
     v = Validator(schema)
     self.assertTrue(v.validate(doc))