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

unit test and refactor database.py #619

Closed
wants to merge 11 commits into from
1 change: 1 addition & 0 deletions dev_requirements.txt
Expand Up @@ -4,5 +4,6 @@ httpretty
mock
pep8==1.4.6
pytest-cov==1.6
pytest-httpretty==0.2.0
pytest==2.5.2
Sphinx<=1.2.3
270 changes: 131 additions & 139 deletions src/freeseer/framework/database.py

Large diffs are not rendered by default.

6 changes: 6 additions & 0 deletions src/freeseer/framework/failure.py
Expand Up @@ -39,6 +39,12 @@ def __init__(self, talkID, comment, indicator, release=False):
self.indicator = indicator
self.release = release

def __eq__(self, obj):
return self.__dict__ == obj.__dict__

def __ne__(self, obj):
return not self == obj


class Report():
def __init__(self, presentation, failure):
Expand Down
10 changes: 8 additions & 2 deletions src/freeseer/framework/presentation.py
Expand Up @@ -40,10 +40,16 @@ def __init__(self, title, speaker="", description="", category="", event="Defaul
self.category = category
self.event = event
self.room = room
self.date = date
self.startTime = startTime
self.date = date # QDateTime.currentDateTime().toString(1) # eg date='2010-05-14T10:45'
self.startTime = startTime # QDateTime.currentDateTime().toString(1) # eg startTime='2010-05-14T10:45'
self.endTime = endTime

def __eq__(self, obj):
return self.__dict__ == obj.__dict__

def __ne__(self, obj):
return not self == obj


class PresentationFile(Presentation):

Expand Down
2 changes: 1 addition & 1 deletion src/freeseer/frontend/configtool/configtool.py
Expand Up @@ -574,7 +574,7 @@ def show_plugin_widget_dialog(self, widget, name):
self.dialog.closeButton = QtGui.QPushButton("Close")
self.dialog_layout.addWidget(self.dialog.closeButton)
self.connect(self.dialog.closeButton, QtCore.SIGNAL('clicked()'), self.dialog.close)
self.dialog.setWindowTitle(u'{} Setup'.format(name))
self.dialog.setWindowTitle('{} Setup'.format(name))
self.dialog.setModal(True)
self.dialog.show()

Expand Down
4 changes: 2 additions & 2 deletions src/freeseer/frontend/record/record.py
Expand Up @@ -428,8 +428,8 @@ def record(self):
if self.current_event and self.current_room:
starttime = QtCore.QDateTime().currentDateTime()
stoptime = starttime.addSecs(900)
talkid = self.db.get_talk_between_time(self.current_event, self.current_room,
starttime.toString(), stoptime.toString())
talkid = self.db.get_talk_between_dates(self.current_event, self.current_room,
starttime.toString(), stoptime.toString())

if talkid is not None:
for i in range(self.mainWidget.talkComboBox.count()):
Expand Down
6 changes: 4 additions & 2 deletions src/freeseer/plugins/importer/csv_importer.py
Expand Up @@ -63,12 +63,14 @@ def get_presentations(self, fname):
'Level': unicode(row.get('Level', ''), 'utf-8'),
'Event': unicode(row.get('Event', ''), 'utf-8'),
'Room': unicode(row.get('Room', ''), 'utf-8'),
'Time': unicode(row.get('Time', ''), 'utf-8')
'Time': unicode(row.get('Time', ''), 'utf-8'),
'Problem': unicode(row.get('Problem', ''), 'utf-8'), # optional value from report csv
'Error': unicode(row.get('Error', ''), 'utf-8') # optional value from report csv
}

presentations.append(talk)

except IOError:
log.exception("CSV: File %s not found", csv_file)
log.exception("CSV: File %s not found", fname)

return presentations
Empty file.
122 changes: 122 additions & 0 deletions src/freeseer/tests/framework/database/conftest.py
@@ -0,0 +1,122 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-

# freeseer - vga/presentation capture software
#
# Copyright (C) 2014 Free and Open Source Software Learning Centre
# http://fosslc.org
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.

# For support, questions, suggestions or any other inquiries, visit:
# http://wiki.github.com/Freeseer/freeseer/

import pytest
from PyQt4 import QtCore

from freeseer.framework.config.profile import Profile
from freeseer.framework.presentation import Presentation


@pytest.fixture
def db(tmpdir):
"""Return a new empty QtDBConnector"""
profile = Profile(str(tmpdir), 'testing')
return profile.get_database()


# TODO: Give these presentation fixutres meaningful names
@pytest.fixture
def presentation1():
"""Returns a made-up presentation object. Also demonstrates how to construct time values for presentations"""
today = QtCore.QDateTime().currentDateTime() # today
current_time = QtCore.QDateTime().currentDateTime() # yyyy-mm-ddThh:mm:ss
return Presentation(
title='MITM presentation attacks',
speaker='Alice and Eve',
description='Field survey of current MITM presentation attacks.',
category='Security category',
event='testing event',
room='1300',
date=today.date().toString(1), # format date yyyy-mm-dd
startTime=current_time.addSecs(60 * 5).toString(), # Start in 5 minutes
endTime=current_time.addSecs(60 * 10).toString() # End time in 10 minutes
)


@pytest.fixture
def presentation2():
"""Presentation object from the Summercamp2010 rss feed."""
return Presentation(
title='Managing map data in a database',
speaker='Andrew Ross',
description='''This talk will provide a brief introduction to geospatial technologies. It will focus on '''
'''managing map data with a relational database. Managing map data with a database provides the atomicity, '''
'''security, access that is difficult to achieve otherwise. It also provides powerful techniques for querying'''
''' spatial aware data which can enable new insights.''',
category='Intermediate',
event='Summercamp2010',
room='Rom AB113',
date='2010-05-14T10:45',
startTime='2010-05-14T10:45'
)


@pytest.fixture
def presentation3():
"""Creates a presentation from the summercamp2011 csv file"""
return Presentation(
title='Building NetBSD',
speaker='David Maxwell',
description='''People who are interested in learning about operating systems have a lot of topics to absorb,'''
''' but the very first barrier that gets in people's way is that you need to be able to build the software. '''
'''If you can't build it, you can't make changes. If building it is painful, you'll find other things to do '''
'''with your time.\n'''
'''\tThe NetBSD Project has a build system that goes far beyond what many other projects implement. Come to '''
'''this talk about learn about\n'''
'''\tbuild.sh and the features available that make multi-architecture and embedded development environments '''
'''a breeze with NetBSD.\n'''
'''\tNetBSD website: http://www.NetBSD.org/''',
event='SC2011',
category='Beginner',
room=unicode(''),
date='2011-08-17T20:29',
startTime='2011-08-17T20:29'
)


@pytest.fixture
def presentation4():
"""Presentation from the Summercamp2011 csv file"""
return Presentation(
title='Lecture Broadcast and Capture using BigBlueButton',
speaker='Fred Dixon',
description='''BigBlueButton is an open source web conferencing system for distance education. It's goal is '''
'''to enable remote students to have a high-quality learning experience. The #1 requested feature we've had '''
'''over the last year is to integrate record and playback of a session.\n'''
'''\n'''
'''\t\n'''
'''\tFred Dixon and Richard Alam, two of the BigBlueButton committers, will describe the architecture and '''
'''implementation of record and playback as well as demonstrate the integration with Moodle to show how an '''
'''educational institution can use BigBlueButton to setup virtual classrooms, record lectures, and provide '''
'''students access to the recorded content from within the Moodle interface.\n'''
'''\n'''
'''\tWe will also demonstrate an prototype integration with popcorn.js (Mozilla project) using it as a '''
'''playback client for the recorded content.''',
event='SC2011',
category='Intermediate',
room='',
date='',
startTime=''
)