def test_insert_email_for_commit_does_nothing_if_email_already_sent(self):
     commit = create_commit()
     self.db.insert_commit(commit)
     email = create_email()
     self.db.insert_email_for_commit(email, commit)
     # This should do nothing, i.e. not raising an error regarding the
     # UNIQUE constraint of commit_id in the emails table.
     self.db.insert_email_for_commit(email, commit)
    def test_initialize_commit_records_does_not_clear_emails_when_forced_not_to(self):
        commit = create_commit()
        self.db.insert_commit(commit)
        self.db.insert_email_for_commit(create_email(), commit)

        self.db.initialize_commit_records(commit, remove_emails=False)

        self.assertTrue(self.db.email_sent_for_commit(commit))
    def test_initialize_commit_records_clears_emails_when_email_is_present(self):
        commit = create_commit()
        self.db.insert_commit(commit)
        self.db.insert_email_for_commit(create_email(), commit)

        self.db.initialize_commit_records(commit)

        self.assertFalse(self.db.email_sent_for_commit(commit))
 def test_email_sent_for_commit_returns_true_if_email_sent(self):
     commit = create_commit()
     self.db.insert_commit(commit)
     self.db.insert_email_for_commit(create_email(), commit)
     self.assertTrue(self.db.email_sent_for_commit(commit))
 def test_insert_email_for_commit_raises_invalid_commit_error_when_no_such_commit(
         self):
     with self.assertRaises(InvalidCommitError):
         self.db.insert_email_for_commit(create_email(), create_commit())
 def test_insert_email_for_commit_inserts_commit_if_not_already_sent(self):
     commit = create_commit()
     self.db.insert_commit(commit)
     email = create_email()
     self.db.insert_email_for_commit(email, commit)
     self.assertTrue(self.db.email_sent_for_commit(commit))