Example #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)
Example #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"])
Example #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))
Example #4
0
def client():
    with app.app_context():
        db.create_all()
    app.testing = True
    app.debug = True
    return app.test_client()
Example #5
0
def get_db():
    with app.app_context():
        if not hasattr(g, 'db'):
            g.db = connect_db(app.config['connect'])
        return g.db
Example #6
0
 def setUp(self):
     self.ctx = app.app_context()
     self.ctx.push()
     super(TestMyAppWithAppContext, self).setUp()
Example #7
0
def app():
    with flask_app.app_context():
        # Resetting database
        db.drop_all()
        db.create_all()
    yield flask_app
Example #8
0
def _callback_error(e: Exception):
    with app.app_context():
        app.logger.error(e)
Example #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()
Example #10
0
 def setUp(self):
     self.ctx = app.app_context()
     self.ctx.push()
     super(TestMyAppWithAppContext, self).setUp()
Example #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)
Example #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))
Example #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)
Example #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'))
Example #15
0
 def test_password_getter_error(self):
     with app.app_context():
         u = models.User(password='******')
         with self.assertRaises(AttributeError):
             u.password
Example #16
0
 def test_password_setter(self):
     with app.app_context():
         u = models.User(password='******')
         self.assertTrue(u.password_hash is not None)
Example #17
0
def send_async_email(app, msg):
    with app.app_context():
        mail.send(msg)
Example #18
0
def send_async_email(app, msg):
    """sends asynchronous mail"""
    with app.app_context():
        mail.send(msg)