Skip to content

Commit

Permalink
fixed tests
Browse files Browse the repository at this point in the history
  • Loading branch information
FredHaa committed Apr 3, 2023
1 parent 3817c80 commit 32ba198
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
2 changes: 1 addition & 1 deletion src/mediacatch_s2t/uploader.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ def get_duration(self):
else:
for stream in probe.json['streams']:
if stream['codec_type'] == 'audio':
return float(stream['duration']) * 1000, stream
return int(float(stream['duration']) * 1000), stream
else:
return 0, "The file doesn't have an audio track"
except OSError as e:
Expand Down
22 changes: 11 additions & 11 deletions tests/test_uploader.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ def test_is_file_exist_mocked_return_true(mock_is_file):
assert Uploader('fake file', 'fake key')._is_file_exist() is True


@mock.patch("pymediainfo.MediaInfo.parse")
def test_get_duration_mocked_return_value(mock_pymedia):
class MockDuration:
duration = 1000
mock_pymedia.return_value.audio_tracks = [MockDuration]
assert Uploader('fake file', 'fake key').get_duration() == (True, 1000)
@mock.patch("subprocess.run")
def test_get_duration_mocked_return_value(mock_subprocess):
mock_subprocess.return_value.returncode = 0
mock_subprocess.return_value.stdout = '{"streams": [{"codec_type": "audio", "duration": 1}]}'
mock_subprocess.return_value.stderr = None
assert Uploader('fake file', 'fake key').get_duration() == (1000, {'codec_type': 'audio', 'duration': 1})


def test_estimated_result_time():
Expand All @@ -26,8 +26,8 @@ def test_estimated_result_time():
read_data="bytes of data")
@mock.patch("pathlib.Path")
@mock.patch("os.path.getsize", return_value=100)
@mock.patch("pymediainfo.MediaInfo.parse")
def test_upload_succeed(mock_pymedia, mock_getsize, mock_Path, mock_open):
@mock.patch("subprocess.run")
def test_upload_succeed(mock_subprocess, mock_getsize, mock_Path, mock_open):
URL_EXAMPLE = 'http://url-for-upload.example.com'

def side_effect():
Expand All @@ -36,9 +36,9 @@ def side_effect():
mock_Path.return_value.suffix = '.avi'
mock_Path.return_value.is_file.side_effect = side_effect

class MockDuration:
duration = 100000
mock_pymedia.return_value.audio_tracks = [MockDuration]
mock_subprocess.return_value.returncode = 0
mock_subprocess.return_value.stdout = '{"streams": [{"codec_type": "audio", "duration": 100}]}'
mock_subprocess.return_value.stderr = None

responses.add(
responses.POST, f'{URL}{PRESIGNED_ENDPOINT}', status=200,
Expand Down

0 comments on commit 32ba198

Please sign in to comment.