-
Notifications
You must be signed in to change notification settings - Fork 1
Global topics #18
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Global topics #18
Changes from 5 commits
6e4fa10
f8be8ad
418b564
842ba9b
84e020b
6a86483
d444427
ff30ded
7c6ad65
0aec5df
41bd085
581508d
b7fb25f
f03e813
5dc528b
7e8996a
5451ccc
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -124,22 +124,96 @@ def _create_session(cursor, session_id, user_id): | |
|
||
def _create_global_topics(cursor): | ||
# type: (psycopg2.extensions.cursor) -> None | ||
|
||
cursor.execute( | ||
"insert into" | ||
" phpbb_topics(topic_id, forum_id, topic_title, topic_time," | ||
" topic_first_poster_name, topic_first_post_id, topic_type)" | ||
" values (0,0,'naslov_teme_0',10,'ime',0,3)," | ||
" (1,0,'naslov teme 1',13,'drugi poster',1,3)," | ||
" (2,0,'naslov teme 2',200,'post it',2,3)," | ||
" (3,0,'naslov teme 3',256,'posted it',3,3)" | ||
"insert into phpbb_topics (" | ||
"topic_id" | ||
",forum_id" | ||
",topic_title" | ||
",topic_time" | ||
",topic_first_poster_name" | ||
",topic_first_post_id" | ||
",topic_type" | ||
") values (" | ||
"0" | ||
",0" | ||
",'topic title 0'" | ||
",10" | ||
",'name'" | ||
",0,3" | ||
"), (" | ||
"1," | ||
"0," | ||
"'topic title 1'," | ||
"13," | ||
"'second poster'," | ||
"1," | ||
"3" | ||
"), (" | ||
"2" | ||
",0" | ||
",'topic title 2'" | ||
",200" | ||
",'post it'" | ||
",2," | ||
"3" | ||
"), (" | ||
"3" | ||
",0" | ||
",'topic title 3'" | ||
",256" | ||
",'posted it'" | ||
",3" | ||
",3" | ||
"), (" | ||
"4" | ||
",0" | ||
",'topic title 4'" | ||
",666" | ||
",'posted it again'" | ||
",3" | ||
",3" | ||
") , (" | ||
"6" | ||
",0" | ||
",'topic title 5'" | ||
",777" | ||
",'posted as 7, expecting 6'" | ||
",3" | ||
",3" | ||
") , (" | ||
"7" | ||
",0" | ||
",'different data type'" | ||
",999" | ||
",'inserted into table, expecting different type'" | ||
",3" | ||
",3" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should this number be something else (topic_type)? I see in your dataset you have only topic_type 3. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I have set up one example where topic_type is different from 3. But the select expression for global topics has a where clause with a condition that topic_type = 3. So I think it would make sense to have most of examples fulfilling this condition. |
||
")" | ||
) | ||
|
||
cursor.execute( | ||
" insert into " | ||
" phpbb_posts(post_id,post_subject,post_text)" | ||
" values (0,'prva tema', 'bla')," | ||
" (1,'druga tema','blabla')," | ||
" (2,'tretja tema','blablabla')," | ||
" (3,'tretja tema','bla krat 4')" | ||
" insert into phpbb_posts (" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Be careful! You have Add posts before changing your tests to see if it will break your tests. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Posts have been added in the next commit. |
||
"post_id" | ||
",post_subject" | ||
",post_text" | ||
") values (" | ||
"0" | ||
",'topic one'" | ||
", 'hello'" | ||
"), (" | ||
"1" | ||
",'topic two'" | ||
",'hello world'" | ||
"), (" | ||
"2" | ||
",'topic three'" | ||
",'hello hello'" | ||
"), (" | ||
"3" | ||
",'topic three'" | ||
",'hello times four'" | ||
")" | ||
) | ||
|
||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -76,42 +76,72 @@ def test_fetch_global_topics(self): | |
expected_topics = [(0, [{ | ||
'topic_id': 0, | ||
MasterMind2k marked this conversation as resolved.
Show resolved
Hide resolved
|
||
'forum_id': 0, | ||
'topic_title': 'naslov_teme_0', | ||
'topic_title': 'topic title 0', | ||
'topic_time': 10, | ||
'topic_first_poster_name': 'ime', | ||
'post_subject': 'prva tema', | ||
'post_text': 'bla'}]), | ||
'topic_first_poster_name': 'name', | ||
'post_subject': 'topic one', | ||
'post_text': 'hello'}]), | ||
|
||
(1, [{ | ||
'topic_id': 1, | ||
'forum_id': 0, | ||
'topic_title': 'naslov teme 1', | ||
'topic_title': 'topic title 1', | ||
'topic_time': 13, | ||
'topic_first_poster_name': 'drugi poster', | ||
'post_subject': 'druga tema', | ||
'post_text': 'blabla'}]), | ||
'topic_first_poster_name': 'second poster', | ||
'post_subject': 'topic two', | ||
'post_text': 'hello world'}]), | ||
(2, [{ | ||
'topic_id': 2, | ||
'forum_id': 0, | ||
'topic_title': 'naslov teme 2', | ||
'topic_title': 'topic title 2', | ||
'topic_time': 200, | ||
'topic_first_poster_name': 'post it', | ||
'post_subject': 'tretja tema', | ||
'post_text': 'blablabla'}]), | ||
'post_subject': 'topic three', | ||
'post_text': 'hello hello'}]), | ||
(3, [{ | ||
'topic_id': 3, | ||
'forum_id': 0, | ||
'topic_title': 'naslov teme 3', | ||
'topic_title': 'topic title 3', | ||
'topic_time': 256, | ||
'topic_first_poster_name': 'posted it', | ||
'post_subject': 'tretja tema', | ||
'post_text': 'bla x4'}])] | ||
for skip in range(0, 3): | ||
'post_subject': 'topic three', | ||
'post_text': 'hello times four'}]), | ||
(4, [{ | ||
'topic_id': 4, | ||
'forum_id': 2, | ||
'topic_title': 'topic missing', | ||
'topic_time': 666, | ||
'topic_first_poster_name': 'no forum', | ||
'post_subject': 'topic yes, forum no', | ||
'post_text': 'test case'}]), | ||
(5, [{ | ||
'topic_id': 5, | ||
'forum_id': 0, | ||
'topic_title': 'topic missing', | ||
'topic_time': 777, | ||
'topic_first_poster_name': 'not existent forum', | ||
'post_subject': 'topic yes, forum no', | ||
'post_text': 'test case'}]), | ||
(6, [{ | ||
'unexpected_column': 5, | ||
'random_column': 0, | ||
'topic_title': 'topic missing', | ||
'topic_time': 777, | ||
'do_not_change_all': 'not existent forum', | ||
'post_subject': 'topic yes, forum no', | ||
'post_text': 'test case'}]), | ||
(7, [1, 2, 3]) | ||
] | ||
|
||
for skip in range(0, 7): | ||
topic = self.app.phpbb3.fetch_global_topics( | ||
skip=skip, | ||
limit=1, | ||
forum_id=0) | ||
self.assertEqual((skip, topic), expected_topics[skip]) | ||
if skip > 3: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I was wondering what this was for. You can compare lists without any problems. So, if database has positive and negative items, you only compare if actual result is equal to expected result (only positive). There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh, must have misunderstood the the positive vs. negative tests. All tests after index 3 are expected to not be equal. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, I see that. What I would like to see is, that this would be more explicitly be seen from code. This does its job, but I needed cca 30 minutes longer to get the point. By properly separating tests and naming them, you can really make the tests easy readable. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok, I see what you mean, will submit new changes soon. |
||
self.assertNotEqual((skip, topic), expected_topics[skip]) | ||
else: | ||
self.assertEqual((skip, topic), expected_topics[skip]) | ||
|
||
|
||
class TestSession(base.TestWithDatabase): | ||
|
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.
Whitespace in strings are missing (simulating you would be writing into a file).
Also, I see you could congest each row into one line. While keeping field list with each column in its own line (for readability).
Example: