コード例 #1
0
ファイル: tests.py プロジェクト: yogee007/chirpradio
    def test_landing_page_shows_spots(self):
        user = User(email='test')
        user.save()
        spot = models.Spot(title='Legal ID', type='Station ID')
        spot_key = spot.put()
        # assign it to every day of the week at the top of the hour:
        constraint_keys = views.saveConstraint(
            dict(hour_list=range(0, 24), dow_list=range(1, 8), slot=0))
        views.connectConstraintsAndSpot(constraint_keys, spot_key)

        spot_copy = models.SpotCopy(body='body', spot=spot, author=user)
        spot_copy.put()

        resp = self.client.get(reverse('traffic_log.index'))
        context = resp.context[0]
        spot_map = {}
        constraint_map = {}
        for c in context['slotted_spots']:
            spot_map[c.hour] = list(c.iter_spots())[0]
            constraint_map[c.hour] = c

        now = time_util.chicago_now()

        # first hour:
        self.assertEqual(spot_map[now.hour].title, 'Legal ID')
        # second hour:
        self.assertEqual(
            spot_map[(now + datetime.timedelta(hours=1)).hour].title,
            'Legal ID')
コード例 #2
0
    def test_landing_page_shows_spots(self):
        user = User(email='test')
        user.save()
        spot = models.Spot(
                        title='Legal ID',
                        type='Station ID')
        spot_key = spot.put()
        # assign it to every day of the week at the top of the hour:
        constraint_keys = views.saveConstraint(dict(hour_list=range(0,24), dow_list=range(1,8), slot=0))
        views.connectConstraintsAndSpot(constraint_keys, spot_key)

        spot_copy = models.SpotCopy(body='body',
                                    spot=spot,
                                    author=user)
        spot_copy.put()

        resp = self.client.get(reverse('traffic_log.index'))
        context = resp.context[0]
        spot_map = {}
        constraint_map = {}
        for c in context['slotted_spots']:
            spot_map[c.hour] = list(c.iter_spots())[0]
            constraint_map[c.hour] = c

        now = time_util.chicago_now()

        # first hour:
        self.assertEqual(spot_map[now.hour].title, 'Legal ID')
        # second hour:
        self.assertEqual(spot_map[(now + datetime.timedelta(hours=1)).hour].title,
                'Legal ID')
コード例 #3
0
ファイル: tests.py プロジェクト: yogee007/chirpradio
    def test_delete_spot(self):
        spot = models.Spot(title='Legal ID', type='Station ID')
        spot.put()
        self.assertEqual(spot.active, True)

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

        # assign it to every day of the week at the top of the hour:
        constraint_keys = views.saveConstraint(
            dict(hour_list=range(0, 24), dow_list=range(1, 8), slot=0))
        views.connectConstraintsAndSpot(constraint_keys, spot.key())

        resp = self.client.get(reverse('traffic_log.index'))
        context = resp.context[0]
        slotted_spots = [c for c in context['slotted_spots']]
        spots = [s.title for s in slotted_spots[0].iter_spots()]
        self.assertEqual(spots[0], spot.title)

        resp = self.client.get(
            reverse('traffic_log.deleteSpot', args=[spot.key()]))

        # datastore was cleaned up:
        saved_spot = models.Spot.get(spot.key())
        self.assertEqual(saved_spot.active, False)

        saved_constaints = [
            s for s in models.SpotConstraint.get(constraint_keys)
        ]
        active_spots = []
        for constraint in saved_constaints:
            for spot in constraint.iter_spots():
                active_spots.append(spot)
        self.assertEqual(len(active_spots), 0)

        # spot is hidden from landing page:
        resp = self.client.get(reverse('traffic_log.index'))
        context = resp.context[0]
        slotted_spots = [c for c in context['slotted_spots']]
        active_spots = []
        for slot in slotted_spots:
            for spot in slot.iter_spots_at_constraint():
                active_spots.append(spot)
        self.assertEqual(active_spots, [])

        # spot is hidden from admin view:
        resp = self.client.get(reverse('traffic_log.listSpots'))
        context = resp.context[0]
        spots = [c.title for c in context['spots']]
        self.assertEqual(spots, [])
コード例 #4
0
    def test_delete_spot(self):
        spot = models.Spot(
                        title='Legal ID',
                        type='Station ID')
        spot.put()
        self.assertEqual(spot.active, True)

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

        # assign it to every day of the week at the top of the hour:
        constraint_keys = views.saveConstraint(dict(hour_list=range(0,24), dow_list=range(1,8), slot=0))
        views.connectConstraintsAndSpot(constraint_keys, spot.key())

        resp = self.client.get(reverse('traffic_log.index'))
        context = resp.context[0]
        slotted_spots = [c for c in context['slotted_spots']]
        spots = [s.title for s in slotted_spots[0].iter_spots()]
        self.assertEqual(spots[0], spot.title)

        resp = self.client.get(reverse('traffic_log.deleteSpot', args=[spot.key()]))

        # datastore was cleaned up:
        saved_spot = models.Spot.get(spot.key())
        self.assertEqual(saved_spot.active, False)

        saved_constaints = [s for s in models.SpotConstraint.get(constraint_keys)]
        active_spots = []
        for constraint in saved_constaints:
            for spot in constraint.iter_spots():
                active_spots.append(spot)
        self.assertEqual(len(active_spots), 0)

        # spot is hidden from landing page:
        resp = self.client.get(reverse('traffic_log.index'))
        context = resp.context[0]
        slotted_spots = [c for c in context['slotted_spots']]
        active_spots = []
        for slot in slotted_spots:
            for spot in slot.iter_spots_at_constraint():
                active_spots.append(spot)
        self.assertEqual(active_spots, [])

        # spot is hidden from admin view:
        resp = self.client.get(reverse('traffic_log.listSpots'))
        context = resp.context[0]
        spots = [c.title for c in context['spots']]
        self.assertEqual(spots, [])