-
Notifications
You must be signed in to change notification settings - Fork 110
unit test and refactor database.py part 2 #671
base: master
Are you sure you want to change the base?
unit test and refactor database.py part 2 #671
Conversation
@dideler @zxiiro edit: This is from adding a print statement to |
From the expected csv lines. Note that the ,, is like None pretty much. So SQL isn't inserting '' at all. instead it is taking the content from the string objects (which is nothing) and inserting it into the prepared presentation fields in |
This should be equivalent to what is already in Specifically when presentation.room='' this fails. |
AND StartTime >= :startTime ORDER BY StartTime ASC | ||
''') | ||
query.bindValue(':room', room) | ||
query.bindValue(':date', current_time) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm confused by all this date/time stuff. You're now passing the time to the date field?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sqlite and python website mentions that python and SQLITE treat the timestamp
SQL data type as a DateTime
Python object.
The SQL statement on line 192 says to only take the date from the given timestamp value, date documentation.
However, SQL is kind of confusing. I changed it such that Python now get the date from the DateTime object.
In summary, the presentation.date
and presentation.startTime or presentation.endTime
are both of the type QDateTime
. presentation.date
has a more specific type QDate
QDate which only contains the date part.
Both Python and SQLITE know how to convert QDateTime objects into QDate objects using a version of the date()
call. In SQLITE it is just applied to a value with a timestamp like any function call in SQL, and in Python date()
can be used on a QDateTime object.
edit:
Example:
# ./frontend/reporteditor/reporteditor.py
def add_talk(self):
date = self.addTalkWidget.dateEdit.date()
startTime = self.addTalkWidget.startTimeEdit.time()
datetime = QDateTime(date, startTime) # original "time" is now "startTime"
presentation = Presentation(unicode(self.addTalkWidget.titleLineEdit.text()),
unicode(self.addTalkWidget.presenterLineEdit.text()),
"", # description
"", # level
unicode(self.addTalkWidget.eventLineEdit.text()),
unicode(self.addTalkWidget.roomLineEdit.text()),
unicode(datetime.toString()), # presentation.date
unicode(self.addTalkWidget.endTimeEdit.text())) # presentation.startTime
This code sets the presentation.date
to DateTime instead of just a Date object. (Making some confusion..)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If I understand you correctly, the Date
field (with type TIMESTAMP
) can work with QDateTime
or QDate
? If so, I think being explicit and using QDate
is better than implicitly converting a QDateTime
into QDate
.
If I misunderstand and that's not possible, then I think there should be an inline comment on L192, e.g. "Takes the date from the timestamp value."
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
QDate
can work.
The complication is that the rest of the code needs to enforce this convention (even though it will work fine with the QDateTime objects too). I will start coding this now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hm. One issue I have caused is the date, starttime, endtime in the talkeditor table are now showing the funky timestamp values instead of human readable times..
@dideler https://www.sqlite.org/datatype3.html in section 1.2 it mentions that SQLITE does not have a DATE or a TIME type and instead just has that timestamp one. :(. |
The first record uses the latest changes on this branch. def create_presentation(self, talkDetailsWidget):
"""Creates and returns an instance of Presentation using data from the input fields"""
title = unicode(talkDetailsWidget.titleLineEdit.text()).strip()
if title:
return Presentation(
title,
unicode(talkDetailsWidget.presenterLineEdit.text()).strip(),
unicode(talkDetailsWidget.descriptionTextEdit.toPlainText()).strip(),
unicode(talkDetailsWidget.categoryLineEdit.text()).strip(),
unicode(talkDetailsWidget.eventLineEdit.text()).strip(),
unicode(talkDetailsWidget.roomLineEdit.text()).strip(),
talkDetailsWidget.dateEdit.date(),
talkDetailsWidget.startTimeEdit.time().toString("hh:mm ap"),
talkDetailsWidget.endTimeEdit.time().toString("hh:mm ap")) |
bc58ab2
to
e70c6c6
Compare
Exporting talks to CSV and then importing them gets rid of the date and start/end times. Haven't checked an earlier version to see if it worked, but if it did, this is a regression and will need to be fixed before merging. |
@dideler the missing dates on import seems to occur in master too. |
@dideler I think the csv cannot be imported because the exporter uses StartTime,EndTime in its output and the import utility looks for only a Time field. |
@wigglier you asked on IRC if this should be split up into smaller commits. I think it would help and shouldn't be too difficult. You can group files into new PRs, for example:
|
e70c6c6
to
6a3e6e6
Compare
cd44e5c
to
3e58cde
Compare
Related Freeseer#667 Related Freeseer#484 Related Freeseer#671
3e58cde
to
2da4e03
Compare
14c1f41
to
863e6bb
Compare
@dideler I removed the code that stored the time format as 'hh:mm ap' and just kept it as 'hh:mm:ss'. The second problem is that I am not sure how the database is going to handle sorting timestamp values with entries like '3:52 pm' instead of '15:52:00'. In Python if the string '3:52 pm' is cast into the |
DEFAULT_DATE = '' | ||
DEFAULT_TIME = '' | ||
|
||
# TODO: Confirm Presentation.date is or is not a QDate object. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
L44-46 can be removed.
What about displaying the time in a human friendly format but saving it however is easiest in the DB? |
@dideler I think that can be done. I will investigate how. |
- Remove test methods that only check function return types - Create resources folder for common test data like test rss feeds - Fix database.py query bugs - Add database folder for database related tests - Refactor common database fixtures into the database conftest file - Refactor comments in database.py - Refactor queries in database.py to have better style and sanitization - Add comments and examples of the presentation time stamps - Remove unused functions from database.py - Add httpretty mock tests for database.py - Add a database schema upgrade test - Add tests that check multiple scenarios of each method in database.py - Replace string % operators with calls to format for nonlog string formatting - Remove several try/finally statements and replaced them with 'with's - Fix an exception logging statement which referred to an out of scope value - Add failure and presentation equality and inequality comparison functions - Add example of parameterized test with fixtures - Add fixtures based on summer camp 2010 and 2011 stored data Related Freeseer#484 Related Freeseer#667 Related Freeseer#670
4785c23
to
dc35cb3
Compare
- Add database scheme upgrade function from 310 to 315 - Update presentation constructor to use empty string default values
506f715
to
9a42835
Compare
Add unit tests and refactor/fix/document issues related to the database.
(Part 2, because #619 grew too large.)
Related #484
Related #619