Skip to content
This repository has been archived by the owner on May 28, 2022. It is now read-only.

Commit

Permalink
Removed get_events from database module because it was only used in the
Browse files Browse the repository at this point in the history
test module.

Altered the update_presentation method in the database module to be more
consistent with the insert_presentation's method of preparing database queries.

Removed string docs from the test_database module since they were reiteratings
of the function names. One string doc was converted into a comment because it
is an assumption about the database state.

Some of the code that got the first record_id from the database was refactored
from the test_database module because of the test_first_talk_id test method.
  • Loading branch information
Stephen Romansky committed Oct 10, 2014
1 parent d458561 commit 9c82e20
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 39 deletions.
12 changes: 4 additions & 8 deletions src/freeseer/framework/database.py
Expand Up @@ -175,10 +175,6 @@ def get_talks(self):
"""Gets all the talks from the database including all columns"""
return QtSql.QSqlQuery('SELECT * FROM presentations')

def get_events(self):
"""Gets all the talk events from the database"""
return QtSql.QSqlQuery('SELECT DISTINCT Event FROM presentations')

def get_talk_ids(self):
"""Gets all the talk events from the database"""
return QtSql.QSqlQuery('SELECT Id FROM presentations')
Expand Down Expand Up @@ -262,10 +258,10 @@ def insert_presentation(self, presentation):
def update_presentation(self, talk_id, presentation):
"""Updates an existing Presentation in the database."""
query = QtSql.QSqlQuery()
query.prepare(
'''UPDATE presentations SET Title=:title, Speaker=:speaker, Description=:description, Category=:category,
Event=:event, Room=:room, Date=:date, StartTime=:startTime, EndTime=:endTime
WHERE Id=:talk_id''')
query.prepare('UPDATE presentations '
'SET Title=:title, Speaker=:speaker, Description=:description, Category=:category, '
'Event=:event, Room=:room, Date=:date, StartTime=:startTime, EndTime=:endTime '
'WHERE Id=:talk_id')

query.bindValue(':talk_id', talk_id)
query.bindValue(':title', presentation.title)
Expand Down
37 changes: 6 additions & 31 deletions src/freeseer/tests/framework/test_database.py
Expand Up @@ -59,19 +59,14 @@ def presentation():


def test_first_talk_id(db, presentation):
"""Assert that the first talk id in the database is one. This assumption is used throughout this unit test module."""
# Assert that the first talk id in the database is '1'. This assumption is used throughout this unit test module.
db.insert_presentation(presentation)

talk_ids = db.get_talk_ids()
if talk_ids.first():
talk_id_record = talk_ids.record()
talk_id = talk_ids.value(talk_id_record.indexOf('id')).toString()
assert talk_id == "1"
return "1"
else:
assert False
# Something has caused the inserted presentation to not have an id of value 1.
return "-1"
assert talk_ids.first()
talk_id_record = talk_ids.record()
talk_id = talk_ids.value(talk_id_record.indexOf('id')).toString()
assert talk_id == '1'


def todo_test_query_result_type_is_model(db):
Expand All @@ -82,7 +77,6 @@ def todo_test_query_result_type_is_model(db):


def test_add_talks_from_rss(db):
"""Test that talks are retrieved from the RSS feed"""
dirname = os.path.dirname(__file__)

feed1 = os.path.join(dirname, 'sample_rssfeeds/summercamp2010')
Expand All @@ -99,8 +93,6 @@ def test_add_talks_from_rss(db):


def test_add_talks_from_csv(db):
"""Test that talks are retrieved from the CSV file"""

dirname = os.path.dirname(__file__)
fname = os.path.join(dirname, 'sample_talks.csv')

Expand All @@ -111,7 +103,6 @@ def test_add_talks_from_csv(db):


def test_insert_presentation(db, presentation):
"""Assert that inserting a fake presentation is succesful."""
assert not db.presentation_exists(presentation)
db.insert_presentation(presentation)

Expand All @@ -131,17 +122,10 @@ def test_insert_presentation(db, presentation):

def test_update_presentation(db, presentation):
db.insert_presentation(presentation)
talks = db.get_talks()
record = talks.record()

# Get the id of the presentation we inserted.
talks.first()
record = talks.record()
record_id = talks.value(record.indexOf('id')).toString()

# Update the inserted presentation
presentation.title = 'Presentation Title Redacted'
db.update_presentation(record_id, presentation)
db.update_presentation(FIRST_TALK_ID, presentation)

updated_talks = db.get_talks()
updated_talks.first()
Expand All @@ -166,15 +150,6 @@ def test_clear_database(db, presentation):
assert not db.presentation_exists(presentation)


def test_get_events(db, presentation):
db.insert_presentation(presentation)

events = db.get_events()
assert events.first()
event_record = events.record()
assert presentation.event == events.value(event_record.indexOf('event')).toString()


def test_get_talk_ids(db, presentation):
db.insert_presentation(presentation)

Expand Down

0 comments on commit 9c82e20

Please sign in to comment.