def test_unresolved_count_matches_unresolved_answers(self): self.assertEqual( None, CompletedAudit( title="Title", datetime=datetime.now(), auditor="Auditor", severity=Severity.green(), unresolved_count=4, answers=[ VALID_ANSWER, VALID_ANSWER, VALID_ANSWER, VALID_ANSWER, ], ).validate()) self.assertRaises( ValidationError, CompletedAudit( title="Title", datetime=datetime.now(), auditor="Auditor", severity=Severity.green(), answers=[ VALID_ANSWER, VALID_ANSWER, VALID_ANSWER, VALID_ANSWER, ], ).validate)
def test_title_min_length(self): character_minimum = "" for _ in range(0, TITLE_MIN_LENGTH): character_minimum += "a" too_few_characters = character_minimum[1:] self.assertEqual( None, CompletedAudit( title=character_minimum, datetime=datetime.now(), auditor="Auditor", severity=Severity.green(), unresolved_count=1, answers=[VALID_ANSWER], ).validate()) self.assertRaises( ValidationError, CompletedAudit( title=too_few_characters, datetime=datetime.now(), auditor="Auditor", severity=Severity.green(), unresolved_count=1, answers=[VALID_ANSWER], ).validate)
def get_severity_color(severity): if severity == Severity.red(): return RGB_RED if severity == Severity.yellow(): return RGB_YELLOW if severity == Severity.green(): return RGB_GREEN
def test_each_answer_is_validated(self): self.assertEqual( None, CompletedAudit( title="Title", datetime=datetime.now(), auditor="Auditor", severity=Severity.green(), unresolved_count=4, answers=[ VALID_ANSWER, VALID_ANSWER, VALID_ANSWER, VALID_ANSWER, ], ).validate()) self.assertRaises( ValidationError, CompletedAudit( title="Title", datetime=datetime.now(), auditor="Auditor", severity=Severity.green(), unresolved_count=4, answers=[ VALID_ANSWER, VALID_ANSWER, OTHER_NO_COMMENT_ANSWER, VALID_ANSWER, ], ).validate)
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)
def test_max_severity_yellow(self): audit = CompletedAuditBuilder() \ .with_title("Title") \ .with_auditor("Auditor") \ .with_answer(GREEN_ANSWER) \ .with_answer(RED_ANSWER) \ .with_answer(GREEN_ANSWER) \ .with_answer(YELLOW_ANSWER) \ .with_answer(GREEN_ANSWER) \ .build() self.assertEqual(Severity.red(), audit.severity) audit = CompletedAuditBuilder() \ .with_title("Title") \ .with_auditor("Auditor") \ .with_answer(GREEN_ANSWER) \ .with_answer(YELLOW_ANSWER) \ .with_answer(GREEN_ANSWER) \ .with_answer(RED_ANSWER) \ .with_answer(GREEN_ANSWER) \ .build() self.assertEqual(Severity.red(), audit.severity) audit = CompletedAuditBuilder() \ .with_title("Title") \ .with_auditor("Auditor") \ .with_answer(GREEN_ANSWER) \ .with_answer(GREEN_ANSWER) \ .with_answer(RED_ANSWER) \ .with_answer(GREEN_ANSWER) \ .build() self.assertEqual(Severity.red(), audit.severity)
def other_btn_press(self): self.other_severity = Severity.next(self.other_severity) if self.other_severity == Severity.green(): self.other_button.background_color = RGB_GREEN elif self.other_severity == Severity.yellow(): self.other_button.background_color = RGB_YELLOW elif self.other_severity == Severity.red(): self.other_button.background_color = RGB_RED
def with_answer(self, answer): if answer.severity == Severity.red(): self.max_severity = Severity.red() answer.resolved = False self.unresolved_count += 1 elif self.max_severity == Severity.green() and answer.severity == Severity.yellow(): self.max_severity = Severity.yellow() self.answers.append(answer) return self
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)
def __init__(self): self.title = None self.auditor = None self.datetime = None self.max_severity = Severity.green() self.answers = [] self.unresolved_count = 0
def show_audit_list(self, instance): show = AuditListPop() show.title = "Related completed audits for the question: " + instance.text + " from " + instance.audit_title audit_list = list( CompletedAudit.objects(title=instance.audit_title, severity=Severity.red())) self.populate_audit_list_pop(audit_list, show, instance.text, show) show.open()
class QuestionModule(FloatLayout): ##variables with Object properties so that we can "see" whats going on in kv file question_text = ObjectProperty(None) delete_question = ObjectProperty(None) yes_button = ObjectProperty(None) no_button = ObjectProperty(None) yes_severity = Severity.default() no_severity = Severity.default() other_severity = Severity.default() q_id = 0 ##do stuff when the yes button is pressed def yes_btn_press(self): self.yes_severity = self.yes_severity.next() if self.yes_severity == Severity.green(): self.yes_button.background_color = RGB_GREEN elif self.yes_severity == Severity.yellow(): self.yes_button.background_color = RGB_YELLOW elif self.yes_severity == Severity.red(): self.yes_button.background_color = RGB_RED ##do stuff when the no button is pressed def no_btn_press(self): self.no_severity = Severity.next(self.no_severity) if self.no_severity == Severity.green(): self.no_button.background_color = RGB_GREEN elif self.no_severity == Severity.yellow(): self.no_button.background_color = RGB_YELLOW elif self.no_severity == Severity.red(): self.no_button.background_color = RGB_RED ##do stuff when the other button is pressed def other_btn_press(self): self.other_severity = Severity.next(self.other_severity) if self.other_severity == Severity.green(): self.other_button.background_color = RGB_GREEN elif self.other_severity == Severity.yellow(): self.other_button.background_color = RGB_YELLOW elif self.other_severity == Severity.red(): self.other_button.background_color = RGB_RED
def test_max_severity_green(self): audit = CompletedAuditBuilder() \ .with_title("Title") \ .with_auditor("Auditor") \ .with_answer(GREEN_ANSWER) \ .with_answer(GREEN_ANSWER) \ .with_answer(GREEN_ANSWER) \ .build() self.assertEqual(Severity.green(), audit.severity)
def test_answers_are_required(self): self.assertEqual( None, CompletedAudit( title="Title", datetime=datetime.now(), auditor="Auditor", severity=Severity.green(), unresolved_count=1, answers=[VALID_ANSWER], ).validate()) self.assertRaises( ValidationError, CompletedAudit( title="Title", datetime=datetime.now(), auditor="Auditor", severity=Severity.green(), ).validate)
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)
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)
def retrieve_flagged_answers(self): self.unique_entry_rows = [] completed_audits = list( CompletedAudit.objects(severity=Severity.red())) # Go over each flagged answer and append them to a local 3d-array while counting the number of repeated flags for audit in completed_audits: for answer in audit.answers: if answer.severity == Severity.red(): is_unique_row = True for entry_row in self.unique_entry_rows: if entry_row[0] == audit.title and entry_row[ 1] == answer.text: entry_row[2] += 1 is_unique_row = False break if is_unique_row: self.unique_entry_rows.append( [audit.title, answer.text, 1]) # Default Sort self.sort_by_times_flagged()
def test_custom_severities(self): question = Question( text="Question Text", yes=Severity.red(), no=Severity.yellow(), other=Severity.green(), ) self.assertEqual(Severity.red(), question.yes) self.assertEqual(Severity.yellow(), question.no) self.assertEqual(Severity.green(), question.other)
def populate_audit_list_pop(self, al, pop, ans, show): for audit in al: for answer in audit.answers: if ans == answer.text and answer.severity == Severity.red(): pop.name_col.add_widget( CilantroLabel(text=audit.auditor, size_hint_y=None)) temp = CilantroButton(id=str(audit.datetime), text=format_datetime( utc_to_local(audit.datetime)), size_hint_y=None, on_press=show.dismiss) temp.bind(on_press=self.load_completed_audit) pop.date_col.add_widget(temp) pop.unresolved_col.add_widget( CilantroLabel(text=str(audit.unresolved_count), size_hint_y=None))
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)
def test_storage_and_retrieval(self): title = "Test Storage And Retrieval" q0_text = "Question 0" q1_text = "Question 1" q2_text = "Question 2" question0 = Question(text=q0_text) question1 = Question(text=q1_text, yes=Severity.red()) question2 = Question(text=q2_text, no=Severity.red(), other=Severity.yellow()) AuditTemplateBuilder() \ .with_title(title) \ .with_question(question0) \ .with_question(question1) \ .with_question(question2) \ .build() \ .save() templates = AuditTemplate.objects(title=title) self.assertEqual(title, templates[0].title) self.assertEqual(1, len(templates)) self.assertEqual(3, len(templates[0].questions)) template = templates[0] self.assertEqual(q0_text, template.questions[0].text) self.assertEqual(Severity.green(), template.questions[0].yes) self.assertEqual(Severity.green(), template.questions[0].no) self.assertEqual(Severity.green(), template.questions[0].other) self.assertEqual(q1_text, template.questions[1].text) self.assertEqual(Severity.red(), template.questions[1].yes) self.assertEqual(Severity.green(), template.questions[1].no) self.assertEqual(Severity.green(), template.questions[1].other) self.assertEqual(q2_text, template.questions[2].text) self.assertEqual(Severity.green(), template.questions[2].yes) self.assertEqual(Severity.red(), template.questions[2].no) self.assertEqual(Severity.yellow(), template.questions[2].other)
def test_default_severities(self): question = Question(text="Question Text") self.assertEqual(Severity.green(), question.yes) self.assertEqual(Severity.green(), question.no) self.assertEqual(Severity.green(), question.other)
def test_severity_constructors(self): self.assertEqual(SeverityEnum.RED, Severity.red().severity) self.assertEqual(SeverityEnum.YELLOW, Severity.yellow().severity) self.assertEqual(SeverityEnum.GREEN, Severity.green().severity)
def test_severity_is_required(self): self.assertEqual(None, Severity.default().validate()) self.assertRaises(ValidationError, Severity().validate)
def test_next_severity(self): self.assertEqual(Severity.yellow(), Severity.green().next()) self.assertEqual(Severity.red(), Severity.yellow().next()) self.assertEqual(Severity.green(), Severity.red().next())
def test_severity_validations(self): self.assertRaises(ValidationError, Severity("REED").validate) self.assertRaises(ValidationError, Severity("YEELOW").validate) self.assertRaises(ValidationError, Severity("GREEEN").validate)
def test_default_severity(self): self.assertEqual(SeverityEnum.GREEN, Severity.default().severity)
"Ismail Wells", "Ikrah Tapia", "Nell Lim", "Damian Fry", "Jaya Mills", "Tai Sargent", "Elizabeth Bentley", "Wren O'Moore", "Justin Lawson", "Regina Mcculloch", "Liberty Padilla", "Jenson Wilkerson", ] SEVERITIES = [ Severity.red(), Severity.yellow(), Severity.yellow(), Severity.yellow(), Severity.green(), Severity.green(), Severity.green(), Severity.green(), Severity.green(), Severity.green(), Severity.green(), Severity.green(), ] RESPONSES = [ Response.yes(),
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)
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(),