Beispiel #1
0
    def test_add_post(self):
        self._login("alice", "Alic3")
        rv = self.client.post("/user/add")
        self.assertIn("required", rv.data)
        rv = self.client.post("/user/add", data={"user": "******"})
        self.assertIn("Please provide a password", rv.data)
        rv = self.client.post("/user/add", data={"passwd": "passwd"})
        self.assertIn("required", rv.data)
        rv = self.client.post("/user/add", data={"user": "******", "passwd": "passwd"})
        self.assertIn("passwords don", rv.data)
        rv = self.client.post(
            "/user/add",
            data={"user": "******", "passwd": "passwd", "passwd_confirm": "passwd"},
        )
        self.assertIn(escape("User 'alice' exists"), rv.data)
        with db_session:
            self.assertEqual(User.select().count(), 2)

        rv = self.client.post(
            "/user/add",
            data={
                "user": "******",
                "passwd": "passwd",
                "passwd_confirm": "passwd",
                "admin": 1,
            },
            follow_redirects=True,
        )
        self.assertIn("added", rv.data)
        with db_session:
            self.assertEqual(User.select().count(), 3)
        self._logout()
        rv = self._login("user", "passwd")
        self.assertIn("Logged in", rv.data)
Beispiel #2
0
def do_user_import():
	if not request.files['file']:
		return render_template('importusers.html')

	users = []
	reader = csv.reader(request.files['file'])
	for id, name, mail, password, salt, admin, lfmsess, lfmstatus in reader:
		mail = None if mail == 'None' else mail
		admin = admin == 'True'
		lfmsess = None if lfmsess == 'None' else lfmsess
		lfmstatus = lfmstatus == 'True'

		user = User()
		user.id = uuid.UUID(id)
		user.name = name
		user.password = password
		user.salt = salt
		user.admin = admin
		user.lastfm_session = lfmsess
		user.lastfm_status = lfmstatus

		users.append(user)

	store.find(User).remove()
	for u in users:
		store.add(u)
	store.commit()

	return redirect(url_for('user_index'))
Beispiel #3
0
def do_user_import():
	if not request.files['file']:
		return render_template('importusers.html', admin = UserManager.get(store, session.get('userid'))[1].admin)

	users = []
	reader = csv.reader(request.files['file'])
	for id, name, mail, password, salt, admin, lfmsess, lfmstatus in reader:
		mail = None if mail == 'None' else mail
		admin = admin == 'True'
		lfmsess = None if lfmsess == 'None' else lfmsess
		lfmstatus = lfmstatus == 'True'

		user = User()
		user.id = uuid.UUID(id)
		user.name = name
		user.password = password
		user.salt = salt
		user.admin = admin
		user.lastfm_session = lfmsess
		user.lastfm_status = lfmstatus

		users.append(user)

	store.find(User).remove()
	for u in users:
		store.add(u)
	store.commit()

	return redirect(url_for('user_index'))
Beispiel #4
0
    def setUp(self):
        super(AnnotationTestCase, self).setUp()

        with db_session:
            root = Folder(name = 'Root', root = True, path = 'tests')
            folder = Folder(name = 'Folder', path = 'tests/assets', parent = root)
            artist = Artist(name = 'Artist')
            album = Album(name = 'Album', artist = artist)

            track = Track(
                title = 'Track',
                album = album,
                artist = artist,
                disc = 1,
                number = 1,
                path = 'tests/assets/empty',
                folder = folder,
                root_folder = root,
                duration = 2,
                bitrate = 320,
                last_modification = 0
            )

            self.folderid = folder.id
            self.artistid = artist.id
            self.albumid = album.id
            self.trackid = track.id
            self.user = User.get(name = 'alice')
Beispiel #5
0
    def test_user_delete(self):
        self.__invoke("user add -p Alic3 alice")
        self.__invoke("user delete alice")
        self.__invoke("user delete bob", True)

        with db_session:
            self.assertEqual(User.select().count(), 0)
Beispiel #6
0
    def setUp(self):
        super(AnnotationTestCase, self).setUp()

        with db_session:
            root = Folder(name='Root', root=True, path='tests')
            folder = Folder(name='Folder', path='tests/assets', parent=root)
            artist = Artist(name='Artist')
            album = Album(name='Album', artist=artist)

            track = Track(title='Track',
                          album=album,
                          artist=artist,
                          disc=1,
                          number=1,
                          path='tests/assets/empty',
                          folder=folder,
                          root_folder=root,
                          duration=2,
                          bitrate=320,
                          content_type='audio/mpeg',
                          last_modification=0)

            self.folderid = folder.id
            self.artistid = artist.id
            self.albumid = album.id
            self.trackid = track.id
            self.user = User.get(name='alice')
Beispiel #7
0
    def test_user_delete(self):
        self.__cli.onecmd("user add -p Alic3 alice")
        self.__cli.onecmd("user delete alice")
        self.__cli.onecmd("user delete bob")

        with db_session:
            self.assertEqual(User.select().count(), 0)
Beispiel #8
0
    def setUp(self):
        super(PlaylistTestCase, self).setUp()

        with db_session:
            folder = Folder(name="Root", path="tests/assets", root=True)
            artist = Artist(name="Artist!")
            album = Album(name="Album!", artist=artist)

            track = Track(
                path="tests/assets/23bytes",
                title="23bytes",
                artist=artist,
                album=album,
                folder=folder,
                root_folder=folder,
                duration=2,
                disc=1,
                number=1,
                bitrate=320,
                last_modification=0,
            )

            playlist = Playlist(name="Playlist!", user=User.get(name="alice"))
            for _ in range(4):
                playlist.add(track)

        self.playlistid = playlist.id
Beispiel #9
0
    def setUp(self):
        super().setUp()

        with db_session:
            root = Folder(name="Root", root=True, path="tests")
            folder = Folder(name="Folder", path="tests/assets", parent=root)
            artist = Artist(name="Artist")
            album = Album(name="Album", artist=artist)

            # Populate folder ids
            root = Folder.get(name="Root")
            folder = Folder.get(name="Folder")

            track = Track(
                title="Track",
                album=album,
                artist=artist,
                disc=1,
                number=1,
                path="tests/assets/empty",
                folder=folder,
                root_folder=root,
                duration=2,
                bitrate=320,
                last_modification=0,
            )

            self.folderid = folder.id
            self.artistid = artist.id
            self.albumid = album.id
            self.trackid = track.id
            self.user = User.get(name="alice")
Beispiel #10
0
    def test_user_rename(self):
        self.__invoke("user add -p Alic3 alice")
        self.__invoke("user rename alice alice")
        self.__invoke("user rename bob charles", True)

        self.__invoke("user rename alice ''", True)
        with db_session:
            self.assertEqual(User.select().first().name, "alice")

        self.__invoke("user rename alice bob")
        with db_session:
            self.assertEqual(User.select().first().name, "bob")

        self.__invoke("user add -p Ch4rl3s charles")
        self.__invoke("user rename bob charles", True)
        with db_session:
            self.assertEqual(User.select(lambda u: u.name == "bob").count(), 1)
            self.assertEqual(User.select(lambda u: u.name == "charles").count(), 1)
Beispiel #11
0
 def test_root_with_valid_session(self):
     # Root with valid session
     with db_session:
         with self.client.session_transaction() as sess:
             sess["userid"] = User.get(name="alice").id
     rv = self.client.get("/", follow_redirects=True)
     self.assertIn("alice", rv.data)
     self.assertIn("Log out", rv.data)
     self.assertIn("There's nothing much to see here.", rv.data)
Beispiel #12
0
    def setUp(self):
        super().setUp()

        with db_session:
            FolderManager.add("folder", os.path.abspath("tests/assets/folder"))
            scanner = Scanner()
            scanner.queue_folder("folder")
            scanner.run()

            self.trackid = Track.select().first().id
            self.userid = User.get(name="alice").id
Beispiel #13
0
    def test_delete(self):
        path = "/user/del/{}".format(self.users["bob"])

        self._login("bob", "B0b")
        rv = self.client.get(path, follow_redirects=True)
        self.assertIn("There's nothing much to see", rv.data)
        with db_session:
            self.assertEqual(User.select().count(), 2)
        self._logout()

        self._login("alice", "Alic3")
        rv = self.client.get("/user/del/string", follow_redirects=True)
        self.assertIn("badly formed", rv.data)
        rv = self.client.get("/user/del/" + str(uuid.uuid4()), follow_redirects=True)
        self.assertIn("No such user", rv.data)
        rv = self.client.get(path, follow_redirects=True)
        self.assertIn("Deleted", rv.data)
        with db_session:
            self.assertEqual(User.select().count(), 1)
        self._logout()
        rv = self._login("bob", "B0b")
        self.assertIn("Wrong username or password", rv.data)
Beispiel #14
0
    def add(store, name, password, mail, admin):
        if store.find(User, User.name == name).one():
            return UserManager.NAME_EXISTS

        crypt, salt = UserManager.__encrypt_password(password)

        user = User()
        user.name = name
        user.mail = mail
        user.password = crypt
        user.salt = salt
        user.admin = admin

        store.add(user)
        store.commit()

        return UserManager.SUCCESS
Beispiel #15
0
    def setUp(self):
        super(PlaylistTestCase, self).setUp()

        with db_session:
            root = Folder(root=True, name="Root folder", path="tests/assets")
            artist = Artist(name="Artist")
            album = Album(name="Album", artist=artist)

            songs = {}
            for num, song in enumerate(["One", "Two", "Three", "Four"]):
                track = Track(
                    disc=1,
                    number=num,
                    title=song,
                    duration=2,
                    album=album,
                    artist=artist,
                    bitrate=320,
                    path="tests/assets/" + song,
                    last_modification=0,
                    root_folder=root,
                    folder=root,
                )
                songs[song] = track

            users = {u.name: u for u in User.select()}

            playlist = Playlist(user=users["alice"], name="Alice's")
            playlist.add(songs["One"])
            playlist.add(songs["Three"])

            playlist = Playlist(user=users["alice"],
                                public=True,
                                name="Alice's public")
            playlist.add(songs["One"])
            playlist.add(songs["Two"])

            playlist = Playlist(user=users["bob"], name="Bob's")
            playlist.add(songs["Two"])
            playlist.add(songs["Four"])
Beispiel #16
0
    def setUp(self):
        super(PlaylistTestCase, self).setUp()

        with db_session:
            root = Folder(root = True, name = 'Root folder', path = 'tests/assets')
            artist = Artist(name = 'Artist')
            album = Album(name = 'Album', artist = artist)

            songs = {}
            for num, song in enumerate([ 'One', 'Two', 'Three', 'Four' ]):
                track = Track(
                    disc = 1,
                    number = num,
                    title = song,
                    duration = 2,
                    album = album,
                    artist = artist,
                    bitrate = 320,
                    path = 'tests/assets/' + song,
                    content_type = 'audio/mpeg',
                    last_modification = 0,
                    root_folder = root,
                    folder = root
                )
                songs[song] = track

            users = { u.name: u for u in User.select() }

            playlist = Playlist(user = users['alice'], name = "Alice's")
            playlist.add(songs['One'])
            playlist.add(songs['Three'])

            playlist = Playlist(user = users['alice'], public = True, name = "Alice's public")
            playlist.add(songs['One'])
            playlist.add(songs['Two'])

            playlist = Playlist(user = users['bob'], name = "Bob's")
            playlist.add(songs['Two'])
            playlist.add(songs['Four'])
Beispiel #17
0
    def add(store, name, password, mail, admin):
        if store.find(User, User.name == name).one():
            return UserManager.NAME_EXISTS

        crypt, salt = UserManager.__encrypt_password(password)

        user = User()
        user.name = name
        user.mail = mail
        user.password = crypt
        user.salt = salt
        user.admin = admin

        store.add(user)
        store.commit()

        return UserManager.SUCCESS
Beispiel #18
0
    def test_user_add(self):
        self.__cli.onecmd("user add -p Alic3 alice")
        self.__cli.onecmd("user add -p alice alice")

        with db_session:
            self.assertEqual(User.select().count(), 1)
Beispiel #19
0
 def test_user_unsetjukebox(self):
     self.__cli.onecmd("user add -p Alic3 alice")
     self.__cli.onecmd("user setroles -J alice")
     self.__cli.onecmd("user setroles -j alice")
     with db_session:
         self.assertFalse(User.get(name="alice").jukebox)
Beispiel #20
0
 def test_user_unsetadmin(self):
     self.__cli.onecmd("user add -p Alic3 alice")
     self.__cli.onecmd("user setroles -A alice")
     self.__cli.onecmd("user setroles -a alice")
     with db_session:
         self.assertFalse(User.get(name="alice").admin)
Beispiel #21
0
 def test_user_setadmin(self):
     self.__invoke("user add -p Alic3 alice")
     self.__invoke("user setroles -A alice")
     self.__invoke("user setroles -A bob", True)
     with db_session:
         self.assertTrue(User.get(name="alice").admin)
Beispiel #22
0
 def test_user_setjukebox(self):
     self.__invoke("user add -p Alic3 alice")
     self.__invoke("user setroles -J alice")
     with db_session:
         self.assertTrue(User.get(name="alice").jukebox)
Beispiel #23
0
    def test_user_add(self):
        self.__invoke("user add -p Alic3 alice")
        self.__invoke("user add -p alice alice", True)

        with db_session:
            self.assertEqual(User.select().count(), 1)
Beispiel #24
0
    def setUp(self):
        super().setUp()

        with db_session:
            self.users = {u.name: u.id for u in User.select()}