Skip to content

Commit 4802bf4

Browse files
authored
Merge pull request #12 from Podnapisi-NET/tests
Write initial tests
2 parents 414198a + 3b9caf8 commit 4802bf4

14 files changed

Lines changed: 766 additions & 13 deletions

File tree

.gitignore

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
1-
build
2-
dist
1+
# Distribution
2+
build/
3+
dist/
4+
.eggs/
35
Flask*egg-info
6+
# Local config
47
.vscode/
8+
# Testing
59
.mypy_cache/
10+
htmlcov/
11+
.coverage
12+
# Bytecode
13+
*.pyc

.travis.yml

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,19 @@
11
language: python
2+
services:
3+
- postgresql
4+
addons:
5+
postgresql: "9.2"
26
python:
37
- "2.7"
48
- "3.6"
59
install:
6-
- pip install -r requirements.txt
7-
- pip install flake8
8-
- if [[ $TRAVIS_PYTHON_VERSION != 2.7 ]]; then pip install mypy; fi
10+
- |
11+
if [[ $TRAVIS_PYTHON_VERSION = 2.7 ]]; then
12+
pip install -r requirements/dev.txt
13+
else
14+
pip install -r requirements/dev-3.txt
15+
fi
916
script:
1017
- if [[ $TRAVIS_PYTHON_VERSION = 2.7 ]]; then flake8; fi
1118
- if [[ $TRAVIS_PYTHON_VERSION != 2.7 ]]; then mypy flask_phpbb3.py; fi
19+
- if [[ $TRAVIS_PYTHON_VERSION = 2.7 ]]; then python setup.py test; fi

docker-compose.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
version: '3.1'
2+
3+
services:
4+
postgresql-9.6:
5+
image: postgres:9.6
6+
ports:
7+
- 5432:5432

flask_phpbb3.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -329,14 +329,24 @@ def __setitem__(self, key, value):
329329
modified = self.get(key) != value
330330
super(PhpBB3Session, self).__setitem__(key, value)
331331
if key not in self._read_only_properties:
332-
self.modified = modified
332+
self.modified |= modified
333+
334+
def __delitem__(self, key):
335+
# type: (str) -> None
336+
super(PhpBB3Session, self).__delitem__(key)
337+
self.modified = True
333338

334339
def pop(self, *args, **kwargs):
335340
# type: (*typing.Any, **typing.Any) -> typing.Any
336341
"""Wrapper to set modified."""
337342
self.modified = True
338343
return super(PhpBB3Session, self).pop(*args, **kwargs)
339344

345+
def clear(self):
346+
# type: () -> None
347+
self.modified = True
348+
return super(PhpBB3Session, self).clear()
349+
340350
@property
341351
def is_authenticated(self):
342352
# type: () -> bool

requirements.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
psycopg2>=2.4.5
2-
Flask>=0.10
2+
Flask>=0.10
3+
typing

requirements/dev-3.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
-r dev.txt
2+
mypy

requirements/dev.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
-r ../requirements.txt
2+
flake8
3+
flake8-import-order
4+
coverage
5+
mock

setup.cfg

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,3 @@ modules = flask_phpbb3
2222

2323
[wheel]
2424
universal = 1
25-
26-
[extras]
27-
development =
28-
flake8
29-
flake8-import-order
30-
mypy:python_version>='3.4'

tests/__init__.py

Whitespace-only changes.

tests/fixtures/postgres/schema.sql

Lines changed: 156 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,156 @@
1+
-- A poor man's phpbb3 copy
2+
create table phpbb_users (
3+
user_id serial primary key,
4+
user_type smallint not null default 0,
5+
group_id integer not null default 3,
6+
user_permissions text not null default '',
7+
user_perm_from integer not null default 0,
8+
user_ip character varying(40) not null default ''::character varying,
9+
user_regdate integer not null default 0,
10+
username varchar not null default ''::character varying,
11+
username_clean varchar not null default ''::character varying,
12+
user_password character varying(255) not null default ''::character varying,
13+
user_passchg integer not null default 0,
14+
user_email character varying(100) not null default ''::character varying,
15+
user_email_hash bigint not null default (0)::bigint,
16+
user_birthday character varying(10) not null default ''::character varying,
17+
user_lastvisit integer not null default 0,
18+
user_lastmark integer not null default 0,
19+
user_lastpost_time integer not null default 0,
20+
user_lastpage character varying(200) not null default ''::character varying,
21+
user_last_confirm_key character varying(10) not null default ''::character varying,
22+
user_last_search integer not null default 0,
23+
user_warnings smallint not null default (0)::smallint,
24+
user_last_warning integer not null default 0,
25+
user_login_attempts smallint not null default (0)::smallint,
26+
user_inactive_reason smallint not null default (0)::smallint,
27+
user_inactive_time integer not null default 0,
28+
user_posts integer not null default 0,
29+
user_lang character varying(30) not null default ''::character varying,
30+
user_timezone character varying(100) not null default ''::character varying,
31+
user_dateformat character varying(64) not null default 'd M Y H:i'::character varying,
32+
user_style integer not null default 0,
33+
user_rank integer not null default 0,
34+
user_colour character varying(6) not null default ''::character varying,
35+
user_new_privmsg integer not null default 0,
36+
user_unread_privmsg integer not null default 0,
37+
user_last_privmsg integer not null default 0,
38+
user_message_rules smallint not null default (0)::smallint,
39+
user_full_folder integer not null default (-3),
40+
user_emailtime integer not null default 0,
41+
user_topic_show_days smallint not null default (0)::smallint,
42+
user_topic_sortby_type character varying(1) not null default 't'::character varying,
43+
user_topic_sortby_dir character varying(1) not null default 'd'::character varying,
44+
user_post_show_days smallint not null default (0)::smallint,
45+
user_post_sortby_type character varying(1) not null default 't'::character varying,
46+
user_post_sortby_dir character varying(1) not null default 'a'::character varying,
47+
user_notify smallint not null default (0)::smallint,
48+
user_notify_pm smallint not null default (1)::smallint,
49+
user_notify_type smallint not null default (0)::smallint,
50+
user_allow_pm smallint not null default (1)::smallint,
51+
user_allow_viewonline smallint not null default (1)::smallint,
52+
user_allow_viewemail smallint not null default (1)::smallint,
53+
user_allow_massemail smallint not null default (1)::smallint,
54+
user_options integer not null default 230271,
55+
user_avatar character varying(255) not null default ''::character varying,
56+
user_avatar_type character varying(255) not null default ''::character varying,
57+
user_avatar_width smallint not null default (0)::smallint,
58+
user_avatar_height smallint not null default (0)::smallint,
59+
user_sig text not null default ''::text,
60+
user_sig_bbcode_uid character varying(8) not null default ''::character varying,
61+
user_sig_bbcode_bitfield character varying(255) not null default ''::character varying,
62+
user_jabber character varying(255) not null default ''::character varying,
63+
user_actkey character varying(32) not null default ''::character varying,
64+
user_newpasswd character varying(255) not null default ''::character varying,
65+
user_form_salt character varying(32) not null default ''::character varying,
66+
user_new smallint not null default (1)::smallint,
67+
user_reminded smallint not null default (0)::smallint,
68+
user_reminded_time integer not null default 0
69+
);
70+
71+
insert into phpbb_users (
72+
username
73+
, username_clean
74+
) values (
75+
'Anonymous'
76+
, 'anonymous'
77+
);
78+
79+
create table phpbb_sessions_keys (
80+
key_id character(32) not null default ''::bpchar,
81+
user_id integer not null default 0,
82+
last_ip character varying(40) not null default ''::character varying,
83+
last_login integer not null default 0
84+
);
85+
86+
create table phpbb_sessions (
87+
session_id character(32) not null default ''::bpchar,
88+
session_user_id integer not null default 0,
89+
session_forum_id integer not null default 0,
90+
session_last_visit integer not null default 0,
91+
session_start integer not null default 0,
92+
session_time integer not null default 0,
93+
session_ip character varying(40) not null default ''::character varying,
94+
session_browser character varying(150) not null default ''::character varying,
95+
session_forwarded_for character varying(255) not null default ''::character varying,
96+
session_page character varying(255) not null default ''::character varying,
97+
session_viewonline smallint not null default (1)::smallint,
98+
session_autologin smallint not null default (0)::smallint,
99+
session_admin smallint not null default (0)::smallint
100+
);
101+
102+
create table phpbb_user_group (
103+
group_id integer not null default 0,
104+
user_id integer not null default 0,
105+
group_leader smallint not null default (0)::smallint,
106+
user_pending smallint not null default (1)::smallint
107+
);
108+
109+
create table phpbb_groups (
110+
group_id serial primary key,
111+
group_type smallint not null default (1)::smallint,
112+
group_founder_manage smallint not null default (0)::smallint,
113+
group_skip_auth smallint not null default (0)::smallint,
114+
group_name varchar not null default ''::character varying,
115+
group_desc character varying(4000) not null default ''::character varying,
116+
group_desc_bitfield character varying(255) not null default ''::character varying,
117+
group_desc_options integer not null default 7,
118+
group_desc_uid character varying(8) not null default ''::character varying,
119+
group_display smallint not null default (0)::smallint,
120+
group_avatar character varying(255) not null default ''::character varying,
121+
group_avatar_type character varying(255) not null default ''::character varying,
122+
group_avatar_width smallint not null default (0)::smallint,
123+
group_avatar_height smallint not null default (0)::smallint,
124+
group_rank integer not null default 0,
125+
group_colour character varying(6) not null default ''::character varying,
126+
group_sig_chars integer not null default 0,
127+
group_receive_pm smallint not null default (0)::smallint,
128+
group_message_limit integer not null default 0,
129+
group_max_recipients integer not null default 0,
130+
group_legend integer not null default 0
131+
);
132+
133+
create table phpbb_acl_options (
134+
auth_option_id serial primary key,
135+
auth_option character varying(50) not null default ''::character varying,
136+
is_global smallint not null default (0)::smallint,
137+
is_local smallint not null default (0)::smallint,
138+
founder_only smallint not null default (0)::smallint
139+
);
140+
141+
create table phpbb_notifications (
142+
notification_id serial primary key,
143+
notification_type_id smallint not null default (0)::smallint,
144+
item_id integer not null default 0,
145+
item_parent_id integer not null default 0,
146+
user_id integer not null default 0,
147+
notification_read smallint not null default (0)::smallint,
148+
notification_time integer not null default 1,
149+
notification_data character varying(4000) not null default ''::character varying
150+
);
151+
152+
create table phpbb_notification_types (
153+
notification_type_id smallint primary key,
154+
notification_type_name character varying(255) not null default ''::character varying,
155+
notification_type_enabled smallint not null default (1)::smallint
156+
);

0 commit comments

Comments
 (0)