BW3-Core/test/test_descriptor.py

71 lines
2.5 KiB
Python
Raw Normal View History

2018-01-07 21:51:43 +01:00
#!/usr/bin/python
# -*- coding: utf-8 -*-
2018-01-07 21:52:53 +01:00
"""!
2018-01-07 21:51:43 +01:00
____ ____ ______ __ __ __ _____
/ __ )/ __ \/ ___/ | / /___ _/ /______/ /_ |__ /
/ __ / / / /\__ \| | /| / / __ `/ __/ ___/ __ \ /_ <
/ /_/ / /_/ /___/ /| |/ |/ / /_/ / /_/ /__/ / / / ___/ /
/_____/\____//____/ |__/|__/\__,_/\__/\___/_/ /_/ /____/
German BOS Information Script
by Bastian Schroll
@file: test_descriptor.py
@date: 07.01.2017
@author: Bastian Schroll
2018-01-08 23:41:33 +01:00
@description: Unittests for BOSWatch. File must be _run as "pytest" unittest
2018-01-07 21:51:43 +01:00
"""
2018-01-12 07:48:27 +01:00
import logging
2018-01-07 21:51:43 +01:00
2018-01-11 12:59:53 +01:00
from boswatch.descriptor.descriptor import Descriptor
from boswatch.descriptor.descriptor import DescriptionList
from boswatch.packet.packet import Packet
2018-01-07 21:51:43 +01:00
class Test_Descriptor:
2018-01-07 23:02:04 +01:00
"""!Unittests for the descriptor"""
2018-01-07 21:51:43 +01:00
2018-01-12 07:48:27 +01:00
def setup_method(self, method):
2018-09-18 06:05:24 +02:00
logging.debug("[TEST] %s.%s", type(self).__name__, method.__name__)
2018-01-12 07:48:27 +01:00
2018-01-11 12:59:53 +01:00
def test_loadCsvNotExist(self):
2018-01-07 23:32:09 +01:00
"""!read CSV file where not exist direct per DescriptionList class"""
2018-01-11 12:59:53 +01:00
descList = DescriptionList()
2018-01-10 13:06:18 +01:00
assert not descList.loadCSV("boswatch")
2018-01-07 21:51:43 +01:00
2018-01-11 12:59:53 +01:00
def test_loadCsv(self):
2018-01-07 23:32:09 +01:00
"""!read CSV file direct per DescriptionList class"""
2018-01-11 12:59:53 +01:00
descList = DescriptionList()
2018-01-10 13:06:18 +01:00
assert descList.loadCSV("zvei")
2018-01-07 23:32:09 +01:00
def test_descriptorLoadFailed(self):
"""!read CSV file where not exist"""
2018-01-11 12:59:53 +01:00
bwDescriptor = Descriptor()
2018-01-10 13:06:18 +01:00
assert not bwDescriptor.loadDescription("boswatch")
2018-01-07 23:32:09 +01:00
def test_descriptorLoad(self):
2018-01-07 21:51:43 +01:00
"""!read CSV file"""
2018-01-11 12:59:53 +01:00
bwDescriptor = Descriptor()
2018-01-10 13:06:18 +01:00
assert bwDescriptor.loadDescription("zvei")
2018-01-07 23:32:09 +01:00
def test_loadDescriptionsNotSet(self):
"""!load descriptions where not set to an bwPacket"""
2018-01-11 12:59:53 +01:00
bwDescriptor = Descriptor()
2018-01-10 13:06:18 +01:00
assert bwDescriptor.loadDescription("zvei")
2018-01-11 12:59:53 +01:00
bwPacket = Packet()
2018-01-09 11:33:23 +01:00
bwPacket.set("mode", "zvei")
bwPacket.set("zvei", "54321")
2018-01-10 13:06:18 +01:00
assert bwDescriptor.addDescriptions(bwPacket)
2018-01-09 11:33:23 +01:00
assert bwPacket.get("shortDescription") is ""
assert bwPacket.get("longDescription") is ""
2018-01-07 23:32:09 +01:00
def test_loadDescriptions(self):
"""!load descriptions to an bwPacket"""
2018-01-11 12:59:53 +01:00
bwDescriptor = Descriptor()
2018-01-10 13:06:18 +01:00
assert bwDescriptor.loadDescription("zvei")
2018-01-11 12:59:53 +01:00
bwPacket = Packet()
2018-01-09 11:33:23 +01:00
bwPacket.set("mode", "zvei")
bwPacket.set("zvei", "12345")
2018-01-10 13:06:18 +01:00
assert bwDescriptor.addDescriptions(bwPacket)
2018-01-09 11:33:23 +01:00
assert bwPacket.get("shortDescription") is not ""
assert bwPacket.get("longDescription") is not ""