TestsThatNeedsRules   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 34
rs 10
wmc 8

4 Methods

Rating   Name   Duplication   Size   Complexity  
A tearDown() 0 2 1
A __create_rule() 0 13 2
A setUp() 0 7 1
A __delete_rule() 0 7 4
1
# Something that is untested is broken.
2
3
import unittest
4
5
from spike.model.naxsi_rules import NaxsiRules
6
from spike.model import db
7
8
from spike import create_app
9
10
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