Example #1
0
 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)
Example #2
0
 def test_datetime_stamp(self):
     audit = CompletedAuditBuilder() \
         .with_title("Title") \
         .with_auditor("Auditor") \
         .with_answer(VALID_ANSWER) \
         .build()
     self.assertGreaterEqual(datetime.utcnow(), audit.datetime)
Example #3
0
 def test_title_max_length(self):
     too_many_characters = "PM4t5qKhqS6oSEtPrtXUaQWbEeZ2ITca4AsSzF2KApecyI6Yh2f"
     builder = CompletedAuditBuilder() \
         .with_title(too_many_characters) \
         .with_auditor("Auditor") \
         .with_answer(VALID_ANSWER)
     self.assertRaises(ValidationError, builder.build)
Example #4
0
 def test_title_min_length(self):
     empty_string = ""
     builder = CompletedAuditBuilder() \
         .with_title(empty_string) \
         .with_auditor("Auditor") \
         .with_answer(VALID_ANSWER)
     self.assertRaises(ValidationError, builder.build)
Example #5
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()
Example #6
0
 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)
Example #7
0
 def test_each_answer_is_validated(self):
     builder = CompletedAuditBuilder() \
         .with_title("Title") \
         .with_auditor("Auditor") \
         .with_answer(VALID_ANSWER) \
         .with_answer(VALID_ANSWER) \
         .with_answer(INVALID_ANSWER) \
         .with_answer(VALID_ANSWER)
     self.assertRaises(ValidationError, builder.build)
Example #8
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)
Example #9
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)
Example #10
0
        time.sleep(DELAY)
        title = random_title()
        q0 = random_question()
        q1 = random_question()
        q2 = random_question()
        q3 = random_question()
        q4 = random_question()

        AuditTemplateBuilder() \
            .with_title(title) \
            .with_question(q0) \
            .with_question(q1) \
            .with_question(q2) \
            .with_question(q3) \
            .with_question(q4) \
            .build() \
            .save()

        for _ in range(NUM_COMPLETED_PER_TEMPLATE):
            time.sleep(DELAY)
            CompletedAuditBuilder() \
                .with_title(title) \
                .with_auditor(random.choice(AUDITORS)) \
                .with_answer(random_answer_from_question(q0)) \
                .with_answer(random_answer_from_question(q1)) \
                .with_answer(random_answer_from_question(q2)) \
                .with_answer(random_answer_from_question(q3)) \
                .with_answer(random_answer_from_question(q4)) \
                .build() \
                .save()
    # Create an AuditTemplate for each Audit Title and assign x-number of CompletedAudits (Responses) to it
    for title in AUDIT_TITLES:
        template_audit = AuditTemplateBuilder().with_title(title)

        # Use a variable number of random questions for each template and add them to this Audit Template
        rand_questions_list = []
        for question_text in sample(QUESTION_TEXTS,
                                    randrange(1, len(QUESTION_TEXTS))):
            q = get_question(question_text)
            rand_questions_list.append(q)
            template_audit.with_question(q)

        template_audit.build().save()

        # Assign a variable number of CompletedAudits (Responses) to this template (no duplicate auditors)
        for unique_auditor in sample(AUDITORS, NUM_RESPONSES):
            completed_audit = CompletedAuditBuilder() \
                .with_title(title) \
                .with_auditor(unique_auditor) \
                .with_datetime(datetime.utcnow() - timedelta(days=randint(0, (31 * 12 * MAX_YEAR_DELTA)),
                                                             hours=randint(0, 24),
                                                             minutes=randint(0, 60),
                                                             seconds=randint(0, 60)))

            for rand_question in rand_questions_list:
                completed_audit.with_answer(
                    get_random_answer_for(rand_question))

            completed_audit.build().save()
Example #12
0
 def test_answers_are_required(self):
     builder = CompletedAuditBuilder() \
         .with_title("Title") \
         .with_auditor("Auditor")
     self.assertRaises(ValidationError, builder.build)
Example #13
0
 def test_title_is_required(self):
     builder = CompletedAuditBuilder() \
         .with_auditor("Auditor") \
         .with_answer(VALID_ANSWER)
     self.assertRaises(ValidationError, builder.build)