def test_manage_album_viewers_remove_not_viewer(self): from lasco import api from lasco.models import Album from lasco.models import AlbumViewer from lasco.models import Gallery g = Gallery('g', u'title') self.session.add(g) g.albums.append(Album('album', u'title')) assert not self.session.query(AlbumViewer).all() self.add_user(u'user1') api.manage_album_viewers(self.session, 'g', 'album', u'-user1') self.assert_( not self.session.query(AlbumViewer).all())
def test_get_album_viewers(self): from lasco import api from lasco.models import Album from lasco.models import Gallery g = Gallery('g', u'title') self.session.add(g) g.albums.append(Album('album', u'title')) self.assertEqual( api.get_album_viewers(self.session, 'g', 'album'), []) self.add_user(u'user1') api.manage_album_viewers(self.session, 'g', 'album', u'+user1') viewers = api.get_album_viewers(self.session, 'g', 'album') self.assertEqual([v.login for v in viewers], ['user1'])
def test_manage_album_viewers_add_already_viewer(self): from lasco import api from lasco.models import Album from lasco.models import AlbumViewer from lasco.models import Gallery g = Gallery('g', u'title') self.session.add(g) g.albums.append(Album('album', u'title')) user = self.add_user(u'user1') api.manage_album_viewers(self.session, 'g', 'album', u'+user1') assert self.session.query(AlbumViewer).one() api.manage_album_viewers(self.session, 'g', 'album', u'+user1') viewer = self.session.query(AlbumViewer).one() self.assertEqual(viewer.user_id, user.id)
def test_manage_album_viewers(self): from lasco import api from lasco.models import Album from lasco.models import AlbumViewer from lasco.models import Gallery g = Gallery('g', u'title') a = Album('album', u'title') self.session.add(g) g.albums.append(a) user1 = self.add_user(u'user1') user2 = self.add_user(u'user2') user3 = self.add_user(u'user3') api.manage_album_viewers(self.session, 'g', 'album', u'+user1') viewer = self.session.query(AlbumViewer).one() self.assertEqual(viewer.album_id, a.id) self.assertEqual(viewer.user_id, user1.id) api.manage_album_viewers( self.session, 'g', 'album', u'-user1', u'+user2', u'+user3') viewers = self.session.query(AlbumViewer).all() self.assertEqual(sorted([v.user_id for v in viewers]), [user2.id, user3.id])
def add_album_viewer(self, gallery_name, album_name, login): lascoapi.manage_album_viewers( self.session, gallery_name, album_name, '+%s' % login)