Test Setup Failed
Push — master ( ad6234...17e8fd )
by -
01:11
created

FlaskrTestCase   A

Complexity

Total Complexity 18

Size/Duplication

Total Lines 51
Duplicated Lines 0 %
Metric Value
dl 0
loc 51
rs 10
wmc 18

6 Methods

Rating   Name   Duplication   Size   Complexity  
A test_robotstxt() 0 2 2
A test_del_rule() 0 11 3
A setUp() 0 4 1
A tearDown() 0 2 1
A test_redirect_root() 0 4 3
C test_add_rule() 0 21 8
1
try:
0 ignored issues
show
Coding Style introduced by
This module should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
2
    from urlparse import urlparse
3
except ImportError:  # python3
4
    from urllib.parse import urlparse
5
6
import re
0 ignored issues
show
Unused Code introduced by
The import re seems to be unused.
Loading history...
7
8
from spike import create_app
9
from spike.model import db
0 ignored issues
show
Unused Code introduced by
Unused db imported from spike.model
Loading history...
10
from spike.model.naxsi_rules import ValueTemplates, NaxsiRules, NaxsiRuleSets
0 ignored issues
show
Unused Code introduced by
Unused ValueTemplates imported from spike.model.naxsi_rules
Loading history...
Unused Code introduced by
Unused NaxsiRuleSets imported from spike.model.naxsi_rules
Loading history...
11
import unittest
12
13
14
class FlaskrTestCase(unittest.TestCase):
0 ignored issues
show
Coding Style introduced by
This class should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
15
16
    def setUp(self):
17
        app = create_app()
18
        app.config['TESTING'] = True
19
        self.app = app.test_client()
20
21
    def tearDown(self):
22
        pass
23
24
    def test_robotstxt(self):
0 ignored issues
show
Coding Style introduced by
This method should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
25
        assert self.app.get('/robots.txt').data == 'User-agent: *\n Disallow: /'
26
27
    def test_redirect_root(self):
0 ignored issues
show
Coding Style introduced by
This method should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
28
        rv = self.app.get('/', follow_redirects=False)
0 ignored issues
show
Coding Style Naming introduced by
The name rv does not conform to the variable naming conventions ([a-z_][a-z0-9_]{2,30}$).

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
29
        assert rv.status_code == 302
30
        assert urlparse(rv.location).path == '/rules'
31
32
    def test_add_rule(self):
0 ignored issues
show
Coding Style introduced by
This method should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
33
        data = {
34
            'msg': 'this is a test message',
35
            'detection': 'DETECTION',
36
            'mz': 'BODY',
37
            'custom_mz_val': '',
38
            'negative': 'checked',
39
            'score_$SQL': 8,
40
            'score': '$SQL',
41
            'rmks': 'this is a test remark',
42
            'ruleset': 'scanner.rules'
43
        }
44
        rv = self.app.post('/rules/new', data=data, follow_redirects=True)
0 ignored issues
show
Coding Style Naming introduced by
The name rv does not conform to the variable naming conventions ([a-z_][a-z0-9_]{2,30}$).

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
45
        rule = NaxsiRules.query.order_by(NaxsiRules.sid.desc()).first()
0 ignored issues
show
Bug introduced by
The Class NaxsiRules does not seem to have a member named query.

This check looks for calls to members that are non-existent. These calls will fail.

The member could have been renamed or removed.

Loading history...
46
        assert ('<li> - OK: created %d : %s</li>' % (rule.sid, rule.msg)) in rv.data
0 ignored issues
show
Unused Code Coding Style introduced by
There is an unnecessary parenthesis after assert.
Loading history...
47
        assert rule.msg == data['msg']
48
        assert rule.detection == 'str:' + data['detection']
49
        assert rule.mz == data['mz']
50
        assert rule.score == data['score'] + ':' + str(data['score_$SQL'])
51
        assert rule.rmks == data['rmks']
52
        assert rule.ruleset == data['ruleset']
53
54
    def test_del_rule(self):
0 ignored issues
show
Coding Style introduced by
This method should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
55
        current_sid = NaxsiRules.query.order_by(NaxsiRules.sid.desc()).first().sid
0 ignored issues
show
Bug introduced by
The Class NaxsiRules does not seem to have a member named query.

This check looks for calls to members that are non-existent. These calls will fail.

The member could have been renamed or removed.

Loading history...
56
        self.test_add_rule()
57
58
        sid = NaxsiRules.query.order_by(NaxsiRules.sid.desc()).first().sid
0 ignored issues
show
Bug introduced by
The Class NaxsiRules does not seem to have a member named query.

This check looks for calls to members that are non-existent. These calls will fail.

The member could have been renamed or removed.

Loading history...
59
        rv = self.app.get('/rules/del/%d' % sid)
0 ignored issues
show
Coding Style Naming introduced by
The name rv does not conform to the variable naming conventions ([a-z_][a-z0-9_]{2,30}$).

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
60
        assert rv.status_code == 302
61
62
        rule = NaxsiRules.query.order_by(NaxsiRules.sid.desc()).first()
0 ignored issues
show
Bug introduced by
The Class NaxsiRules does not seem to have a member named query.

This check looks for calls to members that are non-existent. These calls will fail.

The member could have been renamed or removed.

Loading history...
63
64
        assert rule.sid == current_sid
65
66
67
68
if __name__ == '__main__':
69
    unittest.main()
0 ignored issues
show
Coding Style introduced by
Final newline missing
Loading history...