コード例 #1
0
ファイル: api_move_test.py プロジェクト: gomyar/metaphor
    def setUp(self):
        self.maxDiff = None
        client = MongoClient()
        client.drop_database('metaphor2_test_db')
        self.db = client.metaphor2_test_db
        self.schema = Schema(self.db)
        self.schema.create_initial_schema()

        self.employee_spec = self.schema.create_spec('employee')
        self.schema.create_field('employee', 'name', 'str')
        self.schema.create_field('employee', 'age', 'int')
        self.schema.create_field('employee', 'created', 'datetime')

        self.division_spec = self.schema.create_spec('division')
        self.schema.create_field('division', 'name', 'str')
        self.schema.create_field('division', 'employees', 'collection', 'employee')
        self.schema.create_field('division', 'parttimers', 'linkcollection', 'employee')
        self.schema.create_field('division', 'contractors', 'linkcollection', 'employee')

        self.schema.create_field('root', 'employees', 'collection', 'employee')
        self.schema.create_field('root', 'former_employees', 'collection', 'employee')
        self.schema.create_field('root', 'divisions', 'collection', 'division')

        self.calcs_spec = self.schema.create_spec('calcs')
        self.schema.create_field('calcs', 'total_employees', 'calc', calc_str='sum(employees.age)')
        self.schema.create_field('calcs', 'total_former_employees', 'calc', calc_str='sum(former_employees.age)')
        #self.schema.create_field('calcs', 'total_division_parttimers', 'calc', calc_str='sum(divisions.parttimers.age)')
        #self.schema.create_field('calcs', 'total_division_contractors', 'calc', calc_str='sum(divisions.contractors.age)')

        self.schema.create_field('root', 'calcs', 'collection', 'calcs')

        self.api = Api(self.schema)
コード例 #2
0
    def setUp(self):
        self.maxDiff = None
        client = MongoClient()
        client.drop_database('metaphor2_test_db')
        #client.drop_database('mataphor2_test_db_integration')
        self.db = client.metaphor2_test_db
        #self.source_db = client.metaphor2_test_db_integration

        self.schema = Schema(self.db)
        self.schema.create_initial_schema()

        self.api = Api(self.schema)

        self.events = [
            {
                "operationType": "insert"
            },
        ]

        watched_collection = mock.Mock()
        watched_collection.watch.return_value = Stream(self.events)

        self.source_db = {'external_collection': watched_collection}

        self.integration = MongoChangeStreamIntegration(
            self.source_db, 'external_collection', [], self.api,
            self._process_change_func)

        self._call_log = []
コード例 #3
0
    def setUp(self):
        self.maxDiff = None
        client = MongoClient()
        client.drop_database('metaphor2_test_db')
        self.db = client.metaphor2_test_db

        Schema(self.db).create_initial_schema()

        self.app = create_app(self.db)
        self.api = self.app.config['api']
        self.schema = self.api.schema

        self.client = self.app.test_client()

        self.user_id = self.api.post('/users', {'username': '******', 'password': '******'})
        self.group_id = self.api.post('/groups', {'name': 'manager'})
        self.api.post('/groups/%s/grants' % self.group_id, {'type': 'read', 'url': '/employees'})
        self.api.post('/groups/%s/grants' % self.group_id, {'type': 'create', 'url': '/employees'})
        self.api.post('/users/%s/groups' % self.user_id, {'id': self.group_id})

        # add test data
        employee_spec = self.schema.add_spec('employee')
        self.schema.add_field(employee_spec, 'name', 'str')

        self.schema.add_field(self.schema.root, 'employees', 'collection', 'employee')

        for i in range(12):
            self.api.post('/employees', {'name': 'fred %s' % i})

        # login
        self.client.post('/login', data={
            "username": "******",
            "password": "******",
        }, follow_redirects=True)
コード例 #4
0
def create_app(db):
    schema = Schema(db)
    schema.load_schema()

    api = Api(schema)

    app = Flask(__name__)
    app.secret_key = 'keepitsecretkeepitsafe'
    app.config['api'] = api
    app.config['admin_api'] = AdminApi(schema)
    app.register_blueprint(api_bp)
    app.register_blueprint(client_bp)
    app.register_blueprint(admin_bp)
    app.register_blueprint(search_bp)
    app.register_blueprint(login_bp)

    init_login(app)

    @app.route("/")
    def index():
        return redirect(url_for('client.client_root'))

    integration_runner = IntegrationRunner(api, db)
    integration_runner.start()

    atexit.register(integration_runner.stop)

    return app
コード例 #5
0
    def setUp(self):
        self.maxDiff = None
        client = MongoClient()
        client.drop_database('metaphor2_test_db')
        self.db = client.metaphor2_test_db
        self.schema = Schema(self.db)

        self.api = Api(self.schema)

        self.employee_spec = self.schema.add_spec('employee')
        self.schema.add_field(self.employee_spec, 'name', 'str')
        self.schema.add_field(self.employee_spec, 'age', 'int')

        self.division_spec = self.schema.add_spec('division')
        self.schema.add_field(self.division_spec, 'name', 'str')
        self.schema.add_field(self.division_spec, 'employees', 'collection',
                              'employee')
        self.schema.add_field(self.division_spec, 'managers', 'linkcollection',
                              'employee')
        self.schema.add_calc(self.division_spec, 'older_managers',
                             'self.managers[age>30]')

        self.company_spec = self.schema.add_spec('company')
        self.schema.add_field(self.company_spec, 'name', 'str')
        self.schema.add_field(self.company_spec, 'division', 'link',
                              'division')
        self.schema.add_calc(self.company_spec, 'max_age',
                             'max(self.division.older_managers.age)')

        self.schema.add_field(self.schema.root, 'companies', 'collection',
                              'company')
        self.schema.add_field(self.schema.root, 'divisions', 'collection',
                              'division')
コード例 #6
0
    def setUp(self):
        self.maxDiff = None
        client = MongoClient()
        client.drop_database('metaphor2_test_db')
        self.db = client.metaphor2_test_db
        self.schema = Schema(self.db)

        self.updater = Updater(self.schema)

        self.employee_spec = self.schema.add_spec('employee')
        self.schema.add_field(self.employee_spec, 'name', 'str')
        self.schema.add_field(self.employee_spec, 'age', 'int')

        self.section_spec = self.schema.add_spec('section')
        self.schema.add_field(self.section_spec, 'name', 'str')
        self.schema.add_field(self.section_spec, 'members', 'linkcollection',
                              'employee')

        self.division_spec = self.schema.add_spec('division')
        self.schema.add_field(self.division_spec, 'name', 'str')
        self.schema.add_field(self.division_spec, 'employees', 'collection',
                              'employee')
        self.schema.add_field(self.division_spec, 'sections', 'collection',
                              'section')

        self.schema.add_field(self.schema.root, 'divisions', 'collection',
                              'division')

        self.aggregator = ReverseAggregator(self.schema)
コード例 #7
0
ファイル: move_resource_test.py プロジェクト: gomyar/metaphor
    def setUp(self):
        self.maxDiff = None
        client = MongoClient()
        client.drop_database('metaphor2_test_db')
        self.db = client.metaphor2_test_db
        self.schema = Schema(self.db)

        self.updater = Updater(self.schema)

        self.employee_spec = self.schema.add_spec('employee')
        self.schema.add_field(self.employee_spec, 'name', 'str')
        self.schema.add_field(self.employee_spec, 'age', 'int')

        self.schema.add_field(self.schema.root, 'current_employees', 'collection', 'employee')
        self.schema.add_field(self.schema.root, 'former_employees', 'collection', 'employee')

        self.calcs_spec = self.schema.add_spec('calcs')
コード例 #8
0
    def setUp(self):
        self.maxDiff = None
        client = MongoClient()
        client.drop_database('metaphor2_test_db')
        self.db = client.metaphor2_test_db
        self.schema = Schema(self.db)
        self.updater = Updater(self.schema)

        self.employee_spec = self.schema.add_spec('employee')
        self.schema.add_field(self.employee_spec, 'name', 'str')
        self.schema.add_field(self.schema.root, 'employees', 'collection',
                              'employee')

        self.api = Api(self.schema)

        self.db.delete_calc.create_index([
            ('update_id', pymongo.ASCENDING),
            ('resource_id', pymongo.ASCENDING),
        ],
                                         unique=True)
コード例 #9
0
ファイル: updater_test.py プロジェクト: gomyar/metaphor
    def setUp(self):
        self.maxDiff = None
        client = MongoClient()
        client.drop_database('metaphor2_test_db')
        self.db = client.metaphor2_test_db
        self.schema = Schema(self.db)
        self.schema.create_initial_schema()

        self.updater = Updater(self.schema)

        self.employee_spec = self.schema.create_spec('employee')
        self.schema.create_field('employee', 'name', 'str')
        self.schema.create_field('employee', 'age', 'int')

        self.division_spec = self.schema.create_spec('division')
        self.schema.create_field('division', 'name', 'str')
        self.schema.create_field('division', 'employees', 'collection',
                                 'employee')

        self.schema.create_field('root', 'divisions', 'collection', 'division')
コード例 #10
0
    def setUp(self):
        self.maxDiff = None
        client = MongoClient()
        client.drop_database('metaphor2_test_db')
        self.db = client.metaphor2_test_db

        Schema(self.db).create_initial_schema()

        self.app = create_app(self.db)
        self.api = self.app.config['api']
        self.schema = self.api.schema

        self.client = self.app.test_client()

        self.user_id = self.api.post('/users', {'username': '******', 'password': '******'})
        self.group_id = self.api.post('/groups', {'name': 'manager'})
        self.grant_id_1 = self.api.post('/groups/%s/grants' % self.group_id, {'type': 'read', 'url': '/employees'})
        self.api.post('/users/%s/groups' % self.user_id, {'id': self.group_id})

        self.client.post('/login', data={
            "username": "******",
            "password": "******",
        }, follow_redirects=True)
コード例 #11
0
ファイル: schema_types_test.py プロジェクト: gomyar/metaphor
 def setUp(self):
     client = MongoClient()
     client.drop_database('metaphor2_test_db')
     self.db = client.metaphor2_test_db
     self.schema = Schema(self.db)
     self.maxDiff = None
コード例 #12
0
ファイル: lrparse_test.py プロジェクト: gomyar/metaphor
    def setUp(self):
        self.maxDiff = None
        client = MongoClient()
        client.drop_database('metaphor2_test_db')
        self.db = client.metaphor2_test_db
        self.schema = Schema(self.db)

        self.db.metaphor_schema.insert_one({
            "specs" : {
                "employee" : {
                    "fields" : {
                        "name" : {
                            "type" : "str"
                        },
                        "pseudoname" : {
                            "type" : "str"
                        },
                        "age": {
                            "type": "int"
                        },
                        "division": {
                            "type": "link",
                            "target_spec_name": "division",
                        },
                    },
                },
                "division": {
                    "fields": {
                        "name": {
                            "type": "str",
                        },
                        "yearly_sales": {
                            "type": "int",
                        },
                        "sections": {
                            "type": "collection",
                            "target_spec_name": "section",
                        },
                        "parttimers": {
                            "type": "linkcollection",
                            "target_spec_name": "employee",
                        },
                        "partners": {
                            "type": "collection",
                            "target_spec_name": "employee",
                        },
                    },
                },
                "section": {
                    "fields": {
                        "name": {
                            "type": "str",
                        },
                    },
                },
            },
            "root": {
                "employees": {
                    "type": "collection",
                    "target_spec_name": "employee",
                },
                "divisions": {
                    "type": "collection",
                    "target_spec_name": "division",
                }
            },
        })
        self.schema.load_schema()
コード例 #13
0
ファイル: api_calc_test.py プロジェクト: gomyar/metaphor
    def setUp(self):
        self.maxDiff = None
        client = MongoClient()
        client.drop_database('metaphor2_test_db')
        self.db = client.metaphor2_test_db
        self.schema = Schema(self.db)

        self.db.metaphor_schema.insert_one({
            "specs" : {
                "employee" : {
                    "fields" : {
                        "name" : {
                            "type" : "str"
                        },
                        "age": {
                            "type": "int"
                        },
                        "division": {
                            "type": "link",
                            "target_spec_name": "division",
                        },
                        "division_link": {
                            "type": "calc",
                            "calc_str": "self.division",
                        },
                        "parttime_division_name": {
                            "type": "calc",
                            "calc_str": "self.name + (self.parent_section_parttimers.parent_division_sections.name)",
                        },
                    },
                },
                "division": {
                    "fields": {
                        "name": {
                            "type": "str",
                        },
                        "yearly_sales": {
                            "type": "int",
                        },
                        "sections": {
                            "type": "orderedcollection",
                            "target_spec_name": "section",
                        },
                        "primary_sections": {
                            "type": "calc",
                            "calc_str": "self.sections[name='primary']",
                        },
                        "average_section_total": {
                            "type": "calc",
                            "calc_str": "average(self.sections.section_total)",
                        },
                        "average_bracket_calc": {
                            "type": "calc",
                            "calc_str": "average(self.sections.section_total) + ((10 + sum(self.sections.section_total)) / 5)",
                        },
                        "older_employees": {
                            "type": "calc",
                            "calc_str": "self.link_employee_division[age>40]",
                        },
                    },
                },
                "section": {
                    "fields": {
                        "name": {
                            "type": "str",
                        },
                        "section_total": {
                            "type": "int",
                        },
                        "division_name": {
                            "type": "calc",
                            "calc_str": "self.parent_division_sections.name",
                        },
                        "distance_from_average": {
                            "type": "calc",
                            "calc_str": "self.section_total - average(self.parent_division_sections.sections.section_total)",
                        },
                        "parttimers": {
                            "type": "orderedcollection",
                            "target_spec_name": "employee",
                        },
                    },
                },
            },
            "root": {
                "employees": {
                    "type": "collection",
                    "target_spec_name": "employee",
                },
                "divisions": {
                    "type": "collection",
                    "target_spec_name": "division",
                }
            },
        })
        self.schema.load_schema()

        self.api = Api(self.schema)