from scoring_engine.engine.engine import Engine
from scoring_engine.models.service import Service
from scoring_engine.models.environment import Environment
from scoring_engine.models.property import Property
from scoring_engine.models.account import Account

import pytest

from tests.scoring_engine.unit_test import UnitTest


class CheckTest(UnitTest):

    def setup(self):
        super(CheckTest, self).setup()
        self.engine = Engine()
        self.service = Service(name='Example Service', check_name=self.check_name, ip_address='127.0.0.1', port=100)
        self.environment = Environment(service=self.service, matching_regex='*')
        if not hasattr(self, 'properties'):
            self.properties = {}
        if not hasattr(self, 'accounts'):
            self.accounts = {}
        for property_name, property_value in self.properties.items():
            self.session.add(Property(environment=self.environment, name=property_name, value=property_value))
        for account_name, account_pass in self.accounts.items():
            self.session.add(Account(username=account_name, password=account_pass, service=self.service))
        self.session.add(self.service)
        self.session.add(self.environment)
        self.session.commit()

    def test_bad_properties(self):
        environment = Environment(service=self.service, matching_regex='*')
        self.session.add(environment)
        self.session.commit()
        self.service.environments = [environment]
        temp_properties = dict(self.properties)
        if len(temp_properties) > 0:
            temp_properties.popitem()
        else:
            temp_properties['exampleproperty'] = 'propertyvalueexample'
        for property_name, property_value in temp_properties.items():
            property_obj = Property(environment=environment, name=property_name, value=property_value)
            self.session.add(property_obj)
            self.session.commit()
        with pytest.raises(LookupError):
            self.engine.check_name_to_obj(self.check_name)(environment)

    def test_cmd(self):
        check_obj = self.engine.check_name_to_obj(self.check_name)(self.environment)
        assert check_obj.command() == self.cmd

from scoring_engine.engine.engine import Engine
from scoring_engine.models.service import Service
from scoring_engine.models.environment import Environment
from scoring_engine.models.property import Property
from scoring_engine.models.account import Account

from tests.scoring_engine.unit_test import UnitTest


class CheckTest(UnitTest):

    def test_cmd(self):
        engine = Engine()
        service = Service(name='Example Service', check_name=self.check_name, ip_address='127.0.0.1', port=100)
        environment = Environment(service=service, matching_regex='*')
        if not hasattr(self, 'properties'):
            self.properties = {}
        if not hasattr(self, 'accounts'):
            self.accounts = {}
        for property_name, property_value in self.properties.items():
            self.session.add(Property(environment=environment, name=property_name, value=property_value))
        for account_name, account_pass in self.accounts.items():
            self.session.add(Account(username=account_name, password=account_pass, service=service))
        self.session.add(service)
        self.session.add(environment)
        self.session.commit()

        check_obj = engine.check_name_to_obj(self.check_name)(environment)
        assert check_obj.command() == self.cmd

Remove troublesome useless test