Ejemplo n.º 1
0
 def test_comment_required_only_for_other_response(self):
     yes_answer = Answer(
         text="Text",
         severity=Severity.red(),
         response=Response.yes(),
     )
     no_answer = Answer(
         text="Text",
         severity=Severity.yellow(),
         response=Response.no(),
     )
     other_answer_without_comment = Answer(
         text="Text",
         severity=Severity.green(),
         response=Response.other(),
     )
     other_answer_with_comment = Answer(text="Text",
                                        severity=Severity.yellow(),
                                        response=Response.other(),
                                        comment="Comments")
     self.assertEqual(None, yes_answer.validate())
     self.assertEqual(None, no_answer.validate())
     self.assertEqual(None, other_answer_with_comment.validate())
     self.assertRaises(ValidationError,
                       other_answer_without_comment.validate)
Ejemplo n.º 2
0
    def submit_audit(self):
        completed_audit = CompletedAuditBuilder()
        completed_audit.with_title(self.audit_title)

        # The object returned from the .kv is a TextField, with a member text
        completed_audit.with_auditor(self.auditor_name.text)
        completed_audit.with_datetime(datetime.utcnow())

        for a in self.questions:
            if a.other_comments.text:
                temp_answer = Answer(text=a.question.text,
                                     severity=self.get_question_severity(a),
                                     response=a.response,
                                     comment=a.other_comments.text)
            else:
                temp_answer = Answer(text=a.question.text,
                                     severity=self.get_question_severity(a),
                                     response=a.response)
            completed_audit.with_answer(temp_answer)

        # Save audit
        completed_audit.build().save()

        # Update audit locked status
        AuditTemplate.objects().filter(title=self.audit_title).update(
            upsert=False, multi=True, locked=True)
Ejemplo n.º 3
0
 def test_text_is_required(self):
     self.assertEqual(
         None,
         Answer(
             text="With Text",
             severity=Severity.red(),
             response=Response.yes(),
         ).validate())
     self.assertRaises(
         ValidationError,
         Answer(
             severity=Severity.red(),
             response=Response.yes(),
         ).validate)
Ejemplo n.º 4
0
    def submit_audit(self, callback):
        completed_audit = CompletedAuditBuilder()
        completed_audit.with_title(self.audit_title)
        # The object returned from the .kv is a TextField, with a member text
        completed_audit.with_auditor(self.auditor_name.text)
        for a in self.questions:
            if a.other_comments.text:
                temp_answer = Answer(text=a.question.text,
                                     severity=self.question_severity(a),
                                     response=a.response,
                                     comment=a.other_comments.text)
            else:
                temp_answer = Answer(text=a.question.text,
                                     severity=self.question_severity(a),
                                     response=a.response)
            completed_audit.with_answer(temp_answer)

        completed_audit.build().save()
Ejemplo n.º 5
0
 def test_text_min_length(self):
     character_minimum = ""
     for _ in range(0, TEXT_MIN_LENGTH):
         character_minimum += "a"
     too_few_characters = character_minimum[1:]
     self.assertEqual(
         None,
         Answer(
             text=character_minimum,
             severity=Severity.red(),
             response=Response.yes(),
         ).validate())
     self.assertRaises(
         ValidationError,
         Answer(
             text=too_few_characters,
             severity=Severity.red(),
             response=Response.yes(),
         ).validate)
Ejemplo n.º 6
0
 def test_comment_min_length(self):
     character_minimum = ""
     for _ in range(0, COMMENT_MIN_LENGTH):
         character_minimum += "a"
     too_few_characters = character_minimum[1:]
     self.assertEqual(
         None,
         Answer(
             text="With Text",
             severity=Severity.red(),
             response=Response.other(),
             comment=character_minimum,
         ).validate())
     self.assertRaises(
         ValidationError,
         Answer(
             text="With Text",
             severity=Severity.red(),
             response=Response.other(),
             comment=too_few_characters,
         ).validate)
Ejemplo n.º 7
0
def get_random_answer_for(question):
    response = choice(RESPONSES)
    if Response.yes() == response:
        return Answer(
            text=question.text,
            severity=question.yes,
            response=response,
        )
    elif Response.no() == response:
        return Answer(
            text=question.text,
            severity=question.no,
            response=response,
        )
    elif Response.other() == response:
        return Answer(
            text=question.text,
            severity=question.yes,
            response=response,
            comment=choice(COMMENTS),
        )
Ejemplo n.º 8
0
    def test_answer_construction(self):
        expected_text = "Expected Text"
        expected_severity = Severity.red()
        expected_response = Response.yes()
        expected_comment = "Expected Comments"
        expected_resolved = True

        answer = Answer(
            text=expected_text,
            severity=expected_severity,
            response=expected_response,
            comment=expected_comment,
        )

        self.assertEqual(expected_text, answer.text)
        self.assertEqual(expected_severity, answer.severity)
        self.assertEqual(expected_response, answer.response)
        self.assertEqual(expected_comment, answer.comment)
        self.assertEqual(expected_resolved, answer.resolved)
import unittest
from datetime import datetime

from mongoengine import ValidationError

from cilantro_audit.audit_template import Severity
from cilantro_audit.completed_audit import CompletedAudit, Answer, Response
from cilantro_audit.constants import TITLE_MAX_LENGTH, TITLE_MIN_LENGTH

VALID_ANSWER = Answer(
    text="Text",
    severity=Severity.red(),
    resolved=False,
    response=Response.yes(),
)

OTHER_NO_COMMENT_ANSWER = Answer(
    text="Text",
    severity=Severity.red(),
    resolved=False,
    response=Response.other(),
)


class CompletedAuditTests(unittest.TestCase):
    def test_title_is_required(self):
        self.assertEqual(
            None,
            CompletedAudit(
                title="Title",
                datetime=datetime.now(),
Ejemplo n.º 10
0
    def test_storage_and_retrieval(self):
        title = "Boiler Room Shenanigans"
        auditor = "Erik The Auditor"

        a0_text = "Did you stick your head in the boiler?"
        a0_severity = Severity.red()
        a0_response = Response.yes()

        a1_text = "Was there dust on the machine?"
        a1_severity = Severity.yellow()
        a1_response = Response.no()

        a2_text = "Did you clean the machine?"
        a2_severity = Severity.green()
        a2_response = Response.other()
        a2_comment = "There was no dust on the machine to clean."

        CompletedAuditBuilder() \
            .with_title(title) \
            .with_auditor(auditor) \
            .with_answer(
            Answer(
                text=a0_text,
                severity=a0_severity,
                response=a0_response,
            )
        ).with_answer(
            Answer(
                text=a1_text,
                severity=a1_severity,
                response=a1_response,
            )
        ).with_answer(
            Answer(
                text=a2_text,
                severity=a2_severity,
                response=a2_response,
                comment=a2_comment,
            )
        ).build().save()

        audits = CompletedAudit.objects(title=title)

        self.assertEqual(title, audits[0].title)
        self.assertEqual(1, len(audits))
        self.assertEqual(3, len(audits[0].answers))

        audit = audits[0]

        a0_text = "Did you stick your head in the boiler?"
        a0_severity = Severity.red()
        a0_response = Response.yes()

        a1_text = "Was there dust on the machine?"
        a1_severity = Severity.yellow()
        a1_response = Response.no()

        a2_text = "Did you clean the machine?"
        a2_severity = Severity.green()
        a2_response = Response.other()
        a2_comment = "There was no dust on the machine to clean."

        self.assertEqual(a0_text, audit.answers[0].text)
        self.assertEqual(a0_severity, audit.answers[0].severity)
        self.assertEqual(a0_response, audit.answers[0].response)
        self.assertEqual(None, audit.answers[0].comment)

        self.assertEqual(a1_text, audit.answers[1].text)
        self.assertEqual(a1_severity, audit.answers[1].severity)
        self.assertEqual(a1_response, audit.answers[1].response)
        self.assertEqual(None, audit.answers[1].comment)

        self.assertEqual(a2_text, audit.answers[2].text)
        self.assertEqual(a2_severity, audit.answers[2].severity)
        self.assertEqual(a2_response, audit.answers[2].response)
        self.assertEqual(a2_comment, audit.answers[2].comment)

        self.assertGreaterEqual(datetime.utcnow(), audit.datetime)
Ejemplo n.º 11
0
import unittest
from datetime import datetime

from mongoengine import ValidationError

from cilantro_audit.audit_template import Severity
from cilantro_audit.completed_audit import CompletedAuditBuilder, Answer, Response

VALID_ANSWER = Answer(
    text="Text",
    severity=Severity.red(),
    response=Response.yes(),
)

GREEN_ANSWER = Answer(
    text="Green Answer",
    severity=Severity.green(),
    response=Response.yes(),
)

YELLOW_ANSWER = Answer(
    text="Yellow Answer",
    severity=Severity.yellow(),
    response=Response.other(),
    comment="Toast",
)

RED_ANSWER = Answer(
    text="Red Answer",
    severity=Severity.red(),
    response=Response.no(),