Beispiel #1
0
    def test_invalid_fv_term(self, mock_track):
        """Raise SystemExit if field/value term is in the wrong format."""
        args = argparse.Namespace(fv_terms=["bad_format"],
                                  query="",
                                  album=False,
                                  extra=False)

        with pytest.raises(SystemExit) as error:
            with patch("moe.core.query.query", return_value=[mock_track]):
                edit._parse_args(config=Mock(), session=Mock(), args=args)

        assert error.value.code != 0
Beispiel #2
0
    def test_multiple_terms(self, mock_track):
        """We can edit multiple terms at once."""
        args = argparse.Namespace(fv_terms=["track_num=3", "title=yo"],
                                  query="",
                                  album=False,
                                  extra=False)

        with patch("moe.core.query.query",
                   return_value=[mock_track]) as mock_query:
            mock_session = Mock()

            edit._parse_args(config=Mock(), session=mock_session, args=args)

            mock_query.assert_called_with("", mock_session, query_type="track")

        assert mock_track.track_num == 3
        assert mock_track.title == "yo"
Beispiel #3
0
    def test_date_field(self, mock_track):
        """We can edit the date."""
        args = argparse.Namespace(fv_terms=["date=2020-11-01"],
                                  query="",
                                  album=False,
                                  extra=False)

        with patch("moe.core.query.query",
                   return_value=[mock_track]) as mock_query:
            mock_session = Mock()

            edit._parse_args(config=Mock(), session=mock_session, args=args)

            mock_query.assert_called_once_with("",
                                               mock_session,
                                               query_type="track")

        assert mock_track.date == datetime.date(2020, 11, 1)
Beispiel #4
0
    def test_int_field(self, mock_track):
        """We can edit integer fields."""
        args = argparse.Namespace(fv_terms=["track_num=3"],
                                  query="",
                                  album=False,
                                  extra=False)

        with patch("moe.core.query.query",
                   return_value=[mock_track]) as mock_query:
            mock_session = Mock()

            edit._parse_args(config=Mock(), session=mock_session, args=args)

            mock_query.assert_called_once_with("",
                                               mock_session,
                                               query_type="track")

        assert mock_track.track_num == 3
Beispiel #5
0
    def test_album(self, mock_track):
        """We can edit an album's field."""
        args = argparse.Namespace(fv_terms=["title=new title"],
                                  query="",
                                  album=True,
                                  extra=False)

        with patch("moe.core.query.query",
                   return_value=[mock_track.album_obj]) as mock_query:
            mock_session = Mock()

            edit._parse_args(config=Mock(), session=mock_session, args=args)

            mock_query.assert_called_once_with("",
                                               mock_session,
                                               query_type="album")

        assert mock_track.album == "new title"
Beispiel #6
0
    def test_genre(self, mock_track):
        """We can edit genres."""
        args = argparse.Namespace(fv_terms=["genre=a; b"],
                                  query="",
                                  album=False,
                                  extra=False)

        with patch("moe.core.query.query",
                   return_value=[mock_track]) as mock_query:
            mock_session = Mock()

            edit._parse_args(config=Mock(), session=mock_session, args=args)

            mock_query.assert_called_once_with("",
                                               mock_session,
                                               query_type="track")

        assert set(mock_track.genres) == {"a", "b"}
Beispiel #7
0
    def test_invalid_date_field(self, mock_track):
        """We can edit the date."""
        args = argparse.Namespace(fv_terms=["date=2020"],
                                  query="",
                                  album=False,
                                  extra=False)

        with pytest.raises(SystemExit) as error:
            with patch("moe.core.query.query",
                       return_value=[mock_track]) as mock_query:
                mock_session = Mock()

                edit._parse_args(config=Mock(),
                                 session=mock_session,
                                 args=args)

                mock_query.assert_called_once_with("",
                                                   mock_session,
                                                   query_type="track")

        assert error.value.code == 1
Beispiel #8
0
    def test_invalid_album_field(self, mock_track):
        """Raise SystemExit if attempting to edit an invalid field."""
        args = argparse.Namespace(fv_terms=["lol=3"],
                                  query="track_num:%",
                                  album=True,
                                  extra=False)

        with pytest.raises(SystemExit) as error:
            with patch("moe.core.query.query",
                       return_value=[mock_track.album_obj]) as mock_query:
                mock_session = Mock()

                edit._parse_args(config=Mock(),
                                 session=mock_session,
                                 args=args)

                mock_query.assert_called_once_with("",
                                                   mock_session,
                                                   query_type="album")

        assert error.value.code != 0
Beispiel #9
0
    def test_multiple_items(self, mock_track_factory):
        """All items returned from a query are edited."""
        args = argparse.Namespace(fv_terms=["track_num=3"],
                                  query="",
                                  album=False,
                                  extra=False)

        track1 = mock_track_factory()
        track2 = mock_track_factory()
        with patch("moe.core.query.query",
                   return_value=[track1, track2]) as mock_query:
            mock_session = Mock()

            edit._parse_args(config=Mock(), session=mock_session, args=args)

            mock_query.assert_called_once_with("",
                                               mock_session,
                                               query_type="track")

        assert track1.track_num == 3
        assert track2.track_num == 3
Beispiel #10
0
    def test_single_invalid_field(self, mock_track):
        """If only one out of multiple fields are invalid, still process the others."""
        args = argparse.Namespace(fv_terms=["lol=3", "track_num=3"],
                                  query="",
                                  album=False,
                                  extra=False)

        with pytest.raises(SystemExit) as error:
            with patch("moe.core.query.query",
                       return_value=[mock_track]) as mock_query:
                mock_session = Mock()

                edit._parse_args(config=Mock(),
                                 session=mock_session,
                                 args=args)

                mock_query.assert_called_once_with("",
                                                   mock_session,
                                                   query_type="track")

        assert error.value.code != 0
        assert mock_track.track_num == 3
Beispiel #11
0
    def test_non_editable_fields(self, mock_track):
        """Paths and file extensions shouldn't be edited."""
        args = argparse.Namespace(fv_terms=["path=3"],
                                  query="",
                                  album=False,
                                  extra=False)

        with pytest.raises(SystemExit) as error:
            with patch("moe.core.query.query",
                       return_value=[mock_track]) as mock_query:
                mock_session = Mock()

                edit._parse_args(config=Mock(),
                                 session=mock_session,
                                 args=args)

                mock_query.assert_called_once_with("",
                                                   mock_session,
                                                   query_type="track")

        assert error.value.code != 0
        assert mock_track.path != "3"