"""Test neo4j utility functions.""" from unittest.mock import patch from sound_recordings.api import app from sound_recordings.utils.neo4j import by def test_by(): """Test building by string from request.""" with app.test_request_context(method='POST', path='/foo/bar'): assert by() == 'ows-sound-recordings/post-foo-bar' def test_by_with_profile(): """Test building by string from request with profile arg.""" with app.test_request_context(method='POST', path='/foo/bar'): profile = ('ContentProfile', 123) assert by(profile) == 'ows-sound-recordings/post-foo-bar/123/ContentProfile' @patch('sound_recordings.utils.neo4j.is_generate_optimized_size_fields_enabled') def test_by_with_optimized_size_fields_enabled(mock_ff): """Test building by string from request with optimized size fields enabled.""" mock_ff.return_value = True with app.test_request_context(method='POST', path='/foo/bar'): assert by(is_for_has_fingerprint_rule=True) == '' profile = ('ContentProfile', 123) assert by(profile, is_for_has_fingerprint_rule=True) == '123_7' @patch('sound_recordings.utils.neo4j.is_generate_optimized_size_fields_enabled') def test_by_with_optimized_size_fields_disabled(mock_ff): """Test building by string from request with optimized size fields disabled.""" mock_ff.return_value = False with app.test_request_context(method='POST', path='/foo/bar'): assert by(is_for_has_fingerprint_rule=True) == 'ows-sound-recordings/post-foo-bar' # noqa E501 profile = ('ContentProfile', 123) assert by(profile, is_for_has_fingerprint_rule=True) == 'ows-sound-recordings/post-foo-bar/123/ContentProfile' # noqa E501 @patch('sound_recordings.utils.neo4j.is_generate_optimized_size_fields_enabled') def test_by_with_optimized_size_fields_enabled_unknown_profile(mock_ff): """Test by() with optimized size fields enabled and unknown profile type.""" mock_ff.return_value = True with app.test_request_context(method='POST', path='/foo/bar'): profile = ('UnknownProfile', 456) assert by(profile, is_for_has_fingerprint_rule=True) == '456_0' @patch('sound_recordings.utils.neo4j.is_generate_optimized_size_fields_enabled') def test_by_with_optimized_size_fields_disabled_no_profile(mock_ff): """Test by() with optimized size fields disabled and no profile.""" mock_ff.return_value = False with app.test_request_context(method='POST', path='/foo/bar'): assert by(is_for_has_fingerprint_rule=True) == 'ows-sound-recordings/post-foo-bar' # noqa E501