Exemplo n.º 1
0
 def test_dwgrecord(self):
     with app.app_context():
         u = models.User(password='******')
         dwg = models.DwgRecord(user_r=u, dwg='1/123.dwg', url='/test')
         self.assertEqual('1/123.dwg', dwg.dwg)
         self.assertEqual('/test', dwg.url)
         self.assertEqual(u.id, dwg.user_r.id)
Exemplo n.º 2
0
def deviceAdd(client, userdata, msg):
    # unpack json payload
    json_data = msg.payload
    raw_data = json.loads(str(json_data, encoding="utf-8"))

    with app.app_context():
        device = Device(raw_data["serial-number"], raw_data["type"],
                        raw_data["address"], raw_data["passwd"])
        db.session.add(device)
        db.session.commit()
    print(datetime.datetime.now(), "new device added:",
          raw_data["serial-number"])
Exemplo n.º 3
0
def alert(client, userdata, msg):
    # unpack json payload
    json_data = msg.payload
    raw_data = json.loads(str(json_data, encoding="utf-8"))

    with app.app_context():
        device = Device.query.filter_by(name=raw_data["serial-number"]).first()
        alert = Alert(deviceID=device.ID,
                      personNo=raw_data["personNo"],
                      confidence=raw_data["confidence"])
        db.session.add(alert)
        db.session.commit()

        deviceID = device.ID
        alertID = alert.alertID
        personNo = alert.personNo
        confidence = alert.confidence
        time = alert.time

    #save alert image
    os.makedirs(app.config['MQTT_IMG_PATH'], exist_ok=True)
    img_path = app.config['MQTT_IMG_PATH'] + 'alert-' + str(alertID) + '.gif'
    base64_string = raw_data["image_base64_string"]
    img_data = base64.b64decode(base64_string)
    with open(img_path, 'wb') as imgf:
        imgf.write(img_data)

    # notify HTTP server in localhost
    payload = {
        'deviceID': deviceID,
        'alertID': alertID,
        'time': time.isoformat(' ', 'seconds'),
        # 'alertInfo':{
        # 'personNo': personNo,
        # 'confidence':confidence,
        # }
    }
    print(payload)
    requests.post("http://127.0.0.1:" + str(app.config['PORT']) +
                  "/device/alert",
                  headers={"Content-Type": "application/json"},
                  data=json.dumps(payload))
Exemplo n.º 4
0
def client():
    with app.app_context():
        db.create_all()
    app.testing = True
    app.debug = True
    return app.test_client()
Exemplo n.º 5
0
def get_db():
    with app.app_context():
        if not hasattr(g, 'db'):
            g.db = connect_db(app.config['connect'])
        return g.db
Exemplo n.º 6
0
 def setUp(self):
     self.ctx = app.app_context()
     self.ctx.push()
     super(TestMyAppWithAppContext, self).setUp()
Exemplo n.º 7
0
def app():
    with flask_app.app_context():
        # Resetting database
        db.drop_all()
        db.create_all()
    yield flask_app
Exemplo n.º 8
0
def _callback_error(e: Exception):
    with app.app_context():
        app.logger.error(e)
Exemplo n.º 9
0
def _calc_scores(user_id: int):
    with app.app_context():
        score = sum(j * user_id for j in range(10000))
        Score.create_score(user_id, score)
        Database.commit()
Exemplo n.º 10
0
 def setUp(self):
     self.ctx = app.app_context()
     self.ctx.push()
     super(TestMyAppWithAppContext, self).setUp()
Exemplo n.º 11
0
def test_dashboard_redirect(client):
    """Check that dashboard redirects to login when unauthenticated"""
    with app.app_context():
        response = client.get('/dashboard')
        assert response.status_code == 302
        assert response.location == url_for('auth.login', _external=True)
Exemplo n.º 12
0
 def test_roles_and_permissions(self):
     with app.app_context():
         models.Role.insert_roles()
         u = models.User(email='*****@*****.**', password='******')
         self.assertTrue(u.can(models.Permission.DEFAULT))
         self.assertFalse(u.can(models.Permission.DWG_BROWSE))
Exemplo n.º 13
0
 def test_password_salts_random(self):
     with app.app_context():
         u1 = models.User(password='******')
         u2 = models.User(password='******')
         self.assertFalse(u1.password_hash == u2.password_hash)
Exemplo n.º 14
0
 def test_password_verify(self):
     with app.app_context():
         u = models.User(password='******')
         self.assertTrue(u.verify_password('cash'))
         self.assertFalse(u.verify_password('qian'))
Exemplo n.º 15
0
 def test_password_getter_error(self):
     with app.app_context():
         u = models.User(password='******')
         with self.assertRaises(AttributeError):
             u.password
Exemplo n.º 16
0
 def test_password_setter(self):
     with app.app_context():
         u = models.User(password='******')
         self.assertTrue(u.password_hash is not None)
Exemplo n.º 17
0
def send_async_email(app, msg):
    with app.app_context():
        mail.send(msg)
Exemplo n.º 18
0
def send_async_email(app, msg):
    """sends asynchronous mail"""
    with app.app_context():
        mail.send(msg)