Total Complexity | 8 |
Total Lines | 34 |
Duplicated Lines | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | # Something that is untested is broken. |
||
11 | class TestsThatNeedsRules(unittest.TestCase): |
||
12 | """ A simple calss that create a rule before running tests, and destroy destroy it when the tests are over. """ |
||
13 | def setUp(self): |
||
14 | app = create_app() |
||
15 | db.init_app(app) |
||
16 | app.config['TESTING'] = True |
||
17 | self.app = app.test_client() |
||
18 | self.created_rules = list() |
||
19 | self.__create_rule() |
||
20 | |||
21 | def tearDown(self): |
||
22 | self.__delete_rule() |
||
23 | |||
24 | def __create_rule(self): |
||
25 | """ |
||
26 | |||
27 | :return int: The id of the new rule |
||
28 | """ |
||
29 | current_sid = NaxsiRules.query.order_by(NaxsiRules.sid.desc()).first() |
||
30 | current_sid = 1337 if current_sid is None else current_sid.sid + 1 |
||
31 | |||
32 | db.session.add(NaxsiRules(u'POUET', 'str:test', u'BODY', u'$SQL:8', current_sid, u'WEB_APPS', |
||
33 | u'f hqewifueiwf hueiwhf uiewh fiewh fhw', '1', True, 1457101045)) |
||
34 | db.session.commit() |
||
35 | self.created_rules.append(current_sid) |
||
36 | return int(current_sid) |
||
37 | |||
38 | def __delete_rule(self, sid=None): |
||
39 | if sid: |
||
40 | db.session.delete(NaxsiRules.query.filter(sid == NaxsiRules.sid).first()) |
||
41 | for sid in self.created_rules: |
||
42 | _rule = NaxsiRules.query.filter(sid == NaxsiRules.sid).first() |
||
43 | if _rule: |
||
44 | db.session.delete(_rule) |
||
45 |