Skip to content

Commit

Permalink
Bug Fixes from Recent Merges (#21)
Browse files Browse the repository at this point in the history
  • Loading branch information
ckrew authored Feb 2, 2024
1 parent 7248750 commit 9ba5da0
Show file tree
Hide file tree
Showing 9 changed files with 32 additions and 29 deletions.
3 changes: 2 additions & 1 deletion .coveragerc
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ omit =
*urls.py,
*wsgi.py,
manage.py,
*workspaces/*
*workspaces/*,
*/.tethys/*
2 changes: 1 addition & 1 deletion .flake8
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[flake8]
max-line-length = 120
exclude = tethysapp/app_store/workspaces/
exclude = *tethysapp/app_store/workspaces/

3 changes: 3 additions & 0 deletions tethysapp/app_store/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,9 @@ def get_conda_stores(active_only=False, conda_channels="all", sensitive_info=Fal
available_stores = [store for store in available_stores if store['conda_channel'] in conda_channels]

for store in available_stores:
if isinstance(store['conda_labels'], str):
store['conda_labels'] = store['conda_labels'].split(",")

if not sensitive_info:
del store['github_token']
del store['github_organization']
Expand Down
3 changes: 2 additions & 1 deletion tethysapp/app_store/notifications.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,9 @@ async def receive(self, text_data):
module_name = sys.modules[__name__]
args = [text_data_json['data'], self.channel_layer]

app_workspace_functions = ['begin_install', 'restart_server', 'get_log_file', 'process_branch'
app_workspace_functions = ['begin_install', 'restart_server', 'get_log_file', 'process_branch',
'initialize_local_repo_for_active_stores', 'update_app', 'uninstall_app']

if function_name in app_workspace_functions:
app_workspace = await sync_to_async(get_app_workspace, thread_sensitive=True)(app)
args.append(app_workspace)
Expand Down
3 changes: 1 addition & 2 deletions tethysapp/app_store/public/js/addModalHelpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ const addModalHelper = {
$("#loaderEllipsis").hide()
$("#fetchRepoButton").hide()
$("#loadingTextAppSubmit").text("")
disableModalInput(disable_email=true, disable_gihuburl=true, disable_channels=true, disable_labels=true)

if (!("branches" in branchesData)) {
sendNotification(
Expand Down Expand Up @@ -259,7 +258,7 @@ const getRepoForAdd = () => {
$("#loaderEllipsis").show()
$("#fetchRepoButton").prop("disabled", true)
$("#loadingTextAppSubmit").text("Please wait. Fetching GitHub Repo")

disableModalInput(disable_email=true, disable_gihuburl=true, disable_channels=true, disable_labels=true)
notification_ws.send(
JSON.stringify({
data: {
Expand Down
2 changes: 1 addition & 1 deletion tethysapp/app_store/submission_handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -565,7 +565,6 @@ def process_branch(install_data, channel_layer, app_workspace):
files_changed = False
app_github_dir = get_gitsubmission_app_dir(app_workspace, app_name, conda_channel)
repo = git.Repo(app_github_dir)
setup_path = get_setup_path(app_github_dir)

# 2. Get sensitive information for store
conda_store = get_conda_stores(conda_channels=conda_channel, sensitive_info=True)[0]
Expand All @@ -580,6 +579,7 @@ def process_branch(install_data, channel_layer, app_workspace):
origin = repo.remote(name='origin')
repo.git.checkout(branch)
origin.pull()
setup_path = get_setup_path(app_github_dir)
setup_path_data = parse_setup_file(setup_path)
current_version = generate_current_version(setup_path_data)

Expand Down
11 changes: 7 additions & 4 deletions tethysapp/app_store/tests/unit_tests/test_helpers.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import pytest
import shutil
from pathlib import Path
from unittest.mock import MagicMock
from unittest.mock import MagicMock, call
from tethysapp.app_store.helpers import (parse_setup_file, get_conda_stores, check_all_present, run_process,
send_notification, apply_template, get_github_install_metadata,
get_override_key, get_color_label_dict, get_setup_path)
Expand Down Expand Up @@ -48,14 +48,16 @@ def test_run_process(mocker, caplog):


def test_send_notification(mocker):
channel_layer = MagicMock(group_send="some_function")
mock_group_send = MagicMock()
channel_layer = MagicMock(group_send=mock_group_send)
mock_async_to_sync = mocker.patch('tethysapp.app_store.helpers.async_to_sync')
msg = "testing functionality"

send_notification(msg, channel_layer)

expected_args = ["notifications", {"type": "install_notifications", "message": msg}]
assert mock_async_to_sync.some_function.called_once_with(expected_args)
expected_args = ("notifications", {"type": "install_notifications", "message": msg})
assert call(mock_group_send) == mock_async_to_sync.mock_calls[0]
assert expected_args in mock_async_to_sync.mock_calls[-1]


def test_apply_template(app_files_dir, tmp_path):
Expand Down Expand Up @@ -153,6 +155,7 @@ def test_get_conda_stores(mocker, store):
mock_app = mocker.patch('tethysapp.app_store.helpers.app')
encryption_key = 'fake_encryption_key'
active_store = store('active_default')
active_store['conda_labels'] = "main"
inactive_store = store("inactive_not_default", default=False, active=False)
mock_app.get_custom_setting.side_effect = [{'stores': [active_store, inactive_store]}, encryption_key]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def test_get_service_options(mocker):
expected_services = [{"name": "service_setting", "id": 1}]
assert services == expected_services
expected_args = Namespace(spatial=True)
assert mock_services_list_command.called_with(expected_args)
mock_services_list_command.asserrt_called_with(expected_args)


def test_restart_server_dev_server(mocker, caplog, tmp_path):
Expand Down
32 changes: 14 additions & 18 deletions tethysapp/app_store/tests/unit_tests/test_submission_handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import os
import filecmp
from unittest.mock import call, MagicMock
from pytest_lazy_fixtures import lf
from github.GithubException import UnknownObjectException, BadCredentialsException
from tethysapp.app_store.submission_handlers import (update_anaconda_dependencies, get_github_repo,
initialize_local_repo_for_active_stores, initialize_local_repo,
Expand Down Expand Up @@ -89,7 +90,7 @@ def test_repo_does_not_exist(mocker, caplog):

@pytest.mark.parametrize(
"stores, expected_call_count", [
(pytest.lazy_fixture("all_active_stores"), 2)])
(lf("all_active_stores"), 2)])
def test_initialize_local_repo_for_active_stores(stores, expected_call_count, mocker):
install_data = {
"url": "https://github.com/notrealorg/fakeapp",
Expand All @@ -116,33 +117,30 @@ def test_initialize_local_repo_fresh(store, tmp_path, mocker):
mock_branch1.name = 'origin/commit1'
mock_branch2 = MagicMock()
mock_branch2.name = 'origin/commit2'
mock_git = mocker.patch('git.Repo.init', side_effect=[mock_repo])
mocker.patch('git.Repo.init', side_effect=[mock_repo])
mock_ws = mocker.patch('tethysapp.app_store.submission_handlers.send_notification')

mock_repo.remote().refs = [mock_branch1, mock_branch2]
initialize_local_repo(github_url, active_store, channel_layer, app_workspace)

expected_github_dur = tmp_path / "gitsubmission" / active_store['conda_channel']
expected_app_github_dur = expected_github_dur / "fakeapp"
assert expected_github_dur.is_dir()

mock_git.create_remote.called_with(['origin', github_url])
mock_git.create_remote().fetch.called_once()
mock_repo.create_remote.assert_called_with('origin', github_url)
mock_repo.create_remote().fetch.assert_called_once()

expected_data_json = {
"data": {
"branches": ["commit1", "commit2"],
"github_dir": expected_app_github_dur,
'app_name': 'fakeapp',
"conda_channel": active_store['conda_channel'],
"github_token": active_store['github_token'],
"conda_labels": active_store['conda_labels'],
"github_organization": active_store['github_organization']
"conda_labels": active_store['conda_labels']
},
"jsHelperFunction": "showBranches",
"helper": "addModalHelper"
}

mock_ws.called_with([expected_data_json, channel_layer])
mock_ws.assert_called_with(expected_data_json, channel_layer)


def test_initialize_local_repo_already_exists(store, tmp_path, mocker):
Expand All @@ -159,31 +157,29 @@ def test_initialize_local_repo_already_exists(store, tmp_path, mocker):
mock_branch1.name = 'origin/commit1'
mock_branch2 = MagicMock()
mock_branch2.name = 'origin/commit2'
mock_git = mocker.patch('git.Repo.init', side_effect=[mock_repo])
mocker.patch('git.Repo.init', side_effect=[mock_repo])
mock_ws = mocker.patch('tethysapp.app_store.submission_handlers.send_notification')

mock_repo.remote().refs = [mock_branch1, mock_branch2]
initialize_local_repo(github_url, active_store, channel_layer, app_workspace)

assert expected_github_dur.is_dir()

mock_git.create_remote.called_with(['origin', github_url])
mock_git.create_remote().fetch.called_once()
mock_repo.create_remote.assert_called_with('origin', github_url)
mock_repo.create_remote().fetch.assert_called_once()

expected_data_json = {
"data": {
"branches": ["commit1", "commit2"],
"github_dir": expected_app_github_dur,
'app_name': 'fakeapp',
"conda_channel": active_store['conda_channel'],
"github_token": active_store['github_token'],
"conda_labels": active_store['conda_labels'],
"github_organization": active_store['github_organization']
"conda_labels": active_store['conda_labels']
},
"jsHelperFunction": "showBranches",
"helper": "addModalHelper"
}

mock_ws.called_with([expected_data_json, channel_layer])
mock_ws.assert_called_with(expected_data_json, channel_layer)


@pytest.mark.parametrize(
Expand Down

0 comments on commit 9ba5da0

Please sign in to comment.