def setUp(self): super().setUp() with self.client: self.loginTestUser() ds1 = DataSource(id=1, label="Test Source", transfer_mechanism_type="curl") ds2 = DataSource(id=2, label="Another Source", transfer_mechanism_type="curl") transform = Transform( from_data_source_id=1, to_data_source_id=2, transform_id=1, preference_order=1, transform_type="change_host", transform_options={"new_host": "example.org"}) dest = Destination(id=1, label="Test Destination") transform.for_destinations.append(dest) self.addToDatabase(ds1, ds2, transform, dest)
def setUp(self): super().setUp() with self.client: self.loginTestUser() origin_source = DataSource(id=1, label="Test Source", transfer_mechanism_type="curl") origin_source.url_matchers.append( UrlMatcher(matcher_id=1, matcher_type="scheme_and_host", matcher_options=dict(scheme="http", host="example.com"))) target_source_1 = DataSource(id=2, label="Target Source 1", transfer_mechanism_type="curl") target_source_1.url_matchers.append( UrlMatcher(matcher_id=1, matcher_type="scheme_and_host", matcher_options=dict(scheme="http", host="example.org"))) target_source_2 = DataSource(id=3, label="Target Source 2", transfer_mechanism_type="curl") target_source_2.url_matchers.append( UrlMatcher(matcher_id=1, matcher_type="scheme_and_host", matcher_options=dict(scheme="http", host="example.net"))) transform_1 = Transform( from_data_source=origin_source, to_data_source=target_source_1, transform_id=1, preference_order=1, transform_type="change_host", transform_options=dict(new_host="example.org")) dest = Destination(id=1, label="Test Destination") transform_2 = Transform( from_data_source=origin_source, to_data_source=target_source_2, for_destinations=[dest], transform_id=2, preference_order=2, transform_type="change_host", transform_options=dict(new_host="example.net")) self.addToDatabase(origin_source, target_source_1, target_source_2, dest, transform_1, transform_2)
def initialize_default_datasources(db, app): # pre-populate the datasources datasource_names = [ datasource.name for datasource in DataSource.query.all() ] for datasource in _config.DEFAULT_DATASOURCES: if datasource["name"] not in datasource_names: connection_details = datasource["connection_details"] # subtitute $HOST_USER_DIR in absolute_host_path if "absolute_host_path" in connection_details: if "$HOST_USER_DIR" in connection_details[ "absolute_host_path"]: absolute_host_path = connection_details[ "absolute_host_path"] connection_details[ "absolute_host_path"] = absolute_host_path.replace( "$HOST_USER_DIR", app.config["HOST_USER_DIR"]) ds = DataSource( name=datasource["name"], connection_details=connection_details, source_type=datasource["source_type"], ) db.session.add(ds) db.session.commit()
def create_source(source_name): logger.debug("### Create source [{}] ###".format(source_name)) source = DataSource(source_name=source_name) db_session.add(source) db_session.commit() return source.source_id
def test_list_sources(self): with self.client as client: self.loginTestUser() ds = DataSource(label="Test Source", transfer_mechanism_type="curl") self.addToDatabase(ds) r = client.get("/data_sources", follow_redirects=True) self.assertTrue(b"Test Source" in r.data)
def add_data_source(): name = flask.request.json["name"] hierarchy_rank = flask.request.json["hierarchy_rank"] api_key = flask.request.json["api_key"] or "" new_ds = DataSource(name=name, hierarchy_rank=hierarchy_rank, api_key=api_key) db.session.add(new_ds) db.session.commit() return data_source_schema.jsonify(new_ds)
def setUp(self): super().setUp() with self.client: self.loginTestUser() ds = DataSource(id=1, label="Test Source", transfer_mechanism_type="curl") matcher = UrlMatcher(data_source_id=1, matcher_id=1, matcher_type="scheme_and_host", matcher_options={"scheme": "http", "host": "example.com"}) self.addToDatabase(ds, matcher)
def post(self, name): if DataSource.query.filter( DataSource.name == name).count() > 0: raise DataSourceNameInUse() new_ds = DataSource( name=name, source_type=request.json["source_type"], connection_details=request.json["connection_details"]) db.session.add(new_ds) db.session.commit() return datasource_schema.dump(new_ds)
def test_prevent_duplicate_source_label(self): with self.client as client: self.loginTestUser() ds = DataSource(label="Test Source", transfer_mechanism_type="curl") self.addToDatabase(ds) r = client.post("/data_sources/new", data=dict(label="Test Source", transfer_mechanism_type="curl"), follow_redirects=True) self.assertTrue(b"Label already taken" in r.data) self.assertEqual(DataSource.query.count(), 1)
def test_add_source(self): with self.client as client: self.loginTestUser() ds = DataSource(label="Test Source", transfer_mechanism_type="curl") self.addToDatabase(ds) r = client.post("/data_sources/new", data=dict(label="Another Source", transfer_mechanism_type="curl"), follow_redirects=True) self.assertTrue(b"Data source saved" in r.data) self.assertEqual(DataSource.query.count(), 2)
def setUp(self): super().setUp() with self.client as c: self.loginTestUser() test_conf_path = os.path.join(os.path.dirname(__file__), "../test_config.json") test_conf = open(test_conf_path).read() load_configuration(test_conf) ds = DataSource(id=4, label="Test Source", transfer_mechanism_type="curl") self.addToDatabase(ds) self.ftp_source_id = DataSource.query.filter(DataSource.label == "Example FTP").first().id c.get("/logout")
def test_edit_source(self): with self.client as client: self.loginTestUser() ds = DataSource(id=1, label="Test Source", transfer_mechanism_type="curl") self.addToDatabase(ds) r = client.post("/data_sources/1/edit", data=dict(label="Renamed Source", transfer_mechanism_type="curl"), follow_redirects=True) self.assertTrue(b"Data source updated" in r.data) self.assertEqual(DataSource.query.first().label, "Renamed Source")
def post(self, name): if DataSource.query.filter( DataSource.name == name).count() > 0: raise DataSourceNameInUse() new_ds = DataSource( name=name, source_type=request.json["source_type"], connection_details=request.json["connection_details"], ) db.session.add(new_ds) try: db.session.commit() except Exception: db.session.rollback() return {"message": "Failed to create data source."}, 500 return datasource_schema.dump(new_ds)