Пример #1
0
    def test_get_by_id(self):
        """Get application by ID."""
        application = Application(name=fake.word(),
                                  support_message=fake.sentence()).save()

        retrieved = Application.get_by_id(application.id)
        assert retrieved == application
        retrieved = Application.get_by_uuid(application.uuid)
        assert retrieved == application
Пример #2
0
def add_app():
    form = AppForm(request.form)

    if request.method == "POST" and form.validate_on_submit():
        app = Application()
        app.name = form.name.data
        app.support_message = form.support.data

        db.session.add(app)
        try:
            db.session.commit()
            flash("Success!")
        except Exception as error:
            flash(f"Failed to add application: {error}")

    return render_template("add_modify.html", form=form, header="Add Application")
Пример #3
0
    def test_get_by_id(self):
        """Get key by ID."""
        application = Application(name=fake.word(),
                                  support_message=fake.sentence()).save()
        num_days = "15"
        key = Key(token=fake.word(),
                  remaining=randint(-1, 50),
                  app_id=application.id,
                  enabled=True,
                  memo=fake.sentence(),
                  hwid=fake.mac_address(),
                  expiry_date=("%s" % num_days)).save()

        retrieved = Key.get_by_id(key.id)
        assert retrieved == key
        retrieved = Key.get_by_uuid(key.uuid)
        assert retrieved == key
Пример #4
0
 def test_application_through_key(self):
     """test the relationship of key.app"""
     application = Application(name=fake.word(),
                               support_message=fake.sentence()).save()
     num_days = "15"
     key1 = Key(token=fake.word(),
                remaining=randint(-1, 50),
                app_id=application.id,
                enabled=True,
                memo=fake.sentence(),
                hwid=fake.mac_address(),
                expiry_date="15").save()
     key2 = Key(token=fake.word(),
                remaining=randint(-1, 50),
                app_id=application.id,
                enabled=True,
                memo=fake.sentence(),
                hwid=fake.mac_address(),
                expiry_date="2020-12-25").save()
     assert key1.app == key2.app == application
Пример #5
0
    def test_key_expiry_date(self):
        """test that a key is only valid for a period of time"""
        application = Application(name=fake.word(),
                                  support_message=fake.sentence()).save()
        num_days = "15"
        key1 = Key(token=fake.word(),
                   remaining=randint(-1, 50),
                   app_id=application.id,
                   enabled=True,
                   memo=fake.sentence(),
                   hwid=fake.mac_address(),
                   expiry_date=("%s" % num_days)).save()
        key2 = Key(token=fake.word(),
                   remaining=randint(-1, 50),
                   app_id=application.id,
                   enabled=True,
                   memo=fake.sentence(),
                   hwid=fake.mac_address(),
                   expiry_date="2020-12-25").save()

        assert key1.valid_until <= dt.datetime.utcnow() + dt.timedelta(
            days=int(num_days))
        assert key2.valid_until == dt.datetime.combine(dt.date(2020, 12, 25),
                                                       dt.datetime.min.time())