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

Conversation

SRomansky
Copy link
Contributor

Updates to tests/framework/test_database.py and framework/database.py.

  • Replaced test_database.py unittest references with pytest references
  • Removed test methods that checked the return type of database functions
  • Added test methods that checked the return values of database functions
  • Modified database functions to handle python strings properly
  • Added bound values to the add_presentation and update_presentation database functions.
  • Removed dummy record inserted by default.

Related gh484

@SRomansky SRomansky changed the title 484 unit test and refactor unit test and refactor database.py Oct 7, 2014
@dideler dideler added this to the 2014 Fall - UCOSP milestone Oct 7, 2014
@dideler
Copy link
Member

dideler commented Oct 7, 2014

There's some style errors, see the Travis build.

@SRomansky
Copy link
Contributor Author

Fixed.

@mtomwing
Copy link
Member

mtomwing commented Oct 8, 2014

FWIW, you can flake8 on your own machine before committing to avoid things like that.

@SRomansky
Copy link
Contributor Author

Thanks mtomwing, that will save some time in the future.


talk_ids = db.get_talk_ids()
talk_id_count = 0
while(talk_ids.next()):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This ain't C.

while condition:
    ...

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed the while loops. I will try to catch up to this Python while it opens doors.

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'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might as well use FIRST_TALK_ID here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

@mtomwing
Copy link
Member

I'm not a big fan of FIRST_TALK_ID. We know that the very first record added will have an id of 1, so it's better to be explicit about it. It's better to be DAMP in tests rather than DRY (with some exceptions).

@SRomansky
Copy link
Contributor Author

Removed FIRST_TALK_ID in favor of '1' and removed the string concatenation from os.path.join calls.

@@ -1,2 +1,3 @@
[run]
omit = freeseer/tests/*

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Revert this change.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

reverted

''')

def __drop_presentation(self):
QtSql.QSqlQuery('DROP TABLE presentations')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These functions definitely do not go here as they're only used by tests. I'd also question whether they're actually required at all?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Migrated to the testing function. I thought of a way to get them out of database.py yesterday but was not able to get back to the keyboard.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If there are end users running older versions of the client then it could be useful to test that their databases upgrade correctly when they get a newer version of freeseer? Although I am not sure how many people actually run freeseer with a very old version like 2x


talk_id = db.get_talk_between_dates(presentation.event, presentation.room,
time_before_presentation, time_after_presentation)
assert talk_id == '1'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test can be improved by inserting more presentations, to make sure it actually filters presentations.

edit: The below test kinda tests that already.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added another test. I also added another presentation object to this test. I have added a fixme comment to the get_talk_between_dates function since it only returns one presentation id (if there are multiple presentations on the same day which one has its id returned?)

Stephen Romansky added 3 commits November 24, 2014 14:28
…o fixtures, need to give them better names, refactored helper function name, added logging, added more tests.)
…d to presentation for comparing records to presentations. Started refactoring failure and presentation references.
@SRomansky
Copy link
Contributor Author

@dideler
The behaviour also occurs with the prepared statements (I had written both originally to double check that).

@SRomansky
Copy link
Contributor Author

@dideler added the __dict__ comparison to failures.py

@SRomansky
Copy link
Contributor Author

@dideler I will take a look again on Friday+Saturday for refactoring. I know for sure that the presentation fixtures will need to be renamed. There may also be some other little points that can be fixed up as well to be cleaner/clearer.


talk_ids = db.get_talk_ids()
expected_id = 1
while(talk_ids.next()):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No parentheses for while.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed.

@dideler
Copy link
Member

dideler commented Nov 25, 2014

Thanks for the updates. I'll try to do some more review and leave comments before Friday/Saturday.

On a sidenote, this PR is getting huge with the amount of conversations, which makes it slow to load and linking to conversations doesn't work anymore (at least not for me). Might be useful to create a new PR and then reference this one.

@SRomansky
Copy link
Contributor Author

@dideler #670 created.

edit: Not certain how to associate the PR with the other issue though. Ah I made an Issue instead of a PR, oops. The PR creation page doesn't mention creating another PR, only to view the current one associated with the branch. Guess it can be cloned and a PR created from that.

edit3: #671 created

@dideler
Copy link
Member

dideler commented Nov 25, 2014

Discussion will continue in #671.

P.S. @wigglier the easiest way to open a replacement PR is to close the existing PR first, then open a new one. You shouldn't have to create a new branch in the process.

@dideler dideler closed this Nov 25, 2014
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants