Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit 92ca905

Browse files
authored
chore: bump deps and remove mock library (#46)
* chore: bump deps and remove mock library * Rebase * Rebase * fix: correct tests
1 parent e342ef5 commit 92ca905

File tree

14 files changed

+170
-150
lines changed

14 files changed

+170
-150
lines changed

.flake8

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
[flake8]
22
max-line-length = 120
3+
extend-ignore = E203

.github/workflows/build.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ jobs:
2020
runs-on: ubuntu-latest
2121
strategy:
2222
matrix:
23-
pythonversion: ["3.6", "3.7", "3.8", "3.9"]
23+
pythonversion: ["3.7", "3.8", "3.9"]
2424
steps:
2525
- name: Checkout Repository
2626
uses: actions/checkout@v2

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
* Previously a webhook secret was required; now, Harvey will run Pipelines without a webhook secret (bypassing decoding and validation of the previously non-existent secret) if there is no `WEBHOOK_SECRET` variable set
99
* Additional refactor surrounding how we validate webhook secrets
1010
* Fixed the container healthcheck when using the compose workflow - this was accomplished by making the compose and non-compose container names uniform
11+
* Bumps dependencies (Flask 1 to Flask 2) and now requires Python 3.7. Also removes the `mock` library in favor of the builtin `unittest.mock` library
1112
* Various code refactors and bug fixes
1213

1314
## v0.12.0 (2021-08-17)

harvey/pipelines.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,8 +107,8 @@ def open_project_config(webhook):
107107
# within a JSON file in the repo
108108
try:
109109
filename = os.path.join(Global.PROJECTS_PATH, Global.repo_full_name(webhook), 'harvey.json')
110-
with open(filename, 'r') as file:
111-
config = json.loads(file.read())
110+
with open(filename, 'r') as config_file:
111+
config = json.loads(config_file.read())
112112
print(json.dumps(config, indent=4))
113113
return config
114114
except FileNotFoundError:

setup.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,16 @@
44
long_description = fh.read()
55

66
REQUIREMENTS = [
7-
'flask == 1.*', # TODO: bump to v2 after thorough testing
7+
'flask == 2.*',
88
'requests == 2.*',
99
'requests_unixsocket == 0.2.*',
1010
'slackclient == 2.*',
11-
'python-dotenv == 0.17.*',
11+
'python-dotenv == 0.19.*',
1212
]
1313

1414
DEV_REQUIREMENTS = [
1515
'coveralls == 3.*',
1616
'flake8',
17-
'mock == 4.*',
1817
'pytest == 6.*',
1918
'pytest-cov == 2.*',
2019
]
@@ -41,5 +40,5 @@
4140
entry_points={
4241
'console_scripts': ['harvey-ci=harvey.app:main'],
4342
},
44-
python_requires='>=3.6',
43+
python_requires='>=3.7',
4544
)

test/unit/conftest.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1+
from unittest.mock import MagicMock, Mock
2+
13
import harvey.app as app
2-
import mock
34
import pytest
45

56

@@ -33,7 +34,7 @@ def mock_webhook(branch='main'):
3334

3435
@pytest.fixture
3536
def mock_webhook_object(branch='main'):
36-
webhook = mock.MagicMock()
37+
webhook = MagicMock()
3738
webhook.remote_addr = '192.30.252.0' # A real GitHub IP address
3839
webhook.json = {
3940
"ref": f'refs/heads/{branch}',
@@ -61,8 +62,8 @@ def mock_project_path():
6162

6263
# TODO: Move this to a fixture
6364
def mock_response(status=201, json_data={'mock': 'json'}):
64-
response = mock.MagicMock()
65-
response.json = mock.MagicMock(
65+
response = MagicMock()
66+
response.json = MagicMock(
6667
return_value=json_data,
6768
)
6869
response.status_code = status
@@ -81,8 +82,8 @@ def mock_config(pipeline='deploy', language='python', version='3.9', compose=Non
8182

8283
# TODO: Move this to a fixture
8384
def mock_response_container(status=200, dead=False, paused=False, restarting=False, running=True):
84-
response = mock.Mock()
85-
response.json = mock.Mock(
85+
response = Mock()
86+
response.json = Mock(
8687
return_value={
8788
'State': {
8889
'Dead': dead,

test/unit/test_app.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import harvey.app as app
2-
import mock
2+
from unittest.mock import patch
33
import pytest
44

55

@@ -17,15 +17,15 @@ def test_routes_are_reachable_get(mock_client, route):
1717
assert response.status_code == 200
1818

1919

20-
@mock.patch('harvey.webhooks.Webhook.parse_webhook')
20+
@patch('harvey.webhooks.Webhook.parse_webhook')
2121
def test_start_pipeline(mock_parse_webhook):
2222
# TODO: Long-term, test the status_code and logic
2323
app.start_pipeline()
2424

2525
mock_parse_webhook.assert_called_once()
2626

2727

28-
@mock.patch('harvey.webhooks.Webhook.parse_webhook')
28+
@patch('harvey.webhooks.Webhook.parse_webhook')
2929
def test_start_pipeline_compose(mock_parse_webhook):
3030
# TODO: Long-term, test the status_code and logic
3131
app.start_pipeline_compose()

test/unit/test_containers.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,25 @@
11
from test.unit.conftest import mock_response # Remove once fixtures are fixed
2+
from unittest.mock import patch
23

3-
import mock
44
from harvey.containers import Container
55
from harvey.globals import Global
66

77

8-
@mock.patch('requests.post', return_value=mock_response(status=201))
8+
@patch('requests.post', return_value=mock_response(status=201))
99
def test_create_container(mock_request, mock_tag):
1010
container = Container.create_container(mock_tag)
1111

1212
mock_request.assert_called_once_with(
1313
f'{Global.BASE_URL}containers/create',
1414
params={'name': mock_tag},
1515
json={'Image': mock_tag},
16-
headers=Global.JSON_HEADERS
16+
headers=Global.JSON_HEADERS,
1717
)
1818
assert container.json() == {'mock': 'json'}
1919
assert container.status_code == 201
2020

2121

22-
@mock.patch('requests.post', return_value=mock_response(status=204))
22+
@patch('requests.post', return_value=mock_response(status=204))
2323
def test_start_container(mock_request, mock_tag):
2424
container = Container.start_container(mock_tag)
2525

@@ -28,7 +28,7 @@ def test_start_container(mock_request, mock_tag):
2828
assert container.status_code == 204
2929

3030

31-
@mock.patch('requests.post', return_value=mock_response(status=204))
31+
@patch('requests.post', return_value=mock_response(status=204))
3232
def test_stop_container(mock_request, mock_tag):
3333
container = Container.stop_container(mock_tag)
3434

@@ -37,7 +37,7 @@ def test_stop_container(mock_request, mock_tag):
3737
assert container.status_code == 204
3838

3939

40-
@mock.patch('requests.get', return_value=mock_response(status=200))
40+
@patch('requests.get', return_value=mock_response(status=200))
4141
def test_inspect_container(mock_request, mock_tag):
4242
container = Container.inspect_container(mock_tag)
4343

@@ -46,7 +46,7 @@ def test_inspect_container(mock_request, mock_tag):
4646
assert container.status_code == 200
4747

4848

49-
@mock.patch('requests.get', return_value=mock_response(status=200))
49+
@patch('requests.get', return_value=mock_response(status=200))
5050
def test_list_containers(mock_request, mock_tag):
5151
container = Container.list_containers()
5252

@@ -55,17 +55,17 @@ def test_list_containers(mock_request, mock_tag):
5555
assert container.status_code == 200
5656

5757

58-
@mock.patch('requests.get', return_value=mock_response(status=200))
58+
@patch('requests.get', return_value=mock_response(status=200))
5959
def test_inspect_container_logs(mock_request):
6060
Container.inspect_container_logs(1)
6161

6262
mock_request.assert_called_once_with(
6363
f'{Global.BASE_URL}containers/1/logs',
64-
params={'stdout': True, 'stderr': True}
64+
params={'stdout': True, 'stderr': True},
6565
)
6666

6767

68-
@mock.patch('requests.post', return_value=mock_response(status=200))
68+
@patch('requests.post', return_value=mock_response(status=200))
6969
def test_wait_container(mock_request, mock_tag):
7070
container = Container.wait_container(mock_tag)
7171

@@ -74,14 +74,14 @@ def test_wait_container(mock_request, mock_tag):
7474
assert container.status_code == 200
7575

7676

77-
@mock.patch('requests.delete', return_value=mock_response(status=204))
77+
@patch('requests.delete', return_value=mock_response(status=204))
7878
def test_remove_container(mock_request, mock_tag):
7979
container = Container.remove_container(mock_tag)
8080

8181
mock_request.assert_called_once_with(
8282
f'{Global.BASE_URL}containers/{mock_tag}',
8383
json={'force': True},
84-
headers=Global.JSON_HEADERS
84+
headers=Global.JSON_HEADERS,
8585
)
8686
assert container.json() == {'mock': 'json'}
8787
assert container.status_code == 204

test/unit/test_git.py

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,68 +1,68 @@
11
import subprocess
2+
from unittest.mock import patch
23

3-
import mock
44
from harvey.git import Git
55

66

7-
@mock.patch('os.path.exists', return_value=True)
8-
@mock.patch('harvey.git.Git.pull_repo')
7+
@patch('os.path.exists', return_value=True)
8+
@patch('harvey.git.Git.pull_repo')
99
def test_update_git_repo_path_exists(mock_pull_repo, mock_path_exists, mock_project_path, mock_webhook): # noqa
1010
Git.update_git_repo(mock_webhook)
1111

1212
mock_pull_repo.assert_called_once_with(mock_project_path, mock_webhook)
1313

1414

15-
@mock.patch('os.path.exists', return_value=False)
16-
@mock.patch('harvey.git.Git.clone_repo')
17-
def test_update_git_repo_path_does_not_exist(mock_clone_repo, mock_path_exists, mock_project_path, mock_webhook): # noqa
15+
@patch('os.path.exists', return_value=False)
16+
@patch('harvey.git.Git.clone_repo')
17+
def test_update_git_repo_path_does_not_exist(mock_clone_repo, mock_path_exists, mock_project_path, mock_webhook):
1818
Git.update_git_repo(mock_webhook)
1919

2020
mock_clone_repo.assert_called_once_with(mock_project_path, mock_webhook)
2121

2222

23-
@mock.patch('subprocess.check_output')
23+
@patch('subprocess.check_output')
2424
def test_clone_repo(mock_subprocess, mock_project_path, mock_webhook):
2525
# TODO: Mock the subprocess better to ensure it does what it's supposed to
2626
Git.clone_repo(mock_project_path, mock_webhook)
2727

2828
mock_subprocess.assert_called_once()
2929

3030

31-
@mock.patch('harvey.utils.Utils.kill')
32-
@mock.patch('subprocess.check_output', side_effect=subprocess.TimeoutExpired(cmd=subprocess.check_output, timeout=0.1)) # noqa
33-
def test_clone_repo_subprocess_timeout(mock_subprocess, mock_utils_kill, mock_project_path, mock_webhook): # noqa
31+
@patch('harvey.utils.Utils.kill')
32+
@patch('subprocess.check_output', side_effect=subprocess.TimeoutExpired(cmd=subprocess.check_output, timeout=0.1))
33+
def test_clone_repo_subprocess_timeout(mock_subprocess, mock_utils_kill, mock_project_path, mock_webhook):
3434
Git.clone_repo(mock_project_path, mock_webhook)
3535

3636
mock_utils_kill.assert_called_once()
3737

3838

39-
@mock.patch('harvey.utils.Utils.kill')
40-
@mock.patch('subprocess.check_output', side_effect=subprocess.CalledProcessError(returncode=1, cmd=subprocess.check_output)) # noqa
41-
def test_clone_repo_process_error(mock_subprocess, mock_utils_kill, mock_project_path, mock_webhook): # noqa
39+
@patch('harvey.utils.Utils.kill')
40+
@patch('subprocess.check_output', side_effect=subprocess.CalledProcessError(returncode=1, cmd=subprocess.check_output))
41+
def test_clone_repo_process_error(mock_subprocess, mock_utils_kill, mock_project_path, mock_webhook):
4242
Git.clone_repo(mock_project_path, mock_webhook)
4343

4444
mock_utils_kill.assert_called_once()
4545

4646

47-
@mock.patch('subprocess.check_output')
47+
@patch('subprocess.check_output')
4848
def test_pull_repo(mock_subprocess, mock_project_path, mock_webhook):
4949
# TODO: Mock the subprocess better to ensure it does what it's supposed to
5050
Git.pull_repo(mock_project_path, mock_webhook)
5151

5252
mock_subprocess.assert_called_once()
5353

5454

55-
@mock.patch('harvey.utils.Utils.kill')
56-
@mock.patch('subprocess.check_output', side_effect=subprocess.TimeoutExpired(cmd=subprocess.check_output, timeout=0.1)) # noqa
57-
def test_pull_repo_subprocess_timeout(mock_subprocess, mock_utils_kill, mock_project_path, mock_webhook): # noqa
55+
@patch('harvey.utils.Utils.kill')
56+
@patch('subprocess.check_output', side_effect=subprocess.TimeoutExpired(cmd=subprocess.check_output, timeout=0.1))
57+
def test_pull_repo_subprocess_timeout(mock_subprocess, mock_utils_kill, mock_project_path, mock_webhook):
5858
Git.pull_repo(mock_project_path, mock_webhook)
5959

6060
mock_utils_kill.assert_called_once()
6161

6262

63-
@mock.patch('harvey.utils.Utils.kill')
64-
@mock.patch('subprocess.check_output', side_effect=subprocess.CalledProcessError(returncode=1, cmd=subprocess.check_output)) # noqa
65-
def test_pull_repo_process_error(mock_subprocess, mock_utils_kill, mock_project_path, mock_webhook): # noqa
63+
@patch('harvey.utils.Utils.kill')
64+
@patch('subprocess.check_output', side_effect=subprocess.CalledProcessError(returncode=1, cmd=subprocess.check_output))
65+
def test_pull_repo_process_error(mock_subprocess, mock_utils_kill, mock_project_path, mock_webhook):
6666
Git.pull_repo(mock_project_path, mock_webhook)
6767

6868
mock_utils_kill.assert_called_once()

test/unit/test_images.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
from test.unit.conftest import mock_response # Remove once fixtures are fixed
2+
from unittest.mock import patch
23

3-
import mock
44
import pytest
55
from harvey.globals import Global
66
from harvey.images import Image
77

88

9-
@pytest.mark.parametrize('context', [('test'), (None)])
10-
@mock.patch('subprocess.check_output')
9+
@pytest.mark.parametrize('context', ['test', (None)])
10+
@patch('subprocess.check_output')
1111
def test_build_image(mock_subprocess, context, mock_webhook):
1212
# TODO: Mock the subprocess better to ensure it does what it's supposed to
1313
Image.build_image(
@@ -17,32 +17,32 @@ def test_build_image(mock_subprocess, context, mock_webhook):
1717
'version': '3.9',
1818
},
1919
mock_webhook,
20-
context
20+
context,
2121
)
2222

2323
mock_subprocess.assert_called_once()
2424

2525

26-
@mock.patch('requests.get', return_value=mock_response(201))
26+
@patch('requests.get', return_value=mock_response(201))
2727
def test_retrieve_image(mock_request):
2828
Image.retrieve_image(1)
2929

3030
mock_request.assert_called_once_with(Global.BASE_URL + 'images/1/json')
3131

3232

33-
@mock.patch('requests.get', return_value=mock_response(201))
33+
@patch('requests.get', return_value=mock_response(201))
3434
def test_retrieve_all_images(mock_request):
3535
Image.retrieve_all_images()
3636

3737
mock_request.assert_called_once_with(Global.BASE_URL + 'images/json')
3838

3939

40-
@mock.patch('requests.delete', return_value=mock_response(201))
40+
@patch('requests.delete', return_value=mock_response(201))
4141
def test_remove_image(mock_request):
4242
Image.remove_image(1)
4343

4444
mock_request.assert_called_once_with(
4545
Global.BASE_URL + 'images/1',
4646
json={'force': True},
47-
headers=Global.JSON_HEADERS
47+
headers=Global.JSON_HEADERS,
4848
)

0 commit comments

Comments
 (0)