示例#1
0
文件: band.py 项目: AnneGilles/c3sar
def band_view(request):

    band_id = request.matchdict['band_id']
    band = Band.get_by_band_id(band_id)

    # redirect if id does not exist in database
    if not isinstance(band, Band):
        request.session.flash('this id wasnt found in our database!')
        return HTTPFound(route_url('not_found', request))

    #calculate for next/previous-navigation
    max_id = Band.get_max_id()
    #previous
    if band.id == 1:           # if looking at first id
        prev_id = max_id       # --> choose highest id
    else:                      # if looking at other id
        prev_id = band.id - 1  # --> choose previous
    # next
    if band.id != max_id:      # if not on highest id
        next_id = band.id + 1  # --> choose next
    elif band.id == max_id:    # if highest_id
        next_id = 1            # --> choose first id ('wrap around')

    # show who is watching. maybe we should log this ;-)
    viewer_username = authenticated_userid(request)

    return {
        'band': band,
        'viewer_username': viewer_username,
        'prev_id': prev_id,
        'next_id': next_id
        }
示例#2
0
    def test_band_view_one(self):
        """
        view a band - just one
        """
        from c3sar.views.band import band_view
        band_instance = self._makeBand1()
        self.dbsession.add(band_instance)
        self.dbsession.flush()
        the_id = band_instance.id  # db id of that band
        from c3sar.models import Band
        max_id = Band.get_max_id()

        request = testing.DummyRequest()
        request.matchdict['band_id'] = the_id
        self.config = testing.setUp(request=request)
        result = band_view(request)
        self.assertTrue('band' in result, 'band was not seen.')
        self.assertTrue(
            result['prev_id'] is the_id - 1 or max_id,
            'wrong nav id.')
        self.assertTrue(
            result['next_id'] is the_id + 1 or 1,
            'wrong nav id.')
        self.assertTrue('viewer_username' in result,
                        'viewer_username was not seen.')
        self.assertTrue(result['viewer_username'] is None,
                        'viewer_username was not seen.')
示例#3
0
    def test_track_list(self):
        """
        track_list

        get number of bands from db, add two,
        check view and confirm resulting number
        """
        from c3sar.models import Band
        band_count = Band.get_max_id()  # how many in db?
        from c3sar.views.band import band_list

        instance1 = self._makeBand1()  # add a band
        self.dbsession.add(instance1)
        instance2 = self._makeBand2()  # add another band
        self.dbsession.add(instance2)

        request = testing.DummyRequest()
        self.config = testing.setUp(request=request)

        result = band_list(request)

        if DEBUG:  # pragma: no cover
            print "result of test_band_list"
            pp.pprint(result)

        # check that there are two bandss in list
        self.assertEquals(len(result['bands']), band_count + 2,
                          "wrong number of bands in list")
示例#4
0
    def test_band_add_view_validating(self):
        """
        add a band -- validating, be redirected to band_view
        """
        from c3sar.views.band import band_add
        request = testing.DummyRequest(
            post={'form.submitted': True,
                  'band_name': u'testband',
                  'band_homepage': u'http://testba.nd',
                  'band_email': u'*****@*****.**',
                  'registrar_is_member': '1',
                  })
        request.user = self._makeUser()  # a user to add the band
        request.user.username = u"newUser"
        self.dbsession.add(request.user)
        self.dbsession.flush()
        the_user_id = request.user.id

        self.config = testing.setUp(request=request)
        _registerRoutes(self.config)
        result = band_add(request)

        self.assertTrue(isinstance(result, HTTPFound),
                        "expected redirect not seen")
        # check database contents
        from c3sar.models import Band
        max_band_id = Band.get_max_id()
        test_band = Band.get_by_band_id(max_band_id)
        self.assertEquals(test_band.id, max_band_id)
        self.assertEquals(test_band.name, 'testband')
        self.assertEquals(test_band.homepage, 'http://testba.nd')
        self.assertEquals(test_band.registrar_id, the_user_id)  # no real user :-/
        self.assertEquals(test_band.registrar, 'newUser')