summaryrefslogtreecommitdiff
path: root/scripts/emit_releases_file/test_get_dlrn_hash.py
blob: 2525fb190b3d1f2e848fc9cfcb9d184b6476478c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
from emit_releases_file import get_dlrn_hash

import mock
import pytest


@mock.patch('requests.get')
def test_get_dlrn_hash(mock_get):
    mock_response = mock.Mock()
    mock_response.content = ('[delorean]\nname=delorean-openstack-nova-81c23c04'
                             '7e8e0fc03b54164921f49fdb4103202c\nbaseurl=https:/'
                             '/trunk.rdoproject.org/centos7/81/c2/81c23c047e8e0'
                             'fc03b54164921f49fdb4103202c_b333f915\nenabled=1\n'
                             'gpgcheck=0\npriority=1')
    release = 'master'
    hash_name = 'current-tripleo'
    repo_url = ('https://trunk.rdoproject.org/centos7-%s/%s/delorean.repo'
                % (release, hash_name))
    mock_get.return_value = mock_response
    assert (get_dlrn_hash(release, hash_name) ==
            '81c23c047e8e0fc03b54164921f49fdb4103202c_b333f915')
    mock_get.assert_called_once_with(repo_url, timeout=(3.05, 27))


@mock.patch('requests.get')
def test_null_response_raises_runtimeerror(mock_get):
    release = 'master'
    hash_name = 'current-tripleo'
    repo_url = ('https://trunk.rdoproject.org/centos7-%s/%s/delorean.repo' %
                (release, hash_name))
    mock_get.return_value = None
    with pytest.raises(RuntimeError):
        get_dlrn_hash(release, hash_name)
    mock_get.assert_called_with(repo_url, timeout=(3.05, 27))
    assert (10 == mock_get.call_count)