Example #1
0
    def test_trip_without_itinerary(self):
        """Prove that we can send emails without an itinerary (a former requirement)"""
        self.trip.info.delete()
        self.trip.refresh_from_db()

        sole.send_email_to_funds(self.trip)

        # Results in sending a single email
        self.assertEqual(len(mail.outbox), 1)
        msg = mail.outbox[0]

        self._expect_basics(msg)
        self._expect_plaintext_contents(msg, has_start_location=False)
        self._expect_html_contents(msg, has_start_location=False)
Example #2
0
def send_sole_itineraries():
    """ Email trip itineraries to Student Organizations, Leadership and Engagement.

    This task should be run daily, so that it will always send SOLE
    this information _before_ the trip actually starts.
    """
    tomorrow = date_utils.local_date() + timedelta(days=1)
    trips = models.Trip.objects.filter(trip_date=tomorrow, info__isnull=False)
    logger.info(
        "Sending itineraries for %d trips taking place tomorrow, %s",
        trips.count(),
        tomorrow,
    )
    for trip in trips.select_related('info').prefetch_related('leaders'):
        send_email_to_funds(trip)
Example #3
0
    def test_message(self):
        sole.send_email_to_funds(self.trip)

        # Results in sending a single email
        self.assertEqual(len(mail.outbox), 1)
        msg = mail.outbox[0]

        self._expect_basics(msg)
        self._expect_plaintext_contents(msg)
        soup = self._expect_html_contents(msg)

        # no drivers in this test!
        self.assertEqual(
            soup.find('h3', string='Drivers').find_next_sibling('p').get_text(
                ' ', strip=True),
            'Nobody on this trip submitted information for a car.',
        )
        self.assertIn(
            'Drivers:\n  Nobody on this trip submitted information for a car.\n',
            msg.body,
        )
Example #4
0
    def test_has_drivers(self):
        """ Both leaders and participants will be reported as drivers. """
        self.leader.car = factories.CarFactory(
            make='Toyota',
            model='Prius',
            license_plate='VANITY',
            state='NH',
            year='2019',
            color='Blue',
        )
        self.leader.save()
        with self.assertRaises(models.LotteryInfo.DoesNotExist):
            self.leader.lotteryinfo  # pylint: disable=pointless-statement

        self.trip.info.drivers.add(self.leader)

        self.joe.car = factories.CarFactory(
            make='Ford',
            model='Fiesta',
            license_plate='ABC 123',
            state='VT',
            year='2001',
            color='Green',
        )
        self.joe.save()
        factories.LotteryInfoFactory.create(participant=self.joe, car_status="own")

        self.trip.info.drivers.add(self.joe)

        sole.send_email_to_funds(self.trip)

        # Results in sending a single email
        self.assertEqual(len(mail.outbox), 1)
        msg = mail.outbox[0]

        self._expect_basics(msg)
        self._expect_plaintext_contents(msg)
        soup = self._expect_html_contents(msg)

        # Make sure that both participant and leader drivers are given in the table!
        drivers_table = soup.find('h3', string='Drivers').find_next_sibling('table')
        header = [el.text for el in drivers_table.find('thead').find_all('th')]
        rows = drivers_table.find('tbody').find_all('tr')
        drivers = [zip(header, (td.text for td in row.find_all('td'))) for row in rows]
        expected = [
            [
                ('Driver', 'Tim Beaver'),
                ('Make + Model', 'Toyota Prius'),
                ('Plate', 'VANITY'),
                ('State', 'NH'),
                ('Year', '2019'),
                ('Color', 'Blue'),
                # The leader never submitted lottery info
                ('Car Status', ''),
            ],
            [
                ('Driver', 'Joe Schmo'),
                ('Make + Model', 'Ford Fiesta'),
                ('Plate', 'ABC 123'),
                ('State', 'VT'),
                ('Year', '2001'),
                ('Color', 'Green'),
                ('Car Status', 'Can drive own car'),
            ],
        ]
        self.assertCountEqual([list(driver) for driver in drivers], expected)

        as_text = '\n'.join(
            [
                'Drivers:',
                ' - Tim Beaver: Blue 2019 Toyota Prius VANITY (NH)',
                ' - Joe Schmo: Green 2001 Ford Fiesta ABC 123 (VT)',
                '\n',
            ]
        )
        self.assertIn(as_text, msg.body)