Ejemplo n.º 1
0
    def test_get_owners(self):
        """Test for app.models.LogEntry.get_entries"""
        logentry = LogEntry('test level', 'test get_owners owner', 'test data', 'test tags')
        logentry_id = logentry.save()
        self._drop.append(logentry_id)

        result = logentry.get_owners()
        self.assertIn('test get_owners owner', result)
Ejemplo n.º 2
0
    def test_count_from_db(self):
        """Test for app.models.LogEntry.count"""
        logentry = LogEntry('test level', 'test owner', 'test count data', 'test tags')
        logentry_id = logentry.save()
        self._drop.append(logentry_id)

        result = logentry.count(dict(data='test count data'))
        self.assertEqual(result, 1)

        result = logentry.count(dict(data='test count data1'))
        self.assertEqual(result, 0)
Ejemplo n.º 3
0
def addLogEntry():
    form = AddLogEntry()
    if form.validate_on_submit():
        newlogentry = LogEntry()
        newlogentry.loglevel = form.loglevel.data
        newlogentry.detail = form.detail.data
        db.session.add(newlogentry)
        db.session.commit()
        flash("Log entry {} added.".format(newlogentry.id))
        return redirect(url_for("main.showLog"))

    return render_template("main/qf.html", title="Add Log Entry", form=form)
Ejemplo n.º 4
0
 def test_insert_into_db(self):
     """Test for app.models.LogEntry.save"""
     logentry = LogEntry('test level', 'test owner', 'test data', 'test tags')
     logentry_id = logentry.save()
     configs = config()
     db = MongoDBConnection.connect(configs)
     collection = unicode(configs['mongo']['collection'])
     logentry_from_db = db[collection].find_one({'_id': ObjectId(logentry_id)})
     db[collection].remove({'_id': ObjectId(logentry_id)})
     self.assertTrue(logentry_from_db['level'] == 'test level' and
                     logentry_from_db['owner'] == 'test owner' and
                     logentry_from_db['data'] == 'test data' and
                     logentry_from_db['tags'] == 'test tags',
                     msg="New entry does not match the expected or does not exist.")
Ejemplo n.º 5
0
def editjson(id: int):
    """Lets the user edit the raw json of the character."""
    c = get_character(id, check_author=True)
    form = ImportForm(obj=c)

    if form.validate_on_submit():
        c.title = form.title.data
        c.body = form.body.data

        if form.migration.data:
            logger.debug("Trying to migrate data")
            data = form.body.data
            c.body = migrate(data, latest, migrations=migrations)
        elif form.conversion.data:
            logger.debug("Conversion is checked")
            data = form.body.data
            c.body = coc7e.convert_from_dholes(data)

        logentry = LogEntry(c, "JSON edited", user_id=current_user.id)
        session.add(logentry)

        session.commit()
        return redirect(url_for('character.view', id=c.id))

    form.submit.label.text = 'Save'

    validation_errors = c.validate()

    return render_template('character/import.html.jinja',
                           title="Edit JSON",
                           validation_errors=validation_errors,
                           form=form,
                           type=None)
Ejemplo n.º 6
0
def update(id: int):
    character = get_character(id, check_author=True)

    if request.method == "POST":
        update = request.get_json()

        for setting in update:
            character.set_attribute(setting)
            field = setting['field']
            subfield = setting.get('subfield', '')
            value = setting['value']
            type = setting.get('type', 'value')
            if type == 'portrait' and value is not None:
                value = "[image]"

            log_subfield = ''
            if subfield is not None and subfield != 'None':
                log_subfield = ' ' + subfield
            log_message = (f"set {type} on {field}{log_subfield}: {value}")

            logentry = LogEntry(character,
                                log_message,
                                user_id=current_user.id)
            session.add(logentry)

        character.store_data()
        session.commit()

    return "OK"
Ejemplo n.º 7
0
Archivo: routes.py Proyecto: swbg/fl
def add_log_entry():
    location_id = request.args.get('location_id', 0, type=int)
    item_id = request.args.get('item_id', 0, type=int)

    db.session.add(LogEntry(location_id=location_id, item_id=item_id))
    db.session.commit()
    return jsonify(True)
Ejemplo n.º 8
0
    def test_get_from_db(self):
        """Test for app.models.LogEntry.get_entries"""
        logentry = LogEntry('test level', 'test get_entries owner', 'test data', 'test tags')
        logentry_id = logentry.save()
        self._drop.append(logentry_id)

        cursor = logentry.get_entries(dict(owner='test get_entries owner'))
        result = list(cursor)
        logentry_from_db = result[0]

        self.assertEqual(len(result), 1)
        self.assertEqual(result[0]['_id'], logentry_id)
        self.assertTrue(logentry_from_db['level'] == 'test level' and
                        logentry_from_db['owner'] == 'test get_entries owner' and
                        logentry_from_db['data'] == 'test data' and
                        logentry_from_db['tags'] == 'test tags',
                        msg="New entry does not match the expected or does not exist.")
Ejemplo n.º 9
0
def view(id, character, editable):
    subskillform = SubskillForm(prefix="subskillform")
    if editable and subskillform.data and subskillform.validate_on_submit():
        character.add_subskill(subskillform.name.data,
                               subskillform.parent.data)
        logentry = LogEntry(
            character,
            f"add subskill {subskillform.name.data} under {subskillform.parent.data}",
            user_id=current_user.id)
        session.add(logentry)

        character.store_data()
        session.commit()
        return redirect(url_for('character.view', id=id))

    skillform = SkillForm(prefix="skillform")
    if editable and skillform.data and skillform.validate_on_submit():
        skills = character.skills()
        for skill in skills:
            if skillform.name.data == skill['name']:
                flash("Skill already exists")
                return redirect(url_for('character.view', id=id))

        character.add_skill(skillform.name.data)
        character.store_data()
        logentry = LogEntry(character,
                            f"add skill {subskillform.name.data}",
                            user_id=current_user.id)
        session.add(logentry)

        session.commit()
        return redirect(url_for('character.view', id=id))

    typeheader = "1920s Era Investigator"
    if character.game and character.game[1] == "Modern":
        typeheader = "Modern Era"

    shared = Invite.query_for(character).count()

    return render_template('character/coc7e/sheet.html.jinja',
                           shared=shared,
                           character=character,
                           typeheader=typeheader,
                           editable=editable,
                           skillform=skillform,
                           subskillform=subskillform)
Ejemplo n.º 10
0
async def log_add(factor1: int,
                  factor2: int,
                  user_result: int,
                  duration: int,
                  user=Depends(get_user)):
    user_db = db.query(User).filter(User.id == user.id).first()
    db.add(
        LogEntry(user_db, factor1, factor2, user_result,
                 factor1 * factor2 == user_result, duration))
    db.commit()
    return {'message': 'Created Log', 'status': 201}
Ejemplo n.º 11
0
 def test_create_instance(self):
     """Test for app.models.LogEntry.__init__"""
     level = 'test level'
     owner = 'test owner'
     data = 'test data'
     tags = 'test tags'
     logentry = LogEntry(level, owner, data, tags)
     self.assertTrue(logentry.level == level and
                     logentry.owner == owner and
                     logentry.data == data and
                     logentry.tags == tags,
                     msg="Can't create or check some field in LogEntry constructor.")
Ejemplo n.º 12
0
def eventlog(id: int):
    page = request.args.get('page', 1, type=int)
    c = get_character(id, check_author=True)
    entries_page = paginate(LogEntry.query_for(c), page, 50)
    """
    # TODO
    next_url = url_for('character.eventlog', id=id,
                       page=entries_page.next_num) \
        if entries_page.has_next else None

    prev_url = url_for('character.eventlog', id=id,
                       page=entries_page.prev_num) \
        if entries_page.has_prev else None
    """
    next_url = None
    prev_url = None
    logger.debug(next_url)
    log_entries = entries_page.items
    return render_template('character/eventlog.html.jinja',
                           character=c,
                           entries=log_entries,
                           next_url=next_url,
                           prev_url=prev_url)
Ejemplo n.º 13
0
    def test_count_api_page(self):
        """Test for app.views.list"""
        logentry = LogEntry('test level', 'test count owner', 'test data', ['tag1', 'tag2'])
        logentry_id = logentry.save()
        logentry1 = LogEntry('test level1', 'test count owner', 'test data1', ['tag1', 'tag2'])
        logentry1_id = logentry1.save()
        self._drop.append(logentry_id)
        self._drop.append(logentry1_id)

        with app.test_client() as test_app:
            find = dict(owner='test count owner')
            response = test_app.post('/api/count/', content_type='application/json', data=json.dumps(dict(find=find)))
            self.assertEqual(response.status_code, 200)
            result = json.loads(response.get_data())
            ok = result.get('OK')
            self.assertTrue(ok)
            data = result['result']
            self.assertEqual(data, 2)
Ejemplo n.º 14
0
    def test_owners_api_page(self):
        """Test for app.views.list"""
        logentry = LogEntry('test level', 'test owners owner', 'test data', 'test tags')
        logentry_id = logentry.save()
        logentry1 = LogEntry('test level1', 'test owners owner1', 'test data1', 'test tags1')
        logentry1_id = logentry1.save()
        self._drop.append(logentry_id)
        self._drop.append(logentry1_id)

        with app.test_client() as test_app:
            response = test_app.get('/api/owners/', content_type='application/json')
            self.assertEqual(response.status_code, 200)
            result = json.loads(response.get_data())
            ok = result.get('OK')
            self.assertTrue(ok)
            data = result['result']
            self.assertGreaterEqual(len(data), 2)
            self.assertIn('test owners owner', data)
            self.assertIn('test owners owner1', data)
Ejemplo n.º 15
0
    def test_list_api_page(self):
        """Test for app.views.list"""
        logentry = LogEntry('test level', 'test list owner', 'test data', 'test tags')
        logentry_id = logentry.save()
        logentry1 = LogEntry('test level1', 'test list owner', 'test data1', 'test tags1')
        logentry1_id = logentry1.save()
        self._drop.append(logentry_id)
        self._drop.append(logentry1_id)

        with app.test_client() as test_app:
            find = dict(owner='test list owner')
            response = test_app.post('/api/list/', content_type='application/json', data=json.dumps(dict(find=find)))
            self.assertEqual(response.status_code, 200)
            result = json.loads(response.get_data())
            ok = result.get('OK')
            self.assertTrue(ok)
            data = result['result']
            self.assertEqual(len(data), 2)
            # By default sorting by timestamp DESCENDING
            self.assertEqual(data[0]['data'], 'test data1')
            self.assertEqual(data[1]['data'], 'test data')
Ejemplo n.º 16
0
            d['wheelchair'] = True if tag.attrib.get('v') == 'yes' else False

    db.session.add(Location(**d))

db.session.add(Item(name='SimpyV'))
db.session.add(Item(name='Creme Vega'))
db.session.add(Item(name='Beyond Burger'))
db.session.add(Item(name='Reiswaffeln'))
db.session.add(Item(name='Bier'))

db.session.commit()

random.seed(0)
location_ids = [l.id for l in Location.query.all()]
item_ids = [i.id for i in Item.query.all()]
for item_id in item_ids:
    for location_id in location_ids:
        if random.random() > 0.2:
            continue
        db.session.add(LogEntry(location_id=location_id, item_id=item_id))

db.session.commit()

print('Created dummy database.')

item_mappings = [f'"{i.name}":{i.id}' for i in Item.query.all()]
with open('item_mappings.json', 'w') as f:
    f.write(f'{{{",".join(item_mappings)}}}')

print('Created json.')