Completed
Pull Request — master (#9)
by George
02:20
created

mock_boto_client_sns()   A

Complexity

Conditions 1

Size

Total Lines 5

Duplication

Lines 0
Ratio 0 %
Metric Value
cc 1
dl 0
loc 5
rs 9.4285
1
# -*- coding: utf-8 -*-
2
# vi:si:et:sw=4:sts=4:ts=4
3
4
from unittest import mock
5
6
import pytest
7
8
9
# boto client methods mock
10
11
@pytest.fixture
12
def mock_get_queue_url():
13
    queue_url = 'https://sqs.us-east-1.amazonaws.com/123456789012/queue-name'
14
    return mock.Mock(return_value={'QueueUrl': queue_url})
15
16
17
@pytest.fixture
18
def mock_receive_message_empty():
19
    return mock.Mock(return_value={})
20
21
22
@pytest.fixture
23
def mock_receive_message():
24
    message = {'Body': 'test'}
25
    return mock.Mock(return_value={'Messages': [message]})
26
27
28
@pytest.fixture
29
def mock_send_message():
30
    response = {'MessageId': 'uuid', 'MD5OfMessageBody': 'md5',
31
                'ResponseMetada': {'RequestId': 'uuid', 'HTTPStatusCode': 200}}
32
    return mock.Mock(return_value=response)
33
34
35
@pytest.fixture
36
def mock_delete_message():
37
    return mock.Mock()
38
39
40
@pytest.fixture
41
def mock_sns_list_topics():
42
    topics = {'Topics': [{'TopicArn': 'arn:aws:sns:region:id:topic-name'}]}
43
    return mock.Mock(return_value=topics)
44
45
46
@pytest.fixture
47
def mock_sns_publish():
48
    response = {'ResponseMetadata': {'HTTPStatusCode': 200, 'RequestId': 'uuid'},
49
                'MessageId': 'uuid'}
50
    return mock.Mock(return_value=response)
51
52
53
# boto client mock
54
55
@pytest.fixture
56
def mock_boto_client_sns(mock_sns_publish, mock_sns_list_topics):
57
    mock_client = mock.Mock(publish=mock_sns_publish,
58
                            list_topics=mock_sns_list_topics)
59
    return mock.patch('boto3.client', return_value=mock_client)
60
61
62
@pytest.fixture
63
def mock_boto_client_sqs(mock_get_queue_url, mock_send_message):
64
    mock_client = mock.Mock(get_queue_url=mock_get_queue_url,
65
                            send_message=mock_send_message)
66
    return mock.patch('boto3.client', return_value=mock_client)
67
68
69
@pytest.fixture
70
def mock_boto_client_sqs_with_empty_messages(mock_get_queue_url,
0 ignored issues
show
Coding Style Naming introduced by
The name mock_boto_client_sqs_with_empty_messages does not conform to the function naming conventions ([a-z_][a-z0-9_]{2,30}$).

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
71
                                             mock_receive_message_empty):
72
    mock_client = mock.Mock(get_queue_url=mock_get_queue_url,
73
                            receive_message=mock_receive_message_empty)
74
    return mock.patch('boto3.client', return_value=mock_client)
75
76
77
@pytest.fixture
78
def mock_boto_client_sqs_with_messages(mock_get_queue_url, mock_receive_message):
0 ignored issues
show
Coding Style Naming introduced by
The name mock_boto_client_sqs_with_messages does not conform to the function naming conventions ([a-z_][a-z0-9_]{2,30}$).

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
79
    mock_client = mock.Mock(get_queue_url=mock_get_queue_url,
80
                            receive_message=mock_receive_message)
81
    return mock.patch('boto3.client', return_value=mock_client)
82
83
84
@pytest.fixture
85
def mock_boto_client_sqs_with_delete_message(mock_get_queue_url, mock_delete_message):
0 ignored issues
show
Coding Style Naming introduced by
The name mock_boto_client_sqs_with_delete_message does not conform to the function naming conventions ([a-z_][a-z0-9_]{2,30}$).

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
86
    mock_client = mock.Mock(get_queue_url=mock_get_queue_url,
87
                            delete_message=mock_delete_message)
88
    return mock.patch('boto3.client', return_value=mock_client)
89