Exemplo n.º 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)
Exemplo n.º 2
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)
Exemplo n.º 3
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)
Exemplo n.º 4
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)
Exemplo n.º 5
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)
Exemplo n.º 6
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"])
Exemplo n.º 7
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'])
Exemplo n.º 8
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)
Exemplo n.º 9
0
    def setUp(self):
        super().setUp()

        with db_session:
            self.users = {u.name: u.id for u in User.select()}
Exemplo n.º 10
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)