1 from tests.test_basics import BasicTest
6 from click.testing import CliRunner
7 from motion import create_user
8 from motion import motion_masking
12 class GeneralTests(BasicTest):
20 def test_create_user(self):
22 host= app.config.get("DEFAULT_HOST")
23 runner = app.test_cli_runner()
24 result = runner.invoke(create_user, (user, host))
25 assert result.exit_code == 0
26 self.assertIn("User 'John Doe' inserted to %s." % host, result.output)
28 rv = self.db_select2("SELECT email FROM voter WHERE lower(email)=lower($1) AND host=$2", user, host)
29 self.assertIn(user, rv[0].get("email"))
31 result = runner.invoke(create_user, (user, host))
32 assert result.exit_code == 0
33 self.assertIn("User 'John Doe' already exists on %s." % host, result.output)
35 # test with second host
36 host= '127.0.0.1:5001'
37 runner = app.test_cli_runner()
38 result = runner.invoke(create_user, (user, host))
39 assert result.exit_code == 0
40 self.assertIn("User 'John Doe' inserted to 127.0.0.1:5001.", result.output)
42 rv = self.db_select2("SELECT email FROM voter WHERE lower(email)=lower($1) AND host=$2", user, host)
43 self.assertIn(user, rv[0].get("email"))
45 result = runner.invoke(create_user, (user, host))
46 assert result.exit_code == 0
47 self.assertIn("User 'John Doe' already exists on 127.0.0.1:5001.", result.output)
49 def test_motion_masking(self):
52 self.assertEqual(records, self.recordCountLog('motionmasking'))
54 # test motion not exists
55 motion = 'g1.20200402.999'
56 motionreason='http://motiontest.wpia.club/motion/xxx'
57 host= app.config.get("DEFAULT_HOST")
58 runner = app.test_cli_runner()
59 result = runner.invoke(motion_masking, (motion, motionreason, host))
60 assert result.exit_code == 0
61 self.assertIn("0 record(s) affected by masking of 'g1.20200402.999'.", result.output)
62 self.assertEqual(records, self.recordCountLog('motionmasking'))
64 # test motion with wilcards
65 motion = 'g1.20200402.00%'
66 motionreason='http://motiontest.wpia.club/motion/xxx'
67 host= app.config.get("DEFAULT_HOST")
68 runner = app.test_cli_runner()
69 result = runner.invoke(motion_masking, (motion, motionreason, host))
70 assert result.exit_code == 0
71 self.assertIn("No wildcards allowed for motion entry 'g1.20200402.00%'.", result.output)
72 self.assertEqual(records, self.recordCountLog('motionmasking'))
74 motion = 'g1.2020040%.001'
75 motionreason='http://motiontest.wpia.club/motion/xxx'
76 host= app.config.get("DEFAULT_HOST")
77 runner = app.test_cli_runner()
78 result = runner.invoke(motion_masking, (motion, motionreason, host))
79 assert result.exit_code == 0
80 self.assertIn("No wildcards allowed for motion entry 'g1.2020040%.001'.", result.output)
81 self.assertEqual(records, self.recordCountLog('motionmasking'))
83 motion = 'g1.20200402.00_'
84 motionreason='http://motiontest.wpia.club/motion/xxx'
85 host= app.config.get("DEFAULT_HOST")
86 runner = app.test_cli_runner()
87 result = runner.invoke(motion_masking, (motion, motionreason, host))
88 assert result.exit_code == 0
89 self.assertIn("No wildcards allowed for motion entry 'g1.20200402.00_'.", result.output)
90 self.assertEqual(records, self.recordCountLog('motionmasking'))
92 motion = 'g1.2020040_.001'
93 motionreason='http://motiontest.wpia.club/motion/xxx'
94 host= app.config.get("DEFAULT_HOST")
95 runner = app.test_cli_runner()
96 result = runner.invoke(motion_masking, (motion, motionreason, host))
97 assert result.exit_code == 0
98 self.assertIn("No wildcards allowed for motion entry 'g1.2020040_.001'.", result.output)
99 self.assertEqual(records, self.recordCountLog('motionmasking'))
101 motion = 'g1.2020040_.%'
102 motionreason='http://motiontest.wpia.club/motion/xxx'
103 host= app.config.get("DEFAULT_HOST")
104 runner = app.test_cli_runner()
105 result = runner.invoke(motion_masking, (motion, motionreason, host))
106 assert result.exit_code == 0
107 self.assertIn("No wildcards allowed for motion entry 'g1.2020040_.%'.", result.output)
108 self.assertEqual(records, self.recordCountLog('motionmasking'))
110 motion = 'g1.20200402.0\\1'
111 motionreason='http://motiontest.wpia.club/motion/xxx'
112 host= app.config.get("DEFAULT_HOST")
113 runner = app.test_cli_runner()
114 result = runner.invoke(motion_masking, (motion, motionreason, host))
115 assert result.exit_code == 0
116 self.assertIn("No wildcards allowed for motion entry 'g1.20200402.0\\1'.", result.output)
117 self.assertEqual(records, self.recordCountLog('motionmasking'))
119 motion = 'g1.2020040\.001'
120 motionreason='http://motiontest.wpia.club/motion/xxx'
121 host= app.config.get("DEFAULT_HOST")
122 runner = app.test_cli_runner()
123 result = runner.invoke(motion_masking, (motion, motionreason, host))
124 assert result.exit_code == 0
125 self.assertIn("No wildcards allowed for motion entry 'g1.2020040\\.001'.", result.output)
126 self.assertEqual(records, self.recordCountLog('motionmasking'))
128 # test masking single motion
129 sql = "SELECT id FROM motion WHERE content LIKE $1"
130 motion = 'g1.20200402.001'
131 motionreason='http://motiontest.wpia.club/motion/xxx'
132 runner = app.test_cli_runner()
133 result = runner.invoke(motion_masking, (motion, motionreason, host))
134 assert result.exit_code == 0
135 self.assertIn("1 record(s) affected by masking of 'g1.20200402.001'.", result.output)
136 self.assertIn("1 record(s) updated by masking of 'g1.20200402.001'.", result.output)
138 self.assertEqual(records, self.recordCountLog('motionmasking'))
139 self.logRecordDetailsTest('motionmasking', records-1, 0,
140 "1 motion(s) masked on base of motion http://motiontest.wpia.club/motion/xxx with motion identifier 'g1.20200402.001' on host 127.0.0.1:5000", 0)
141 self.assertEqual(1, self.recordCount(sql, '%' + motionreason +'%'))
143 # test masking muliple motions
144 motion = 'g1.20200402'
145 motionreason='http://motiontest.wpia.club/motion/1xxx'
146 runner = app.test_cli_runner()
147 result = runner.invoke(motion_masking, (motion, motionreason, host))
148 assert result.exit_code == 0
149 self.assertIn("4 record(s) affected by masking of 'g1.20200402'.", result.output)
150 self.assertIn("4 record(s) updated by masking of 'g1.20200402'.", result.output)
152 self.assertEqual(records, self.recordCountLog('motionmasking'))
153 self.logRecordDetailsTest('motionmasking', records-1, 0,
154 "4 motion(s) masked on base of motion http://motiontest.wpia.club/motion/1xxx with motion identifier 'g1.20200402' on host 127.0.0.1:5000", 0)
155 self.assertEqual(4, self.recordCount(sql, '%' + motionreason +'%'))
157 # test different host
158 motion = 'g1.20200402.001'
159 motionreason='http://motiontest.wpia.club/motion/xxx'
160 host= '127.0.0.1:5001'
161 runner = app.test_cli_runner()
162 result = runner.invoke(motion_masking, (motion, motionreason, host))
163 assert result.exit_code == 0
164 self.assertIn("0 record(s) affected by masking of 'g1.20200402.001'.", result.output)
165 self.assertEqual(records, self.recordCountLog('motionmasking'))