コード例 #1
0
def test_client():
    test_client = app.test_client()

    ctx = app.app_context()
    ctx.push()

    yield test_client

    ctx.pop()
コード例 #2
0
def main():
    from src.app import app
    with app.app_context():
        logging.info("Start importing.")
        import_dataset("wave", Wave)
        # import_dataset("conditions", Conditions)
        import_dataset("tides", Tide)
        import_dataset("weather", Weather)
        import_dataset("wind", Wind)
        logging.info("Import finished.")
コード例 #3
0
    def test_app_can_respond_to_challenges(self, mocker):
        with app.app_context():
            with app.test_client() as c:
                data = {
                    "token": os.environ.get("VERIFICATION_TOKEN"),
                    "challenge": 'my challenge'
                }

                response = c.post('/listening',
                                  data=json.dumps(data),
                                  content_type='application/json')
                expect(response.status_code).to(equal(200))
コード例 #4
0
ファイル: conftest.py プロジェクト: yuri0051/vehicle_api
def client():
    db_fd, app.config['DATABASE'] = tempfile.mkstemp()
    app.config['TESTING'] = True

    with app.test_client() as client:
        with app.app_context():
            init_db()

        yield client

    os.close(db_fd)
    os.unlink(app.config['DATABASE'])
コード例 #5
0
    def test_event_handler_understands_mentions(self):
        with app.app_context() as c:
            event = {
                "type": "app_mention",
                "user": "******",
                "text": "<@U0LAN0Z89> is it everything a river should be?",
                "ts": "1515449522.000016",
                "channel": "C0LAN2Q65",
                "event_ts": "1515449522000016"
            }

            data = {
                "token": os.environ.get("VERIFICATION_TOKEN"),
                "event": event
            }

            response = _event_handler("app_mention", data)
            expect(response.status_code).to(equal(200))
            expect(response.data.decode('utf-8')).to(contain("Parse"))
コード例 #6
0
    def test_user_can_mention_bot(self, mocker):
        with app.app_context():
            with app.test_client() as c:
                event = {
                    "type": "app_mention",
                    "user": "******",
                    "text": "<@U0LAN0Z89> is it everything a river should be?",
                    "ts": "1515449522.000016",
                    "channel": "C0LAN2Q65",
                    "event_ts": "1515449522000016"
                }

                data = {
                    "token": os.environ.get("VERIFICATION_TOKEN"),
                    "event": event
                }

                response = c.post('/listening',
                                  data=json.dumps(data),
                                  content_type='application/json')
                expect(response.status_code).to(equal(200))
コード例 #7
0
def main():
    from src.app import app
    with app.app_context():
        update_all_geodata()
コード例 #8
0
def schedule_task():
    with app.app_context():
        service.trim()
コード例 #9
0
def main():
    from src.app import app
    with app.app_context():
        db.session.query(Spot).delete()
        import_spots(parse_data(get_data()))
コード例 #10
0
ファイル: ingest.py プロジェクト: pndaly/SASSy
def ingest_avro(packet=None):

    # check input(s)
    if packet is None or 'candidate' not in packet or 'prv_candidates' not in packet:
        raise Exception('ingest_avro() entry: packet is empty!')

    # ingest data
    with app.app_context():

        ra = packet['candidate'].pop('ra')
        dec = packet['candidate'].pop('dec')
        location = f'srid=4035;POINT({ra} {dec})'
        c = SkyCoord(ra, dec, unit='deg')
        galactic = c.galactic

        deltamaglatest = None
        if packet['prv_candidates']:
            prv_candidates = sorted(packet['prv_candidates'],
                                    key=lambda x: x['jd'],
                                    reverse=True)
            for candidate in prv_candidates:
                if packet['candidate']['fid'] == candidate[
                        'fid'] and candidate['magpsf']:
                    deltamaglatest = packet['candidate']['magpsf'] - candidate[
                        'magpsf']
                    break

        deltamagref = None
        if packet['candidate']['distnr'] < 2:
            deltamagref = packet['candidate']['magnr'] - packet['candidate'][
                'magpsf']

        alert = ZtfAlert(objectId=packet['objectId'],
                         publisher=packet.get('publisher', ''),
                         alert_candid=packet['candid'],
                         location=location,
                         deltamaglatest=deltamaglatest,
                         deltamagref=deltamagref,
                         gal_l=galactic.l.value,
                         gal_b=galactic.b.value,
                         **packet['candidate'])

        # is it alread in the database?
        _rec = None
        try:
            _rec = db.session.query(ZtfAlert).first()
        except Exception:
            _rec = None

        if _rec is not None:
            logger.warn('object already exists in database',
                        extra={'tags': {
                            'candid': alert.alert_candid
                        }})
        else:
            try:
                logger.info('Updating object database',
                            extra={'tags': {
                                'candid': alert.alert_candid
                            }})
                # db.session.update(alert)
                db.session.add(alert)
                db.session.commit()
                logger.info('Updated object into database',
                            extra={'tags': {
                                'candid': alert.alert_candid
                            }})
            except exc.SQLAlchemyError:
                db.session.rollback()
                logger.warn('Failed to update object into database',
                            extra={'tags': {
                                'candid': alert.alert_candid
                            }})
コード例 #11
0
def spots():
    from src.app import app
    with app.app_context():
        return db.session.query(Spot)