Skip to content

Commit

Permalink
test /loadEntries.php
Browse files Browse the repository at this point in the history
* extend db model so I am able to insert test data into the db
* test whether we can retrieve the test data via a simple search
  • Loading branch information
adrianschlatter committed Dec 29, 2023
1 parent f7a36a9 commit 25cc1ee
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 0 deletions.
36 changes: 36 additions & 0 deletions src/ppf/webref/model.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
from flask_sqlalchemy import SQLAlchemy
from flask_login import UserMixin
from sqlalchemy.orm import relationship
from sqlalchemy.orm.collections import attribute_mapped_collection
from sqlalchemy.ext.associationproxy import association_proxy


db = SQLAlchemy()
Expand All @@ -9,3 +12,36 @@ class User(db.Model, UserMixin):
id = db.Column(db.Integer, primary_key=True)
username = db.Column(db.String(20), nullable=False, unique=True)
password = db.Column(db.String(80), nullable=True)


# Everything below:
# Copy of ppf.jabref as we have to redefine the models based on db.Model:


class Entry(db.Model):
"""Represent a JabRef Entry."""

__tablename__ = 'ENTRY'

shared_id = db.Column('SHARED_ID', db.Integer, primary_key=True)
type = db.Column(db.VARCHAR(255), nullable=False)
version = db.Column(db.Integer, nullable=True)
_fields = relationship(
'Field',
collection_class=attribute_mapped_collection('name'))

# Access like entry.fields['author'] returns 'A. Muller'
# which is nicer than using entry.fields['author'].value:
fields = association_proxy('_fields', 'value',
creator=lambda k, v: Field(name=k, value=v))


class Field(db.Model):
"""Represent a JabRef Field."""

__tablename__ = 'FIELD'

entry_shared_id = db.Column(db.Integer, db.ForeignKey('ENTRY.SHARED_ID'),
primary_key=True)
name = db.Column(db.VARCHAR(255), primary_key=True)
value = db.Column(db.Text, nullable=True)
31 changes: 31 additions & 0 deletions tests/test_services.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,32 @@
import pytest
from ppf.webref.model import Entry, db


@pytest.fixture()
def client_logged_in(app):
client = app.test_client()
client.post('login',
data={'username': 'existing_user', 'password': 'password'})

entry = Entry(type='article', version=1,
fields={
'author': 'Åström, Karl Johan and Murray, Richard M.',
'title': 'Feedback Systems',
'publisher': 'Princeton University Press',
'year': '2020',
'citationkey': 'a',
'month': '#jul#',
'url': ('http://www.cds.caltech.edu/~murray/books/AM08/'
'pdf/fbs-public_24Jul2020.pdf'),
'file': ':a.pdf:PDF',
'keywords': ('feedback, systems, continuous, control, '
'stability, modeling, dynamics, '
'linear systems, state space, t')})

with app.app_context():
db.session.add(entry)
db.session.commit()

return client


Expand All @@ -17,3 +38,13 @@ def test_index(client_logged_in):
def test_references(client_logged_in):
response = client_logged_in.get('/references/does_not_exist.pdf')
assert response.status_code == 404


def test_loadEntries(client_logged_in):
with client_logged_in as client:
response = client.post('loadEntries.php',
data={'searchexpr': 'Feedback'})

assert '<table>' in response.text
assert '</table>' in response.text
assert '<td>Feedback Systems</td>' in response.text

0 comments on commit 25cc1ee

Please sign in to comment.