Пример #1
0
    def test_spot_copy(self):
        author = User(email='test')
        author.save()
        spot = models.Spot(title='Legal ID', type='Station ID')
        spot.put()
        self.assertEqual(
            spot.get_add_copy_url(),
            reverse('traffic_log.views.addCopyForSpot', args=(spot.key(), )))

        constraint = models.SpotConstraint(dow=1,
                                           hour=0,
                                           slot=0,
                                           spots=[spot.key()])
        constraint.put()

        spot_copy = models.SpotCopy(
            body=('You are now and forever listening to a killer '
                  'radio station called chirpradio.org'),
            spot=spot,
            author=author)
        spot_copy.put()

        self.assertEqual(
            str(spot_copy),
            "You are now and forever listening to a killer radio...")
        self.assertEqual(
            spot_copy.get_edit_url(),
            reverse('traffic_log.editSpotCopy', args=(spot_copy.key(), )))
        self.assertEqual(
            spot_copy.get_delete_url(),
            reverse('traffic_log.deleteSpotCopy', args=(spot_copy.key(), )))
Пример #2
0
    def test_view_spot_for_reading_basic(self):
        author = User(email='test')
        author.save()
        spot = models.Spot(title='Legal ID', type='Station ID')
        spot.put()
        constraint = models.SpotConstraint(dow=1,
                                           hour=0,
                                           slot=0,
                                           spots=[spot.key()])
        constraint.put()

        spot_copy = models.SpotCopy(body='You are listening to chirpradio.org',
                                    spot=spot,
                                    author=author)
        spot_copy.put()

        resp = self.client.get(
            reverse('traffic_log.spotTextForReading', args=(spot.key(), )), {
                'hour': constraint.hour,
                'dow': constraint.dow,
                'slot': constraint.slot
            })
        context = resp.context
        self.assertEqual(context['spot_copy'].body,
                         'You are listening to chirpradio.org')
        self.assertEqual(
            context['url_to_finish_spot'],
            "/traffic_log/spot-copy/%s/finish?hour=0&dow=1&slot=0" %
            spot_copy.key())
Пример #3
0
    def test_make_spot_copy_expire(self):
        spot = models.Spot(title='Legal ID', type='Station ID')
        spot.put()
        constraint = models.SpotConstraint(dow=1,
                                           hour=0,
                                           slot=0,
                                           spots=[spot.key()])
        constraint.put()

        author = User(email='test')
        author.put()
        spot_copy = models.SpotCopy(body='First', spot=spot, author=author)
        spot_copy.put()

        resp = self.client.post(
            reverse('traffic_log.editSpotCopy', args=(spot_copy.key(), )),
            {
                'spot_key': spot.key(),
                'body': 'Something else entirely',
                'underwriter': 'another underwriter',
                'expire_on': '2/5/2010'  # any date in the past
            })
        self.assertNoFormErrors(resp)

        spot_copy = [c for c in spot.all_spot_copy()]
        self.assertEqual(spot_copy, [])
Пример #4
0
    def test_delete_spot_copy(self):
        spot = models.Spot(title='Legal ID', type='Station ID')
        spot.put()
        dow = 1
        hour = 0
        slot = 0
        constraint = models.SpotConstraint(dow=dow,
                                           hour=hour,
                                           slot=slot,
                                           spots=[spot.key()])
        constraint.put()

        author = User(email='test')
        author.put()
        spot_copy = models.SpotCopy(body='First', spot=spot, author=author)
        spot_copy.put()

        self.assertEqual(spot.get_spot_copy(dow, hour, slot)[0].body, "First")

        # now edit the second one:
        resp = self.client.get(
            reverse('traffic_log.deleteSpotCopy', args=(spot_copy.key(), )))

        self.assertEqual([c for c in spot.all_spot_copy()], [])

        self.assertEqual(spot.get_spot_copy(dow, hour, slot), (None, False))
Пример #5
0
    def test_create_spot_copy(self):
        dow = 1
        hour = 0
        slot = 0
        spot = models.Spot(title='Legal ID', type='Station ID')
        spot.put()
        constraint = models.SpotConstraint(dow=dow,
                                           hour=hour,
                                           slot=slot,
                                           spots=[spot.key()])
        constraint.put()

        resp = self.client.post(
            reverse('traffic_log.createSpotCopy'), {
                'spot_key': spot.key(),
                'body': 'You are listening to chirprario.odg',
                'underwriter': 'pretend this is an underwriter',
                'expire_on': ''
            })
        self.assertNoFormErrors(resp)

        spot_copy, is_logged = spot.get_spot_copy(dow, hour, slot)
        self.assertEqual(spot_copy.body, 'You are listening to chirprario.odg')
        self.assertEqual(spot_copy.underwriter,
                         'pretend this is an underwriter')
        self.assertEqual(spot_copy.author.email, '*****@*****.**')
Пример #6
0
    def test_move_spot_copy_to_another_spot(self):

        # See http://code.google.com/p/chirpradio/issues/detail?id=124
        dow = 1
        hour = 0
        slot = 0

        spot1 = models.Spot(title='First Spot', type='Station ID')
        spot1.put()
        spot1_key = spot1.key()
        constraint = models.SpotConstraint(dow=dow,
                                           hour=hour,
                                           slot=slot,
                                           spots=[spot1.key()])
        constraint.put()

        spot2 = models.Spot(title='Second Spot', type='Station ID')
        spot2.put()
        constraint = models.SpotConstraint(dow=dow,
                                           hour=hour,
                                           slot=slot,
                                           spots=[spot2.key()])
        constraint.put()

        # assign it to the first one:
        author = User(email='test')
        author.put()
        spot_copy = models.SpotCopy(body='First', spot=spot1, author=author)
        spot_copy.put()

        self.assertEqual(spot1.get_spot_copy(dow, hour, slot)[0].body, "First")

        # now move it to the second spot:
        resp = self.client.post(
            reverse('traffic_log.editSpotCopy', args=(spot_copy.key(), )), {
                'spot_key': spot2.key(),
                'body': 'Second',
                'underwriter': '',
                'expire_on': ''
            })
        self.assertNoFormErrors(resp)

        self.assertEqual(
            spot2.get_spot_copy(dow, hour, slot)[0].body, "Second")

        spot1 = models.Spot.get(spot1_key)
        self.assertEqual(spot1.get_spot_copy(dow, hour, slot)[0], None)
Пример #7
0
 def test_spot_constraint_assign(self):
     user = User(email='test')
     user.save()
     spot_key = models.Spot(title='test',
                            body='body',
                            type='Live Read Promo',
                            author=user).put()
     constraint_key = models.SpotConstraint(dow=1, hour=1, slot=0).put()
     views.connectConstraintsAndSpot([constraint_key], spot_key)
     self.assertEqual(models.Spot.get(spot_key).constraints.count(), 1)
Пример #8
0
    def add_spot_to_constraint(self, spot):
        # make a constraint closest to now:
        today = self.now.date()
        current_hour = self.now.hour

        hour = current_hour
        slot = 0

        constraint = models.SpotConstraint(dow=self.dow,
                                           hour=hour,
                                           slot=slot,
                                           spots=[spot.key()])
        constraint.put()
        return constraint
Пример #9
0
    def test_create_edit_spot_copy_expiry(self):
        dow = 1
        hour = 0
        slot = 0
        spot = models.Spot(title='Legal ID', type='Station ID')
        spot.put()
        constraint = models.SpotConstraint(dow=dow,
                                           hour=hour,
                                           slot=slot,
                                           spots=[spot.key()])
        constraint.put()

        now = time_util.chicago_now() + datetime.timedelta(hours=2)
        resp = self.client.post(
            reverse('traffic_log.views.addCopyForSpot', args=(spot.key(), )),
            {
                'spot_key': spot.key(),
                'body': 'You are listening to chirprario.odg',
                'underwriter': 'pretend this is an underwriter',
                'expire_on': now.strftime(
                    "%m/%d/%Y %H:%M:%S")  # no timezone info
            })
        self.assertNoFormErrors(resp)

        spot_copy, is_logged = spot.get_spot_copy(dow, hour, slot)
        converted_expire_on = time_util.convert_utc_to_chicago(
            spot_copy.expire_on)
        self.assertEqual(converted_expire_on.timetuple(), now.timetuple())

        resp = self.client.post(
            reverse('traffic_log.editSpotCopy', args=(spot_copy.key(), )),
            {
                'spot_key': spot.key(),
                'body': 'You are listening to chirprario.odg',
                'underwriter': 'pretend this is an underwriter',
                'expire_on': spot_copy.expire_on.strftime(
                    "%m/%d/%Y %H:%M:%S")  # no timezone info
            })
        self.assertNoFormErrors(resp)

        spot_copy, is_logged = spot.get_spot_copy(dow, hour, slot)
        converted_expire_on = time_util.convert_utc_to_chicago(
            spot_copy.expire_on)
        self.assertEqual(converted_expire_on.timetuple(), now.timetuple())
Пример #10
0
    def test_edit_spot_copy(self):
        spot = models.Spot(title='Legal ID', type='Station ID')
        spot.put()
        constraint = models.SpotConstraint(dow=1,
                                           hour=0,
                                           slot=0,
                                           spots=[spot.key()])
        constraint.put()

        author = User(email='test')
        author.put()
        spot_copy = models.SpotCopy(body='First', spot=spot, author=author)
        spot_copy.put()
        spot_copy2 = models.SpotCopy(
            body='You are listening to chirpradio.org',
            spot=spot,
            author=author)
        spot_copy2.put()

        # now edit the second one:
        resp = self.client.post(
            reverse('traffic_log.editSpotCopy', args=(spot_copy2.key(), )), {
                'spot_key': spot.key(),
                'body': 'Something else entirely',
                'underwriter': 'another underwriter',
                'expire_on': ''
            })
        self.assertNoFormErrors(resp)

        spot_copy = [c for c in spot.all_spot_copy()]
        self.assertEqual(sorted([c.body for c in spot_copy]),
                         ['First', 'Something else entirely'])
        self.assertEqual(sorted([c.underwriter for c in spot_copy]),
                         [None, 'another underwriter'])
        self.assertEqual(sorted([c.author.email for c in spot_copy]),
                         ['test', '*****@*****.**'])
Пример #11
0
    def test_finish_spot(self):
        self.assertEqual(list(models.TrafficLogEntry.all().fetch(5)), [])

        author = User(email='test')
        author.save()
        spot = models.Spot(title='Legal ID', type='Station ID', author=author)
        spot.put()

        # make a constraint closest to now:
        now = time_util.chicago_now()
        today = now.date()
        current_hour = now.hour
        constraint = models.SpotConstraint(dow=today.isoweekday(),
                                           hour=current_hour,
                                           slot=0,
                                           spots=[spot.key()])
        constraint.put()

        spot_copy = models.SpotCopy(body='You are listening to chirpradio.org',
                                    spot=spot,
                                    author=author)
        spot_copy.put()

        spot.random_spot_copies = [spot_copy.key()]
        spot.save()

        resp = self.client.get(reverse('traffic_log.index'))
        # unfinished spot should have been marked in static HTML:
        assert '<tr class="new">' in resp.content

        resp = self.client.get(
            reverse('traffic_log.finishReadingSpotCopy',
                    args=(spot_copy.key(), )), {
                        'hour': constraint.hour,
                        'dow': constraint.dow,
                        'slot': constraint.slot
                    })
        logged = models.TrafficLogEntry.all().fetch(1)[0]
        self.assertEqual(logged.reader.email, "*****@*****.**")
        self.assertEqual(logged.readtime.timetuple()[0:5],
                         datetime.datetime.now().timetuple()[0:5])
        self.assertEqual(logged.log_date, time_util.chicago_now().date())
        self.assertEqual(logged.spot.key(), spot.key())
        self.assertEqual(logged.spot_copy.key(), spot_copy.key())
        self.assertEqual(logged.scheduled.key(), constraint.key())
        self.assertEqual(logged.hour, constraint.hour)
        self.assertEqual(logged.dow, constraint.dow)

        resp = self.client.get(reverse('traffic_log.index'))
        # finished spot should have been marked in static HTML:
        assert '<tr class="finished">' in resp.content

        resp = self.client.get(
            reverse('traffic_log.spotTextForReading', args=(spot.key(), )), {
                'hour': constraint.hour,
                'dow': constraint.dow,
                'slot': constraint.slot
            })
        context = resp.context
        # already finished, no need for finish URL:
        self.assertEqual(context['url_to_finish_spot'], None)
        assert '(already finished)' in resp.content
Пример #12
0
    def test_random_spot_copy_during_creation_and_after_finishing(self):
        author = User(email='test')
        author.save()
        spot = models.Spot(title='PSA', type='Live Read PSA')
        spot.put()
        first_constraint = models.SpotConstraint(dow=1,
                                                 hour=0,
                                                 slot=0,
                                                 spots=[spot.key()])
        first_constraint.put()
        second_constraint = models.SpotConstraint(dow=1,
                                                  hour=1,
                                                  slot=0,
                                                  spots=[spot.key()])
        second_constraint.put()

        psa_copy = [
            'check out our store', 'turn off the stream',
            'sharkula is the greatest'
        ]
        for body in psa_copy:
            resp = self.client.post(
                spot.get_add_copy_url(), {
                    'underwriter': '',
                    'expire_on': '',
                    'body': body,
                    'spot_key': spot.key()
                })
            self.assertNoFormErrors(resp)
            self.assertEqual(resp.status_code, 302)

        def get_read_context(constraint):
            resp = self.client.get(
                reverse('traffic_log.spotTextForReading', args=(spot.key(), )),
                {
                    'hour': constraint.hour,
                    'dow': constraint.dow,
                    'slot': constraint.slot
                })
            self.assertEqual(resp.status_code, 200)
            context = resp.context
            return context

        first_random_copy = get_read_context(
            first_constraint)['spot_copy'].body
        assert first_random_copy in psa_copy
        # each subsequent reading should show the same:
        self.assertEqual(
            get_read_context(first_constraint)['spot_copy'].body,
            first_random_copy)
        self.assertEqual(
            get_read_context(first_constraint)['spot_copy'].body,
            first_random_copy)

        resp = self.client.get(
            get_read_context(first_constraint)['url_to_finish_spot'])
        self.assertEqual(resp.status_code, 200)
        logged = models.TrafficLogEntry.all().fetch(1)[0]
        self.assertEqual(logged.spot.key(), spot.key())

        # after finishing, copy should be the same for the first slot:
        next_random_copy = get_read_context(first_constraint)['spot_copy'].body
        self.assertEqual(next_random_copy, first_random_copy)
        # but cannot be finished:
        self.assertEqual(
            get_read_context(first_constraint)['url_to_finish_spot'], None)

        # after finishing, copy should be DIFFERENT for the next slot:
        next_random_copy = get_read_context(
            second_constraint)['spot_copy'].body
        self.assertNotEqual(next_random_copy, first_random_copy)
        self.assertNotEqual(
            get_read_context(second_constraint)['url_to_finish_spot'], None)