Browse Source

Added tests, fixed Makefile

master
Johann Schmitz 5 years ago
parent
commit
172b0b3f51
Signed by: ercpe GPG Key ID: A084064277C501ED
  1. 9
      .coveragerc
  2. 10
      Makefile
  3. 1
      src/djunin/tests/__init__.py
  4. 72
      src/djunin/tests/test_updater.py
  5. 50
      test_settings.py

9
.coveragerc

@ -0,0 +1,9 @@
[run]
branch = True
omit =
djunin/migrations/*
djunin/settings.py
djunin/wsgi.py
djunin/urls.py
manage.py

10
Makefile

@ -1,15 +1,15 @@
TARGET?=tests
test_default_python:
PYTHONPATH=".:./src" python -m pytest tests/ -v
cd src && PYTHONPATH="..:." DJANGO_SETTINGS_MODULE="test_settings" python manage.py test -v1
test_py2:
@echo Executing test with python2
PYTHONPATH=".:./src" python2 -m pytest tests/ -v
cd src && PYTHONPATH="..:." DJANGO_SETTINGS_MODULE="test_settings" python2 manage.py test
test_py3:
@echo Executing test with python3
PYTHONPATH=".:./src" python3 -m pytest tests/ -v
cd src && PYTHONPATH="..:." DJANGO_SETTINGS_MODULE="test_settings" python3 manage.py test -v1
test: test_py2 test_py3
@ -23,7 +23,7 @@ compile_optimized:
coverage:
coverage erase
PYTHONPATH=".:./src" coverage run --source='src' --branch -m py.test -qq tests/
coverage report -m
cd src && PYTHONPATH="..:." DJANGO_SETTINGS_MODULE="test_settings" coverage run --source='.' --rcfile ../.coveragerc manage.py test
cd src && coverage report -m
travis: compile compile_optimized test_default_python coverage

1
src/djunin/tests/__init__.py

@ -0,0 +1 @@
# -*- coding: utf-8 -*-

72
src/djunin/tests/test_updater.py

@ -0,0 +1,72 @@
# -*- coding: utf-8 -*-
from StringIO import StringIO
from django.test import TestCase
from djunin.models import Node, Graph, DataRow
from djunin.updater import Updater, Row
class UpdaterTestCase(TestCase):
maxDiff = None
def test_root_graph_parsing(self):
updater = Updater()
fp = StringIO('\n'.join([
'version 0',
'group;node:threads.graph_title Number of threads',
'group;node:threads.graph_vlabel number of threads',
'group;node:threads.graph_category processes',
'group;node:threads.threads.graph_data_size normal',
'group;node:threads.threads.label threads',
]))
data = list(updater.prepare(fp))
self.assertListEqual(sorted(data), sorted([
Row('group', 'node', 'threads', None, None, 'graph_title', 'Number of threads'),
Row('group', 'node', 'threads', None, None, 'graph_vlabel', 'number of threads'),
Row('group', 'node', 'threads', None, None, 'graph_category', 'processes'),
Row('group', 'node', 'threads', None, 'threads', 'graph_data_size', 'normal'),
Row('group', 'node', 'threads', None, 'threads', 'label', 'threads'),
]))
def test_subgraph_parsing(self):
updater = Updater()
fp = StringIO('\n'.join([
'version 0',
'group;node:diskstats_iops.graph_title Disk IOs per device',
'group;node:diskstats_iops.graph_category disk',
'group;node:diskstats_iops.xvda2.graph_title IOs for /dev/xvda2',
'group;node:diskstats_iops.xvda2.avgwrrqsz.draw LINE1',
'group;node:diskstats_iops.xvda2.avgwrrqsz.graph_data_size normal',
]))
data = list(updater.prepare(fp))
self.assertListEqual(sorted(data), sorted([
Row('group', 'node', 'diskstats_iops', None, None, 'graph_title', 'Disk IOs per device'),
Row('group', 'node', 'diskstats_iops', None, None, 'graph_category', 'disk'),
Row('group', 'node', 'diskstats_iops', 'xvda2', None, 'graph_title', 'IOs for /dev/xvda2'),
Row('group', 'node', 'diskstats_iops', 'xvda2', 'avgwrrqsz', 'draw', 'LINE1'),
Row('group', 'node', 'diskstats_iops', 'xvda2', 'avgwrrqsz', 'graph_data_size', 'normal'),
]))
def test_parse_graph_args_empty(self):
updater = Updater()
d = updater.parse_graph_args(None)
self.assertEqual(d, {})
d = updater.parse_graph_args('')
self.assertEqual(d, {})
def test_parse_graph_args(self):
updater = Updater()
d = updater.parse_graph_args('--base 1000 -r --lower-limit 0 --upper-limit 400')
self.assertEqual(d, {
'graph_args_base': '1000',
'graph_args_lower_limit': '0',
'graph_args_upper_limit': '400',
})

50
test_settings.py

@ -0,0 +1,50 @@
# -*- coding: utf-8 -*-
from djunin.settings import *
import logging
SECRET_KEY = 'TEST-SECRET-KEY'
DEBUG = True
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': 'djunin',
}
}
logging.basicConfig(
level=logging.ERROR,
format='%(asctime)s %(levelname)-7s %(message)s',
)
LOGGING = {
'version': 1,
'disable_existing_loggers': False,
'filters': {
'require_debug_false': {
'()': 'django.utils.log.RequireDebugFalse'
}
},
'handlers': {
'mail_admins': {
'level': 'ERROR',
'filters': ['require_debug_false'],
'class': 'django.utils.log.AdminEmailHandler'
}
},
'loggers': {
'django.request': {
'handlers': ['mail_admins'],
'level': 'ERROR',
'propagate': True,
},
'django.db.backends': {
'propagate': False,
},
}
}
MUNIN_DATA_DIR = ''