From 6e4fa10e82979e0eb18c34c9160f58fb0ec9098b Mon Sep 17 00:00:00 2001 From: Gregor Date: Thu, 9 May 2019 23:51:11 +0200 Subject: [PATCH 01/17] added global topics --- flask_phpbb3/backends/psycopg2.py | 17 +++++++++++++++++ flask_phpbb3/extension.py | 18 ++++++++++++++++++ tests/integration/test_extension.py | 6 ++++++ tests/unit/backends/test_psycopg2.py | 5 +++++ tests/unit/test_sessions.py | 2 ++ 5 files changed, 48 insertions(+) diff --git a/flask_phpbb3/backends/psycopg2.py b/flask_phpbb3/backends/psycopg2.py index 816e990..846c4e6 100644 --- a/flask_phpbb3/backends/psycopg2.py +++ b/flask_phpbb3/backends/psycopg2.py @@ -100,6 +100,23 @@ def _prepare_statements(self): " AND nt.notification_type_enabled=1 " " AND n.notification_read=0" ), + fetch_global_topics=( + "SELECT" + " t.topic_id," + " t.forum_id," + " t.topic_title," + " t.topic_time," + " t.topic_first_poster_name," + " p.post_subject," + " p.post_text " + " FROM " + " {TABLE_PREFIX}topics t" + " INNER JOIN {TABLE_PREFIX}posts p ON" + " p.post_id = t.topic_first_post_id" + " WHERE" + " t.topic_type = 3" + " AND t.forum_id = %(forum_id)s" + ), )) self._prepare_custom_fields_statements() diff --git a/flask_phpbb3/extension.py b/flask_phpbb3/extension.py index 4338782..31661c5 100644 --- a/flask_phpbb3/extension.py +++ b/flask_phpbb3/extension.py @@ -228,6 +228,24 @@ def get_unread_notifications_count( ) # type: typing.Optional[dict] return output + def fetch_global_topics( + self, + forum_id, + skip=0, + limit=10, + cache=False, + cache_ttl=None, + ): + output = self._backend.execute( + 'get_global_topics', + forum_id=forum_id, + skip=skip, + limit=limit, + cache=cache, + cache_ttl=cache_ttl, + ) # type: typing.Optional[dict] + return output + def get_user_acl(self, raw_user_permissions): # type: (str) -> flask_phpbb3.backends.base.UserAcl return self._backend.get_user_acl(raw_user_permissions) diff --git a/tests/integration/test_extension.py b/tests/integration/test_extension.py index 177145a..60e1ea5 100644 --- a/tests/integration/test_extension.py +++ b/tests/integration/test_extension.py @@ -69,6 +69,12 @@ def test_paging(self): privilege = self.app.phpbb3.fetch_acl_options(skip=skip, limit=1) self.assertEqual((skip, privilege), expected_privileges[skip]) + def test_fetch_global_Topics(self): + expected_topics = [[(0,),(1,),(2,),(3,),(4,),(5,)]] + for skip in range(0, 5): + topic=self.app.phpbb3.fetch_global_topics(skip=skip, limit=1, forum_id=0) + self.assertEqual((skip,topic), expected_topics[skip]) + class TestSession(base.TestWithDatabase): def setUp(self): diff --git a/tests/unit/backends/test_psycopg2.py b/tests/unit/backends/test_psycopg2.py index d8a16cd..2b4eaa5 100644 --- a/tests/unit/backends/test_psycopg2.py +++ b/tests/unit/backends/test_psycopg2.py @@ -130,6 +130,7 @@ def test_empty(self, mocked_db): 'get_unread_notifications_count', 'get_user', 'get_user_profile', + 'fetch_global_topics', ] ) @@ -155,6 +156,7 @@ def test_valid(self, mocked_db): 'get_unread_notifications_count', 'get_user', 'get_user_profile', + 'fetch_global_topics', ]), ) @@ -181,6 +183,7 @@ def test_empty(self, mocked_db): 'get_unread_notifications_count', 'get_user', 'get_user_profile', + 'fetch_global_topics', ] ) @@ -207,6 +210,7 @@ def test_addition(self, mocked_db): 'some_custom_statement', 'get_user', 'get_user_profile', + 'fetch_global_topics', ] ) self.assertEqual( @@ -236,6 +240,7 @@ def test_override(self, mocked_db): 'get_unread_notifications_count', 'get_user', 'get_user_profile', + 'fetch_global_topics', ] ) self.assertEqual( diff --git a/tests/unit/test_sessions.py b/tests/unit/test_sessions.py index a5c12b4..2d2b822 100644 --- a/tests/unit/test_sessions.py +++ b/tests/unit/test_sessions.py @@ -268,3 +268,5 @@ def test_cache(self, mocked_phpbb3): mocked_phpbb3.get_unread_notifications_count.assert_called_once_with( user_id=user_id, ) + + From f8be8add66ee3af88538085e41b92619b373ad6b Mon Sep 17 00:00:00 2001 From: Gregor Date: Thu, 16 May 2019 22:19:30 +0200 Subject: [PATCH 02/17] added_testing_data --- .../postgres/global_topics_test_data.sql | 18 ++++++++ tests/integration/test_extension.py | 42 ++++++++++++++++--- 2 files changed, 55 insertions(+), 5 deletions(-) create mode 100644 tests/fixtures/postgres/global_topics_test_data.sql diff --git a/tests/fixtures/postgres/global_topics_test_data.sql b/tests/fixtures/postgres/global_topics_test_data.sql new file mode 100644 index 0000000..25ec8dd --- /dev/null +++ b/tests/fixtures/postgres/global_topics_test_data.sql @@ -0,0 +1,18 @@ +INSERT INTO public.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',1,3), + (1,0,'naslov teme 1',13,'drugi poster',2,3), + (2,0,'naslov teme 2',200,'post it',0,3), + (3,0,'naslov teme 3',256,'posted it',3,3) + + + + INSERT INTO public.phpbb_posts(post_id,post_subject,post_text + ) + VALUES + (1,'prva tema', 'bla'), + (2,'druga tema','blabla'), + (0,'tretja tema','blablabla'), + (3,'tretja tema','bla krat 4') + diff --git a/tests/integration/test_extension.py b/tests/integration/test_extension.py index 60e1ea5..e88c115 100644 --- a/tests/integration/test_extension.py +++ b/tests/integration/test_extension.py @@ -69,11 +69,43 @@ def test_paging(self): privilege = self.app.phpbb3.fetch_acl_options(skip=skip, limit=1) self.assertEqual((skip, privilege), expected_privileges[skip]) - def test_fetch_global_Topics(self): - expected_topics = [[(0,),(1,),(2,),(3,),(4,),(5,)]] - for skip in range(0, 5): - topic=self.app.phpbb3.fetch_global_topics(skip=skip, limit=1, forum_id=0) - self.assertEqual((skip,topic), expected_topics[skip]) + def test_fetch_global_topics(self): + expected_topics = [(0, [{ + 'topic_id': 0, + 'forum_id': 0, + 'topic_title': 'naslov_teme_0', + 'topic_time': 10, + 'topic_first_poster_name': 'ime', + 'post_subject': 'prva tema', + 'post_text': 'bla'}]), + + (1, [{ + 'topic_id': 1, + 'forum_id': 0, + 'topic_title': 'naslov teme 1', + 'topic_time': 13, + 'topic_first_poster_name': 'drugi poster', + 'post_subject': 'druga tema', + 'post_text': 'blabla'}]), + (2, [{ + 'topic_id': 2, + 'forum_id': 0, + 'topic_title': 'naslov teme 2', + 'topic_time': 200, + 'topic_first_poster_name': 'post it', + 'post_subject': 'tretja tema', + 'post_text': 'blablabla'}]), + (3, [{ + 'topic_id': 3, + 'forum_id': 0, + 'topic_title': 'naslov teme 3', + 'topic_time': 256, + 'topic_first_poster_name': 'posted it', + 'post_subject': 'tretja tema', + 'post_text': 'bla x4'}])] + for skip in range(0, 3): + topic = self.app.phpbb3.fetch_global_topics(skip=skip, limit=1, forum_id=0) + self.assertEqual((skip, topic), expected_topics[skip]) class TestSession(base.TestWithDatabase): From 418b564b6ec134459833ca54d9b2eda453f25457 Mon Sep 17 00:00:00 2001 From: Gregor Date: Sun, 19 May 2019 00:53:08 +0200 Subject: [PATCH 03/17] passing unit tests for global topics --- flask_phpbb3/backends/psycopg2.py | 8 +- flask_phpbb3/extension.py | 4 +- .../postgres/global_topics_test_data.sql | 8 +- tests/fixtures/postgres/schema.sql | 153 ++++++++++++++++++ tests/integration/base.py | 20 +++ tests/integration/test_extension.py | 3 + tests/unit/backends/test_psycopg2.py | 10 +- 7 files changed, 191 insertions(+), 15 deletions(-) diff --git a/flask_phpbb3/backends/psycopg2.py b/flask_phpbb3/backends/psycopg2.py index 846c4e6..0555a59 100644 --- a/flask_phpbb3/backends/psycopg2.py +++ b/flask_phpbb3/backends/psycopg2.py @@ -100,8 +100,8 @@ def _prepare_statements(self): " AND nt.notification_type_enabled=1 " " AND n.notification_read=0" ), - fetch_global_topics=( - "SELECT" + fetch_global_topics=( + "SELECT" " t.topic_id," " t.forum_id," " t.topic_title," @@ -110,12 +110,13 @@ def _prepare_statements(self): " p.post_subject," " p.post_text " " FROM " - " {TABLE_PREFIX}topics t" + " {TABLE_PREFIX}topics t" " INNER JOIN {TABLE_PREFIX}posts p ON" " p.post_id = t.topic_first_post_id" " WHERE" " t.topic_type = 3" " AND t.forum_id = %(forum_id)s" + " order by t.topic_id " ), )) @@ -248,7 +249,6 @@ def execute( )) operation = command.split('_')[0] - func_or_query = self._functions[command] if callable(func_or_query): return func_or_query(**kwargs) diff --git a/flask_phpbb3/extension.py b/flask_phpbb3/extension.py index 31661c5..6648aad 100644 --- a/flask_phpbb3/extension.py +++ b/flask_phpbb3/extension.py @@ -230,14 +230,14 @@ def get_unread_notifications_count( def fetch_global_topics( self, - forum_id, + forum_id=0, skip=0, limit=10, cache=False, cache_ttl=None, ): output = self._backend.execute( - 'get_global_topics', + 'fetch_global_topics', forum_id=forum_id, skip=skip, limit=limit, diff --git a/tests/fixtures/postgres/global_topics_test_data.sql b/tests/fixtures/postgres/global_topics_test_data.sql index 25ec8dd..912dea2 100644 --- a/tests/fixtures/postgres/global_topics_test_data.sql +++ b/tests/fixtures/postgres/global_topics_test_data.sql @@ -1,18 +1,18 @@ -INSERT INTO public.phpbb_topics( +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',1,3), (1,0,'naslov teme 1',13,'drugi poster',2,3), (2,0,'naslov teme 2',200,'post it',0,3), - (3,0,'naslov teme 3',256,'posted it',3,3) + (3,0,'naslov teme 3',256,'posted it',3,3); - INSERT INTO public.phpbb_posts(post_id,post_subject,post_text + INSERT INTO phpbb_posts(post_id,post_subject,post_text ) VALUES (1,'prva tema', 'bla'), (2,'druga tema','blabla'), (0,'tretja tema','blablabla'), - (3,'tretja tema','bla krat 4') + (3,'tretja tema','bla krat 4'); diff --git a/tests/fixtures/postgres/schema.sql b/tests/fixtures/postgres/schema.sql index ede65cc..9449e70 100644 --- a/tests/fixtures/postgres/schema.sql +++ b/tests/fixtures/postgres/schema.sql @@ -156,3 +156,156 @@ create table phpbb_notification_types ( notification_type_name character varying(255) not null default ''::character varying, notification_type_enabled smallint not null default (1)::smallint ); + + +CREATE TABLE phpbb_topics ( + topic_id integer DEFAULT 0 NOT NULL, + forum_id integer DEFAULT 0 NOT NULL, + icon_id integer DEFAULT 0 NOT NULL, + topic_attachment smallint DEFAULT (0)::smallint NOT NULL, + topic_reported smallint DEFAULT (0)::smallint NOT NULL, + topic_title character varying(255) DEFAULT ''::character varying NOT NULL, + topic_poster integer DEFAULT 0 NOT NULL, + topic_time integer DEFAULT 0 NOT NULL, + topic_time_limit integer DEFAULT 0 NOT NULL, + topic_views integer DEFAULT 0 NOT NULL, + topic_status smallint DEFAULT (0)::smallint NOT NULL, + topic_type smallint DEFAULT (0)::smallint NOT NULL, + topic_first_post_id integer DEFAULT 0 NOT NULL, + topic_first_poster_name character varying(255) DEFAULT ''::character varying NOT NULL, + topic_first_poster_colour character varying(6) DEFAULT ''::character varying NOT NULL, + topic_last_post_id integer DEFAULT 0 NOT NULL, + topic_last_poster_id integer DEFAULT 0 NOT NULL, + topic_last_poster_name character varying(255) DEFAULT ''::character varying NOT NULL, + topic_last_poster_colour character varying(6) DEFAULT ''::character varying NOT NULL, + topic_last_post_subject character varying(255) DEFAULT ''::character varying NOT NULL, + topic_last_post_time integer DEFAULT 0 NOT NULL, + topic_last_view_time integer DEFAULT 0 NOT NULL, + topic_moved_id integer DEFAULT 0 NOT NULL, + topic_bumped smallint DEFAULT (0)::smallint NOT NULL, + topic_bumper integer DEFAULT 0 NOT NULL, + poll_title character varying(255) DEFAULT ''::character varying NOT NULL, + poll_start integer DEFAULT 0 NOT NULL, + poll_length integer DEFAULT 0 NOT NULL, + poll_max_options smallint DEFAULT (1)::smallint NOT NULL, + poll_last_vote integer DEFAULT 0 NOT NULL, + poll_vote_change smallint DEFAULT (0)::smallint NOT NULL, + topic_visibility smallint DEFAULT (0)::smallint NOT NULL, + topic_delete_time integer DEFAULT 0 NOT NULL, + topic_delete_reason character varying(255) DEFAULT ''::character varying NOT NULL, + topic_delete_user integer DEFAULT 0 NOT NULL, + topic_posts_approved integer DEFAULT 0 NOT NULL, + topic_posts_unapproved integer DEFAULT 0 NOT NULL, + topic_posts_softdeleted integer DEFAULT 0 NOT NULL, + CONSTRAINT phpbb_topics_forum_id_check CHECK ((forum_id >= 0)), + CONSTRAINT phpbb_topics_icon_id_check CHECK ((icon_id >= 0)), + CONSTRAINT phpbb_topics_poll_last_vote_check CHECK ((poll_last_vote >= 0)), + CONSTRAINT phpbb_topics_poll_length_check CHECK ((poll_length >= 0)), + CONSTRAINT phpbb_topics_poll_start_check CHECK ((poll_start >= 0)), + CONSTRAINT phpbb_topics_poll_vote_change_check CHECK ((poll_vote_change >= 0)), + CONSTRAINT phpbb_topics_topic_attachment_check CHECK ((topic_attachment >= 0)), + CONSTRAINT phpbb_topics_topic_bumped_check CHECK ((topic_bumped >= 0)), + CONSTRAINT phpbb_topics_topic_bumper_check CHECK ((topic_bumper >= 0)), + CONSTRAINT phpbb_topics_topic_delete_time_check CHECK ((topic_delete_time >= 0)), + CONSTRAINT phpbb_topics_topic_delete_user_check CHECK ((topic_delete_user >= 0)), + CONSTRAINT phpbb_topics_topic_delete_user_check1 CHECK ((topic_delete_user >= 0)), + CONSTRAINT phpbb_topics_topic_first_post_id_check CHECK ((topic_first_post_id >= 0)), + CONSTRAINT phpbb_topics_topic_first_post_id_check1 CHECK ((topic_first_post_id >= 0)), + CONSTRAINT phpbb_topics_topic_id_check CHECK ((topic_id >= 0)), + CONSTRAINT phpbb_topics_topic_last_post_id_check CHECK ((topic_last_post_id >= 0)), + CONSTRAINT phpbb_topics_topic_last_post_id_check1 CHECK ((topic_last_post_id >= 0)), + CONSTRAINT phpbb_topics_topic_last_post_time_check CHECK ((topic_last_post_time >= 0)), + CONSTRAINT phpbb_topics_topic_last_poster_id_check CHECK ((topic_last_poster_id >= 0)), + CONSTRAINT phpbb_topics_topic_last_poster_id_check1 CHECK ((topic_last_poster_id >= 0)), + CONSTRAINT phpbb_topics_topic_last_view_time_check CHECK ((topic_last_view_time >= 0)), + CONSTRAINT phpbb_topics_topic_moved_id_check CHECK ((topic_moved_id >= 0)), + CONSTRAINT phpbb_topics_topic_moved_id_check1 CHECK ((topic_moved_id >= 0)), + CONSTRAINT phpbb_topics_topic_poster_check CHECK ((topic_poster >= 0)), + CONSTRAINT phpbb_topics_topic_poster_check1 CHECK ((topic_poster >= 0)), + CONSTRAINT phpbb_topics_topic_posts_approved_check CHECK ((topic_posts_approved >= 0)), + CONSTRAINT phpbb_topics_topic_posts_softdeleted_check CHECK ((topic_posts_softdeleted >= 0)), + CONSTRAINT phpbb_topics_topic_posts_unapproved_check CHECK ((topic_posts_unapproved >= 0)), + CONSTRAINT phpbb_topics_topic_reported_check CHECK ((topic_reported >= 0)), + CONSTRAINT phpbb_topics_topic_time_check CHECK ((topic_time >= 0)), + CONSTRAINT phpbb_topics_topic_time_limit_check CHECK ((topic_time_limit >= 0)), + CONSTRAINT phpbb_topics_topic_views_check CHECK ((topic_views >= 0)) +); +ALTER TABLE ONLY phpbb_topics + ADD CONSTRAINT phpbb_topics_pkey PRIMARY KEY (topic_id); +CREATE INDEX phpbb_topics_fid_time_moved ON phpbb_topics USING btree (forum_id, topic_last_post_time, topic_moved_id); +CREATE INDEX phpbb_topics_forum_id ON phpbb_topics USING btree (forum_id); +CREATE INDEX phpbb_topics_forum_id_type ON phpbb_topics USING btree (forum_id, topic_type); +CREATE INDEX phpbb_topics_forum_vis_last ON phpbb_topics USING btree (forum_id, topic_visibility, topic_last_post_id); +CREATE INDEX phpbb_topics_last_post_time ON phpbb_topics USING btree (topic_last_post_time); +CREATE INDEX phpbb_topics_latest_topics ON phpbb_topics USING btree (forum_id, topic_last_post_time, topic_last_post_id, topic_moved_id); +CREATE INDEX phpbb_topics_topic_visibility ON phpbb_topics USING btree (topic_visibility); + + +CREATE TABLE phpbb_posts ( + post_id integer DEFAULT 0 NOT NULL, + topic_id integer DEFAULT 0 NOT NULL, + forum_id integer DEFAULT 0 NOT NULL, + poster_id integer DEFAULT 0 NOT NULL, + icon_id integer DEFAULT 0 NOT NULL, + poster_ip character varying(40) DEFAULT ''::character varying NOT NULL, + post_time integer DEFAULT 0 NOT NULL, + post_reported smallint DEFAULT (0)::smallint NOT NULL, + enable_bbcode smallint DEFAULT (1)::smallint NOT NULL, + enable_smilies smallint DEFAULT (1)::smallint NOT NULL, + enable_magic_url smallint DEFAULT (1)::smallint NOT NULL, + enable_sig smallint DEFAULT (1)::smallint NOT NULL, + post_username character varying(255) DEFAULT ''::character varying NOT NULL, + post_subject character varying(255) DEFAULT ''::character varying NOT NULL, + post_text text DEFAULT ''::text NOT NULL, + post_checksum character varying(32) DEFAULT ''::character varying NOT NULL, + post_attachment smallint DEFAULT (0)::smallint NOT NULL, + bbcode_bitfield character varying(255) DEFAULT ''::character varying NOT NULL, + bbcode_uid character varying(8) DEFAULT ''::character varying NOT NULL, + post_postcount smallint DEFAULT (1)::smallint NOT NULL, + post_edit_time integer DEFAULT 0 NOT NULL, + post_edit_reason character varying(255) DEFAULT ''::character varying NOT NULL, + post_edit_user integer DEFAULT 0 NOT NULL, + post_edit_count smallint DEFAULT (0)::smallint NOT NULL, + post_edit_locked smallint DEFAULT (0)::smallint NOT NULL, + post_visibility smallint DEFAULT (0)::smallint NOT NULL, + post_delete_time integer DEFAULT 0 NOT NULL, + post_delete_reason character varying(255) DEFAULT ''::character varying NOT NULL, + post_delete_user integer DEFAULT 0 NOT NULL, + CONSTRAINT phpbb_posts_enable_bbcode_check CHECK ((enable_bbcode >= 0)), + CONSTRAINT phpbb_posts_enable_magic_url_check CHECK ((enable_magic_url >= 0)), + CONSTRAINT phpbb_posts_enable_sig_check CHECK ((enable_sig >= 0)), + CONSTRAINT phpbb_posts_enable_smilies_check CHECK ((enable_smilies >= 0)), + CONSTRAINT phpbb_posts_forum_id_check CHECK ((forum_id >= 0)), + CONSTRAINT phpbb_posts_icon_id_check CHECK ((icon_id >= 0)), + CONSTRAINT phpbb_posts_post_attachment_check CHECK ((post_attachment >= 0)), + CONSTRAINT phpbb_posts_post_delete_time_check CHECK ((post_delete_time >= 0)), + CONSTRAINT phpbb_posts_post_delete_user_check CHECK ((post_delete_user >= 0)), + CONSTRAINT phpbb_posts_post_delete_user_check1 CHECK ((post_delete_user >= 0)), + CONSTRAINT phpbb_posts_post_edit_count_check CHECK ((post_edit_count >= 0)), + CONSTRAINT phpbb_posts_post_edit_locked_check CHECK ((post_edit_locked >= 0)), + CONSTRAINT phpbb_posts_post_edit_time_check CHECK ((post_edit_time >= 0)), + CONSTRAINT phpbb_posts_post_edit_user_check CHECK ((post_edit_user >= 0)), + CONSTRAINT phpbb_posts_post_edit_user_check1 CHECK ((post_edit_user >= 0)), + CONSTRAINT phpbb_posts_post_id_check CHECK ((post_id >= 0)), + CONSTRAINT phpbb_posts_post_postcount_check CHECK ((post_postcount >= 0)), + CONSTRAINT phpbb_posts_post_reported_check CHECK ((post_reported >= 0)), + CONSTRAINT phpbb_posts_post_time_check CHECK ((post_time >= 0)), + CONSTRAINT phpbb_posts_poster_id_check CHECK ((poster_id >= 0)), + CONSTRAINT phpbb_posts_poster_id_check1 CHECK ((poster_id >= 0)), + CONSTRAINT phpbb_posts_topic_id_check CHECK ((topic_id >= 0)), + CONSTRAINT phpbb_posts_topic_id_check1 CHECK ((topic_id >= 0)) +); +ALTER TABLE ONLY phpbb_posts + ADD CONSTRAINT phpbb_posts_pkey PRIMARY KEY (post_id); +CREATE INDEX phpbb_posts_forum_id ON phpbb_posts USING btree (forum_id); +CREATE INDEX phpbb_posts_post_username ON phpbb_posts USING btree (post_username); +CREATE INDEX phpbb_posts_post_visibility ON phpbb_posts USING btree (post_visibility); +CREATE INDEX phpbb_posts_poster_id ON phpbb_posts USING btree (poster_id); +CREATE INDEX phpbb_posts_poster_ip ON phpbb_posts USING btree (poster_ip); +CREATE INDEX phpbb_posts_simple_post_content ON phpbb_posts USING gin (to_tsvector('simple'::regconfig, ((post_text || ' '::text) || (post_subject)::text))); +CREATE INDEX phpbb_posts_simple_post_subject ON phpbb_posts USING gin (to_tsvector('simple'::regconfig, (post_subject)::text)); +CREATE INDEX phpbb_posts_tid_post_time ON phpbb_posts USING btree (topic_id, post_time); +CREATE INDEX phpbb_posts_topic_id ON phpbb_posts USING btree (topic_id); + + + diff --git a/tests/integration/base.py b/tests/integration/base.py index 5d394c4..eca5938 100644 --- a/tests/integration/base.py +++ b/tests/integration/base.py @@ -122,6 +122,26 @@ def _create_session(cursor, session_id, user_id): ) +def _create_global_topics(cursor): + 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)" + ) + 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')" + ) + + def _create_privilege(cursor, privilege_id, privilege): # type: (psycopg2.extensions.cursor, int, str) -> None cursor.execute( diff --git a/tests/integration/test_extension.py b/tests/integration/test_extension.py index e88c115..c78a6c1 100644 --- a/tests/integration/test_extension.py +++ b/tests/integration/test_extension.py @@ -70,6 +70,8 @@ def test_paging(self): self.assertEqual((skip, privilege), expected_privileges[skip]) def test_fetch_global_topics(self): + base._create_global_topics(self.cursor) + expected_topics = [(0, [{ 'topic_id': 0, 'forum_id': 0, @@ -174,6 +176,7 @@ def test_privilege(self): base._create_session(self.cursor, self.session_id, 2) base._create_privilege(self.cursor, 1, 'm_edit') base._grant_privilege(self.cursor, 2) + base._create_global_topics(self.cursor) data = self.client.get('/priv_test').data self.assertEqual(data, 'False,False,False') diff --git a/tests/unit/backends/test_psycopg2.py b/tests/unit/backends/test_psycopg2.py index 2b4eaa5..fdf867c 100644 --- a/tests/unit/backends/test_psycopg2.py +++ b/tests/unit/backends/test_psycopg2.py @@ -126,11 +126,11 @@ def test_empty(self, mocked_db): 'get_autologin', 'get_session', 'has_membership', + 'fetch_global_topics', 'fetch_acl_options', 'get_unread_notifications_count', 'get_user', 'get_user_profile', - 'fetch_global_topics', ] ) @@ -151,12 +151,12 @@ def test_valid(self, mocked_db): 'get_session', 'set_some_field', 'has_membership', + 'fetch_global_topics', 'fetch_acl_options', 'set_another_field', 'get_unread_notifications_count', 'get_user', 'get_user_profile', - 'fetch_global_topics', ]), ) @@ -179,11 +179,11 @@ def test_empty(self, mocked_db): 'get_autologin', 'get_session', 'has_membership', + 'fetch_global_topics', 'fetch_acl_options', 'get_unread_notifications_count', 'get_user', 'get_user_profile', - 'fetch_global_topics', ] ) @@ -205,12 +205,12 @@ def test_addition(self, mocked_db): 'get_autologin', 'get_session', 'has_membership', + 'fetch_global_topics', 'fetch_acl_options', 'get_unread_notifications_count', 'some_custom_statement', 'get_user', 'get_user_profile', - 'fetch_global_topics', ] ) self.assertEqual( @@ -236,11 +236,11 @@ def test_override(self, mocked_db): 'get_autologin', 'get_session', 'has_membership', + 'fetch_global_topics', 'fetch_acl_options', 'get_unread_notifications_count', 'get_user', 'get_user_profile', - 'fetch_global_topics', ] ) self.assertEqual( From 842ba9b02b9aed9f6333ca1849bfb2acbacea345 Mon Sep 17 00:00:00 2001 From: Gregor Date: Sun, 19 May 2019 01:09:24 +0200 Subject: [PATCH 04/17] added data annotaions for global topics --- flask_phpbb3/extension.py | 1 + tests/integration/base.py | 1 + tests/integration/test_extension.py | 1 + 3 files changed, 3 insertions(+) diff --git a/flask_phpbb3/extension.py b/flask_phpbb3/extension.py index 6648aad..155085a 100644 --- a/flask_phpbb3/extension.py +++ b/flask_phpbb3/extension.py @@ -236,6 +236,7 @@ def fetch_global_topics( cache=False, cache_ttl=None, ): + # type: (...) -> typing.Optional[dict] output = self._backend.execute( 'fetch_global_topics', forum_id=forum_id, diff --git a/tests/integration/base.py b/tests/integration/base.py index eca5938..c25623f 100644 --- a/tests/integration/base.py +++ b/tests/integration/base.py @@ -123,6 +123,7 @@ 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," diff --git a/tests/integration/test_extension.py b/tests/integration/test_extension.py index c78a6c1..0cf6b21 100644 --- a/tests/integration/test_extension.py +++ b/tests/integration/test_extension.py @@ -70,6 +70,7 @@ def test_paging(self): self.assertEqual((skip, privilege), expected_privileges[skip]) def test_fetch_global_topics(self): + # type: () -> None base._create_global_topics(self.cursor) expected_topics = [(0, [{ From 84e020bf098985b586b731fddbde562a88da25ee Mon Sep 17 00:00:00 2001 From: Gregor Date: Sun, 19 May 2019 01:25:11 +0200 Subject: [PATCH 05/17] corrections in formatting of code --- flask_phpbb3/backends/psycopg2.py | 30 ++++++++++++++--------------- flask_phpbb3/extension.py | 2 +- tests/integration/base.py | 4 ++-- tests/integration/test_extension.py | 5 ++++- tests/unit/test_sessions.py | 4 +--- 5 files changed, 23 insertions(+), 22 deletions(-) diff --git a/flask_phpbb3/backends/psycopg2.py b/flask_phpbb3/backends/psycopg2.py index 0555a59..b086979 100644 --- a/flask_phpbb3/backends/psycopg2.py +++ b/flask_phpbb3/backends/psycopg2.py @@ -100,22 +100,22 @@ def _prepare_statements(self): " AND nt.notification_type_enabled=1 " " AND n.notification_read=0" ), - fetch_global_topics=( + fetch_global_topics=( "SELECT" - " t.topic_id," - " t.forum_id," - " t.topic_title," - " t.topic_time," - " t.topic_first_poster_name," - " p.post_subject," - " p.post_text " - " FROM " - " {TABLE_PREFIX}topics t" - " INNER JOIN {TABLE_PREFIX}posts p ON" - " p.post_id = t.topic_first_post_id" - " WHERE" - " t.topic_type = 3" - " AND t.forum_id = %(forum_id)s" + " t.topic_id," + " t.forum_id," + " t.topic_title," + " t.topic_time," + " t.topic_first_poster_name," + " p.post_subject," + " p.post_text " + " FROM " + " {TABLE_PREFIX}topics t" + " INNER JOIN {TABLE_PREFIX}posts p ON" + " p.post_id = t.topic_first_post_id" + " WHERE" + " t.topic_type = 3" + " AND t.forum_id = %(forum_id)s" " order by t.topic_id " ), )) diff --git a/flask_phpbb3/extension.py b/flask_phpbb3/extension.py index 155085a..bf2d24a 100644 --- a/flask_phpbb3/extension.py +++ b/flask_phpbb3/extension.py @@ -244,7 +244,7 @@ def fetch_global_topics( limit=limit, cache=cache, cache_ttl=cache_ttl, - ) # type: typing.Optional[dict] + ) # type: typing.Optional[dict] return output def get_user_acl(self, raw_user_permissions): diff --git a/tests/integration/base.py b/tests/integration/base.py index c25623f..51c9e30 100644 --- a/tests/integration/base.py +++ b/tests/integration/base.py @@ -125,10 +125,10 @@ def _create_session(cursor, session_id, user_id): def _create_global_topics(cursor): # type: (psycopg2.extensions.cursor) -> None cursor.execute( - "insert into" + " 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)," + " 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)" diff --git a/tests/integration/test_extension.py b/tests/integration/test_extension.py index 0cf6b21..221c78f 100644 --- a/tests/integration/test_extension.py +++ b/tests/integration/test_extension.py @@ -107,7 +107,10 @@ def test_fetch_global_topics(self): 'post_subject': 'tretja tema', 'post_text': 'bla x4'}])] for skip in range(0, 3): - topic = self.app.phpbb3.fetch_global_topics(skip=skip, limit=1, forum_id=0) + topic = self.app.phpbb3.fetch_global_topics( + skip=skip, + limit=1, + forum_id=0) self.assertEqual((skip, topic), expected_topics[skip]) diff --git a/tests/unit/test_sessions.py b/tests/unit/test_sessions.py index 2d2b822..0d27174 100644 --- a/tests/unit/test_sessions.py +++ b/tests/unit/test_sessions.py @@ -267,6 +267,4 @@ def test_cache(self, mocked_phpbb3): mocked_phpbb3.get_unread_notifications_count.assert_called_once_with( user_id=user_id, - ) - - + ) \ No newline at end of file From 6a86483494e8780939ba7c5a62b932315709a073 Mon Sep 17 00:00:00 2001 From: Gregor Date: Sun, 19 May 2019 01:29:43 +0200 Subject: [PATCH 06/17] whitespaces and new lines corrections --- tests/integration/base.py | 2 +- tests/unit/test_sessions.py | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/tests/integration/base.py b/tests/integration/base.py index 51c9e30..1a51d6d 100644 --- a/tests/integration/base.py +++ b/tests/integration/base.py @@ -125,7 +125,7 @@ def _create_session(cursor, session_id, user_id): def _create_global_topics(cursor): # type: (psycopg2.extensions.cursor) -> None cursor.execute( - " insert into" + "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)," diff --git a/tests/unit/test_sessions.py b/tests/unit/test_sessions.py index 0d27174..e0bab2c 100644 --- a/tests/unit/test_sessions.py +++ b/tests/unit/test_sessions.py @@ -267,4 +267,5 @@ def test_cache(self, mocked_phpbb3): mocked_phpbb3.get_unread_notifications_count.assert_called_once_with( user_id=user_id, - ) \ No newline at end of file + ) + \ No newline at end of file From d444427936e4ae0396984aa460459dc3172a9943 Mon Sep 17 00:00:00 2001 From: Gregor Date: Sun, 19 May 2019 23:23:46 +0200 Subject: [PATCH 07/17] more formatting corrections --- tests/integration/base.py | 2 +- tests/unit/test_sessions.py | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/tests/integration/base.py b/tests/integration/base.py index 1a51d6d..92cef07 100644 --- a/tests/integration/base.py +++ b/tests/integration/base.py @@ -125,7 +125,7 @@ def _create_session(cursor, session_id, user_id): def _create_global_topics(cursor): # type: (psycopg2.extensions.cursor) -> None cursor.execute( - "insert into" + "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)," diff --git a/tests/unit/test_sessions.py b/tests/unit/test_sessions.py index e0bab2c..a5c12b4 100644 --- a/tests/unit/test_sessions.py +++ b/tests/unit/test_sessions.py @@ -268,4 +268,3 @@ def test_cache(self, mocked_phpbb3): mocked_phpbb3.get_unread_notifications_count.assert_called_once_with( user_id=user_id, ) - \ No newline at end of file From ff30dedc95d4151e258c52940cc8480550a91cec Mon Sep 17 00:00:00 2001 From: Gregor Date: Sun, 19 May 2019 23:29:11 +0200 Subject: [PATCH 08/17] 3.7 build corrections --- flask_phpbb3/extension.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/flask_phpbb3/extension.py b/flask_phpbb3/extension.py index bf2d24a..9984c8e 100644 --- a/flask_phpbb3/extension.py +++ b/flask_phpbb3/extension.py @@ -230,11 +230,11 @@ def get_unread_notifications_count( def fetch_global_topics( self, - forum_id=0, - skip=0, - limit=10, - cache=False, - cache_ttl=None, + forum_id=0, # type: int + skip=0, # type: int + limit=10, # type: int + cache=False, # type: bool + cache_ttl=None, # type: typing.Optional[int] ): # type: (...) -> typing.Optional[dict] output = self._backend.execute( From 7c6ad65cff77d555771262ae6a97a5ddf68a2081 Mon Sep 17 00:00:00 2001 From: Gregor Date: Thu, 23 May 2019 23:21:19 +0200 Subject: [PATCH 09/17] Changes based on first review --- .../postgres/global_topics_test_data.sql | 18 ---- tests/integration/base.py | 92 ++++++++++++++++--- tests/integration/test_extension.py | 62 +++++++++---- 3 files changed, 125 insertions(+), 47 deletions(-) delete mode 100644 tests/fixtures/postgres/global_topics_test_data.sql diff --git a/tests/fixtures/postgres/global_topics_test_data.sql b/tests/fixtures/postgres/global_topics_test_data.sql deleted file mode 100644 index 912dea2..0000000 --- a/tests/fixtures/postgres/global_topics_test_data.sql +++ /dev/null @@ -1,18 +0,0 @@ -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',1,3), - (1,0,'naslov teme 1',13,'drugi poster',2,3), - (2,0,'naslov teme 2',200,'post it',0,3), - (3,0,'naslov teme 3',256,'posted it',3,3); - - - - INSERT INTO phpbb_posts(post_id,post_subject,post_text - ) - VALUES - (1,'prva tema', 'bla'), - (2,'druga tema','blabla'), - (0,'tretja tema','blablabla'), - (3,'tretja tema','bla krat 4'); - diff --git a/tests/integration/base.py b/tests/integration/base.py index 92cef07..1c046c4 100644 --- a/tests/integration/base.py +++ b/tests/integration/base.py @@ -124,22 +124,88 @@ 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" + ")" ) + 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 (" + "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'" + ")" ) diff --git a/tests/integration/test_extension.py b/tests/integration/test_extension.py index 221c78f..0392447 100644 --- a/tests/integration/test_extension.py +++ b/tests/integration/test_extension.py @@ -76,42 +76,72 @@ def test_fetch_global_topics(self): expected_topics = [(0, [{ 'topic_id': 0, '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': 'not existent 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, + 'dont_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: + self.assertNotEqual((skip, topic), expected_topics[skip]) + else: + self.assertEqual((skip, topic), expected_topics[skip]) class TestSession(base.TestWithDatabase): From 0aec5df2b6738642ce7013fa8500eeb5f68f6c3f Mon Sep 17 00:00:00 2001 From: Gregor Date: Thu, 23 May 2019 23:27:03 +0200 Subject: [PATCH 10/17] Changes based on first review --- tests/integration/base.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/tests/integration/base.py b/tests/integration/base.py index 1c046c4..0439c64 100644 --- a/tests/integration/base.py +++ b/tests/integration/base.py @@ -181,6 +181,14 @@ def _create_global_topics(cursor): ",'posted as 7, expecting 6'" ",3" ",3" + ") , (" + "7" + ",0" + ",'different data type'" + ",999" + ",'inserted into table, expecting different type'" + ",3" + ",3" ")" ) From 41bd085d62399fcf2948f0f89b5bdff039f85ce6 Mon Sep 17 00:00:00 2001 From: Gregor Date: Thu, 23 May 2019 23:32:53 +0200 Subject: [PATCH 11/17] Changes for 2.7 build, fixed errors --- tests/integration/test_extension.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/integration/test_extension.py b/tests/integration/test_extension.py index 0392447..83b2f3b 100644 --- a/tests/integration/test_extension.py +++ b/tests/integration/test_extension.py @@ -107,11 +107,11 @@ def test_fetch_global_topics(self): 'post_subject': 'topic three', 'post_text': 'hello times four'}]), (4, [{ - 'topic_id':4, - 'forum_id':2, + 'topic_id': 4, + 'forum_id': 2, 'topic_title': 'topic missing', 'topic_time': 666, - 'topic_first_poster_name': 'not existent forum', + 'topic_first_poster_name': 'no forum', 'post_subject': 'topic yes, forum no', 'post_text': 'test case'}]), (5, [{ @@ -127,7 +127,7 @@ def test_fetch_global_topics(self): 'random_column': 0, 'topic_title': 'topic missing', 'topic_time': 777, - 'dont_change_all': 'not existent forum', + 'do not_change_all': 'not existent forum', 'post_subject': 'topic yes, forum no', 'post_text': 'test case'}]), (7, [1, 2, 3]) From 581508d55fd865895d16761d0bc58b8693b7c395 Mon Sep 17 00:00:00 2001 From: Gregor Date: Thu, 23 May 2019 23:38:39 +0200 Subject: [PATCH 12/17] last format fix --- tests/integration/test_extension.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/integration/test_extension.py b/tests/integration/test_extension.py index 83b2f3b..d0c40b7 100644 --- a/tests/integration/test_extension.py +++ b/tests/integration/test_extension.py @@ -127,7 +127,7 @@ def test_fetch_global_topics(self): 'random_column': 0, 'topic_title': 'topic missing', 'topic_time': 777, - 'do not_change_all': 'not existent forum', + 'do_not_change_all': 'not existent forum', 'post_subject': 'topic yes, forum no', 'post_text': 'test case'}]), (7, [1, 2, 3]) From b7fb25f504f6221bb23d1e4d34ec287768be6161 Mon Sep 17 00:00:00 2001 From: Gregor Date: Thu, 23 May 2019 23:44:17 +0200 Subject: [PATCH 13/17] indentation fix in base.py --- tests/integration/base.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/integration/base.py b/tests/integration/base.py index 0439c64..c269095 100644 --- a/tests/integration/base.py +++ b/tests/integration/base.py @@ -126,7 +126,7 @@ def _create_global_topics(cursor): # type: (psycopg2.extensions.cursor) -> None cursor.execute( - "insert into phpbb_topics (" + "insert into phpbb_topics (" "topic_id" ",forum_id" ",topic_title" From f03e8133e3a8f3cc889ed71e2ee64562e771abe0 Mon Sep 17 00:00:00 2001 From: Gregor Date: Tue, 17 Sep 2019 02:48:49 +0200 Subject: [PATCH 14/17] changes in tests --- tests/integration/base.py | 108 ++++++------------------- tests/integration/test_extension.py | 121 +++++++++++++++------------- 2 files changed, 87 insertions(+), 142 deletions(-) diff --git a/tests/integration/base.py b/tests/integration/base.py index c269095..6249ef0 100644 --- a/tests/integration/base.py +++ b/tests/integration/base.py @@ -127,93 +127,33 @@ def _create_global_topics(cursor): 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" - ",'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" - ")" - ) + " 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',4,3)" + " ,(5,1,'topic title 5',2,'no forum poster',2,3)" + " ,(6,1,'topic title 5',2,'no forum poster',2,2)" + ) cursor.execute( " insert into phpbb_posts (" - "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'" - ")" + " 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')" ) diff --git a/tests/integration/test_extension.py b/tests/integration/test_extension.py index d0c40b7..e6b73b6 100644 --- a/tests/integration/test_extension.py +++ b/tests/integration/test_extension.py @@ -69,79 +69,84 @@ def test_paging(self): privilege = self.app.phpbb3.fetch_acl_options(skip=skip, limit=1) self.assertEqual((skip, privilege), expected_privileges[skip]) - def test_fetch_global_topics(self): + def test_fetch_global_topics_positive(self): # type: () -> None base._create_global_topics(self.cursor) expected_topics = [(0, [{ - 'topic_id': 0, - 'forum_id': 0, - 'topic_title': 'topic title 0', - 'topic_time': 10, - 'topic_first_poster_name': 'name', - 'post_subject': 'topic one', - 'post_text': 'hello'}]), + 'topic_id': 0, + 'forum_id': 0, + 'topic_title': 'topic title 0', + 'topic_time': 10, + 'topic_first_poster_name': 'name', + 'post_subject': 'topic one', + 'post_text': 'hello'}]), (1, [{ - 'topic_id': 1, - 'forum_id': 0, - 'topic_title': 'topic title 1', - 'topic_time': 13, - 'topic_first_poster_name': 'second poster', - 'post_subject': 'topic two', - 'post_text': 'hello world'}]), + 'topic_id': 1, + 'forum_id': 0, + 'topic_title': 'topic title 1', + 'topic_time': 13, + 'topic_first_poster_name': 'second poster', + 'post_subject': 'topic two', + 'post_text': 'hello world'}]), (2, [{ - 'topic_id': 2, - 'forum_id': 0, - 'topic_title': 'topic title 2', - 'topic_time': 200, - 'topic_first_poster_name': 'post it', - 'post_subject': 'topic three', - 'post_text': 'hello hello'}]), + 'topic_id': 2, + 'forum_id': 0, + 'topic_title': 'topic title 2', + 'topic_time': 200, + 'topic_first_poster_name': 'post it', + 'post_subject': 'topic three', + 'post_text': 'hello hello'}]), (3, [{ - 'topic_id': 3, - 'forum_id': 0, - 'topic_title': 'topic title 3', - 'topic_time': 256, - 'topic_first_poster_name': 'posted it', - '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, + 'topic_id': 3, '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]) + 'topic_title': 'topic title 3', + 'topic_time': 256, + 'topic_first_poster_name': 'posted it', + 'post_subject': 'topic three', + 'post_text': 'hello times four'}]) ] - for skip in range(0, 7): + for skip in range(0, 3): topic = self.app.phpbb3.fetch_global_topics( skip=skip, limit=1, forum_id=0) - if skip > 3: - self.assertNotEqual((skip, topic), expected_topics[skip]) - else: - self.assertEqual((skip, topic), expected_topics[skip]) + + self.assertEqual((skip, topic), expected_topics[skip]) + + def test_fetch_global_topics_topic_not_existing(self): + # type: () -> None + base._create_global_topics(self.cursor) + skip = 4 + topic = self.app.phpbb3.fetch_global_topics( + skip=skip, + limit=1, + forum_id=0) + + self.assertTrue(topic == []) + + def test_fetch_global_topics_forum_not_existing(self): + # type () -> None + base._create_global_topics(self.cursor) + skip = 5 + topic = self.app.phpbb3.fetch_global_topics( + skip=skip, + limit=1, + forum_id=1) + + self.assertTrue(topic == []) + + def test_fetch_global_topics_not_global_topic(self): + # type () -> None + base._create_global_topics(self.cursor) + skip=6 + topic = self.app.phpbb3.fetch_global_topics( + skip=skip, + limit=1, + forum_id=0) + self.assertTrue(topic == []) class TestSession(base.TestWithDatabase): From 5dc528b402f5f3eb3c75b2af46d9822581b443d9 Mon Sep 17 00:00:00 2001 From: Gregor Date: Tue, 17 Sep 2019 16:52:23 +0200 Subject: [PATCH 15/17] formatting differences --- tests/integration/test_extension.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/integration/test_extension.py b/tests/integration/test_extension.py index e6b73b6..b40e860 100644 --- a/tests/integration/test_extension.py +++ b/tests/integration/test_extension.py @@ -141,7 +141,7 @@ def test_fetch_global_topics_forum_not_existing(self): def test_fetch_global_topics_not_global_topic(self): # type () -> None base._create_global_topics(self.cursor) - skip=6 + skip = 6 topic = self.app.phpbb3.fetch_global_topics( skip=skip, limit=1, From 7e8996a6ee34a1ab8c4b6dda09cfcfd4105a2707 Mon Sep 17 00:00:00 2001 From: Gregor Date: Tue, 17 Sep 2019 17:03:58 +0200 Subject: [PATCH 16/17] testing psql server availability --- tests/integration/base.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/integration/base.py b/tests/integration/base.py index 6249ef0..b812370 100644 --- a/tests/integration/base.py +++ b/tests/integration/base.py @@ -12,7 +12,7 @@ import psycopg2.extras -DB_HOST = '127.0.0.1' +DB_HOST = '0.0.0.0' DB_ROOT_USER = 'postgres' DB_USER = 'phpbb3_test' DB_NAME = 'phpbb3_test' From 5451ccc7ebbc980d08a65365af1313ce8fdd7aec Mon Sep 17 00:00:00 2001 From: Gregor Date: Wed, 18 Sep 2019 20:03:16 +0200 Subject: [PATCH 17/17] travis postgres version change --- .travis.yml | 2 +- tests/integration/base.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 13b6f09..3182868 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,7 +2,7 @@ language: python services: - postgresql addons: - postgresql: "9.2" + postgresql: "9.5" python: - "2.7" - "3.6" diff --git a/tests/integration/base.py b/tests/integration/base.py index b812370..6249ef0 100644 --- a/tests/integration/base.py +++ b/tests/integration/base.py @@ -12,7 +12,7 @@ import psycopg2.extras -DB_HOST = '0.0.0.0' +DB_HOST = '127.0.0.1' DB_ROOT_USER = 'postgres' DB_USER = 'phpbb3_test' DB_NAME = 'phpbb3_test'