• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

twschiller / open-synthesis / 9070606557

13 May 2024 10:22PM UTC coverage: 89.664%. Remained the same
9070606557

Pull #674

github

web-flow
Bump pre-commit from 3.5.0 to 3.7.1

Bumps [pre-commit](https://github.com/pre-commit/pre-commit) from 3.5.0 to 3.7.1.
- [Release notes](https://github.com/pre-commit/pre-commit/releases)
- [Changelog](https://github.com/pre-commit/pre-commit/blob/main/CHANGELOG.md)
- [Commits](https://github.com/pre-commit/pre-commit/compare/v3.5.0...v3.7.1)

---
updated-dependencies:
- dependency-name: pre-commit
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Pull Request #674: Bump pre-commit from 3.5.0 to 3.7.1

0 of 1 new or added line in 1 file covered. (0.0%)

1 existing line in 1 file now uncovered.

3739 of 4170 relevant lines covered (89.66%)

0.9 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

98.9
/openach/tests/test_digest.py
1
import datetime
1✔
2
import logging
1✔
3
from unittest.mock import patch
1✔
4

5
from django.conf import settings
1✔
6
from django.core import mail
1✔
7
from django.core.management import call_command
1✔
8
from django.utils import timezone
1✔
9

10
from openach.digest import create_digest_email, send_digest_emails
1✔
11
from openach.models import BoardFollower, DigestFrequency, Evidence, Hypothesis
1✔
12
from openach.views.notifications import notify_add
1✔
13

14
from .common import PrimaryUserTestCase, create_board
1✔
15

16
logger = logging.getLogger(__name__)
1✔
17

18
DEFAULT_FROM_EMAIL = getattr(settings, "DEFAULT_FROM_EMAIL", "admin@localhost")
1✔
19

20

21
class DigestTests(PrimaryUserTestCase):
1✔
22
    def setUp(self):
1✔
23
        super().setUp()
1✔
24
        self.daily = self.user
1✔
25
        self.weekly = self.other
1✔
26

27
        def setup_user(user, freq):
1✔
28
            user.date_joined = timezone.now() + datetime.timedelta(days=-2)
1✔
29
            user.save()
1✔
30
            user.settings.digest_frequency = freq.key
1✔
31
            user.settings.save()
1✔
32

33
        setup_user(self.daily, DigestFrequency.daily)
1✔
34
        setup_user(self.weekly, DigestFrequency.weekly)
1✔
35

36
    def test_can_create_first_digest(self):
1✔
37
        """Test that we can create a digest if the user hasn't received a digest before."""
38
        run_timestamp = timezone.now()
1✔
39
        create_board(board_title="New Board", days=-1)
1✔
40
        email = create_digest_email(self.daily, DigestFrequency.daily, run_timestamp)
1✔
41
        self.assertListEqual(email.to, [self.daily.email])
1✔
42
        logger.debug(email.subject)
1✔
43

44
        self.assertGreater(
1✔
45
            len(email.alternatives), 0, "No HTML body attached to digest email"
46
        )
47
        self.assertTrue(
1✔
48
            "daily" in email.subject,
49
            "No digest frequency in subject: {}".format(email.subject),
50
        )
51
        self.assertTrue("daily" in email.body)
1✔
52

53
    def test_can_email_first_daily_digest(self):
1✔
54
        """Test that we can email a digest if the user hasn't received a daily digest before."""
55
        create_board(board_title="New Board", days=0)
1✔
56
        succeeded, passed, failed = send_digest_emails(DigestFrequency.daily)
1✔
57
        self.assertEqual(succeeded, 1)
1✔
58
        self.assertEqual(passed, 0)
1✔
59
        self.assertEqual(failed, 0)
1✔
60
        self.assertEqual(len(mail.outbox), 1, "No digest email sent")
1✔
61
        self.assertGreater(
1✔
62
            len(mail.outbox[0].alternatives), 0, "No HTML body attached to digest email"
63
        )
64
        self.assertListEqual(mail.outbox[0].to, [self.daily.email])
1✔
65
        self.assertEqual(mail.outbox[0].from_email, DEFAULT_FROM_EMAIL)
1✔
66

67
    def test_can_email_hypothesis_evidence_digest(self):
1✔
68
        """Test that we can email a digest containing new hypotheses and evidence."""
69
        for x in [1, 2]:
1✔
70
            board = create_board(board_title="Board #{}".format(x), days=0)
1✔
71
            BoardFollower.objects.create(
1✔
72
                board=board,
73
                user=self.daily,
74
            )
75
            hypothesis = Hypothesis.objects.create(
1✔
76
                board=board,
77
                hypothesis_text="Hypothesis #{}".format(x),
78
                creator=self.weekly,
79
            )
80
            evidence = Evidence.objects.create(
1✔
81
                board=board,
82
                evidence_desc="Evidence #{}".format(x),
83
                creator=self.weekly,
84
            )
85
            notify_add(board, self.weekly, hypothesis)
1✔
86
            notify_add(board, self.weekly, evidence)
1✔
87

88
        succeeded, passed, failed = send_digest_emails(DigestFrequency.daily)
1✔
89
        self.assertEqual(succeeded, 1)
1✔
90
        self.assertEqual(len(mail.outbox), 1, "No digest email sent")
1✔
91
        txt_body = mail.outbox[0].body
1✔
92
        logger.info(txt_body)
1✔
93

94
        for x in [1, 2]:
1✔
95
            self.assertTrue("Board #{}".format(x) in txt_body)
1✔
96
            self.assertTrue("Hypothesis #{}".format(x) in txt_body)
1✔
97
            self.assertTrue("Evidence #{}".format(x) in txt_body)
1✔
98

99
    def test_email_digest_command(self):
1✔
100
        """Test that admin can send digest from a manage command."""
101
        create_board(board_title="New Board", days=0)
1✔
102
        call_command("senddigest", "daily")
1✔
103
        self.assertEqual(len(mail.outbox), 1, "No weekly digest email sent")
1✔
104

105
    def test_email_weekly_command_digest_day(self):
1✔
106
        """Test that admin can send digest on the weekly digest day."""
107
        setattr(settings, "DIGEST_WEEKLY_DAY", 0)
1✔
108

109
        previous = timezone.now()
1✔
110
        static = previous
1✔
111
        # find the next scheduled digest day
112
        while static.weekday() != 0:
1✔
UNCOV
113
            static += timezone.timedelta(days=1)
×
114

115
        with patch(
1✔
116
            "openach.management.commands.senddigest.timezone.now"
117
        ) as timezone_mock:
118
            timezone_mock.return_value = static
1✔
119
            logger.debug(
1✔
120
                "Shifted timezone.now() from weekday %s to %s",
121
                previous.weekday(),
122
                static.weekday(),
123
            )
124

125
            create_board(board_title="New Board", days=-1)
1✔
126
            call_command("senddigest", "weekly")
1✔
127

128
            self.assertEqual(len(mail.outbox), 1, "No weekly digest email sent")
1✔
129

130
    def test_email_weekly_command_other_day(self):
1✔
131
        """Test that admin cannot digest email not on weekly digest day unless forced."""
132
        setattr(settings, "DIGEST_WEEKLY_DAY", 0)
1✔
133

134
        previous = timezone.now()
1✔
135
        static = previous
1✔
136
        # make sure we're not on a scheduled digest day
137
        while static.weekday() == 0:
1✔
138
            static += timezone.timedelta(days=1)
1✔
139

140
        with patch(
1✔
141
            "openach.management.commands.senddigest.timezone.now"
142
        ) as timezone_mock:
143
            timezone_mock.return_value = static
1✔
144
            logger.debug(
1✔
145
                "Shifted timezone.now() from weekday %s to %s",
146
                previous.weekday(),
147
                static.weekday(),
148
            )
149

150
            create_board(board_title="New Board", days=-1)
1✔
151
            call_command("senddigest", "weekly")
1✔
152

153
            self.assertEqual(
1✔
154
                len(mail.outbox), 0, "Weekly digest email sent on wrong day"
155
            )
156

157
            call_command("senddigest", "weekly", "--force")
1✔
158
            self.assertEqual(
1✔
159
                len(mail.outbox), 1, "Weekly digest email not sent when forced"
160
            )
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc