Test Failed
Push — test-coverage ( b95e5a )
by Konstantinos
02:34
created

tests.test_downloading.download_trials()   A

Complexity

Conditions 1

Size

Total Lines 3
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 3
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
import os
0 ignored issues
show
Coding Style introduced by
This module should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
2
from time import sleep
3
import pytest
4
5
from music_album_creation.downloading import YoutubeDownloader, InvalidUrlError, UnavailableVideoError, TooManyRequestsError, CertificateVerificationError
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (154/100).

This check looks for lines that are too long. You can specify the maximum line length.

Loading history...
6
7
8
@pytest.fixture(scope='module')
9
def youtube():
10
    return YoutubeDownloader
11
12
13
@pytest.fixture(scope='module')
14
def download():
15
    return lambda url, target_directory, times, suppress_certificate_validation: YoutubeDownloader.download_times(url,
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (118/100).

This check looks for lines that are too long. You can specify the maximum line length.

Loading history...
16
                                                                                                                  target_directory,
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (131/100).

This check looks for lines that are too long. You can specify the maximum line length.

Loading history...
17
                                                                                                                  times=10,
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (123/100).

This check looks for lines that are too long. You can specify the maximum line length.

Loading history...
18
                                                                                                                  spawn=False,
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (126/100).

This check looks for lines that are too long. You can specify the maximum line length.

Loading history...
19
                                                                                                                  verbose=False,
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (128/100).

This check looks for lines that are too long. You can specify the maximum line length.

Loading history...
20
                                                                                                                  supress_stdout=True,
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (134/100).

This check looks for lines that are too long. You can specify the maximum line length.

Loading history...
21
                                                                                                                  suppress_certificate_validation=suppress_certificate_validation,
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (178/100).

This check looks for lines that are too long. You can specify the maximum line length.

Loading history...
22
                                                                                                                  delay=0.8)
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (124/100).

This check looks for lines that are too long. You can specify the maximum line length.

Loading history...
23
24
@pytest.fixture(scope='module')
25
def download_trials():
26
    return 15
27
28
29
30
class TestYoutubeDownloader:
31
    NON_EXISTANT_YOUTUBE_URL = 'https://www.youtube.com/watch?v=alpharegavgav'
32
    INVALID_URL = 'gav'
33
    duration = '3:43'
34
    duration_in_seconds = 223
35
36
    def download_trial(self, download_callback, nb_trials):
37
        suppress_certificate_validation = False
38
        try:
39
            download_callback(url, target_directory, 1, suppress_certificate_validation)
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable url does not seem to be defined.
Loading history...
Comprehensibility Best Practice introduced by
The variable target_directory does not seem to be defined.
Loading history...
40
        except CertificateVerificationError as e:
41
            print('{}\nWill try to download without an SSL certificate (plain text as http request)'.format(e))
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (111/100).

This check looks for lines that are too long. You can specify the maximum line length.

Loading history...
42
            suppress_certificate_validation = True
43
            download_callback(url, target_directory, nb_trials, suppress_certificate_validation)
44
45
    @pytest.mark.parametrize("url, target_file", [
46
        ('https://www.youtube.com/watch?v=Q3dvbM6Pias', 'Rage Against The Machine - Testify (Official Video).mp3')])
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (116/100).

This check looks for lines that are too long. You can specify the maximum line length.

Loading history...
47
    def test_downloading_valid_youtube_url(self, url, target_file, tmpdir, download, download_trials):
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (102/100).

This check looks for lines that are too long. You can specify the maximum line length.

Loading history...
48
        target_directory = str(tmpdir.mkdir('youtubedownloads'))
49
        self.download_trial(download, download_trials)
50
        assert os.path.isfile(os.path.join(target_directory, target_file))
51
52
53
    def test_downloading_false_youtube_url(self, download, download_trials):
54
        with pytest.raises(UnavailableVideoError):
55
            self.download_trial(download, download_trials)
56
57
    def test_downloading_invalid_url(self, download):
58
        with pytest.raises(InvalidUrlError):
59
            download(self.INVALID_URL, '/tmp/', 1, False)
60