Skip to content

Commit

Permalink
tests
Browse files Browse the repository at this point in the history
add micro metayaml
update ci
  • Loading branch information
sdc50 committed Sep 26, 2023
1 parent 68c213c commit 601f5a3
Show file tree
Hide file tree
Showing 9 changed files with 148 additions and 116 deletions.
42 changes: 42 additions & 0 deletions .github/workflows/tethys-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -173,3 +173,45 @@ jobs:
conda activate tethys;
echo "Publishing to dev channel...";
anaconda -t "${{ secrets.CONDA_UPLOAD_TOKEN }}" upload -u ${{ secrets.CONDA_UPLOAD_USER }} -l dev $CONDA_BLD_PATH/noarch/tethys-platform*.tar.bz2 --force;
# BUILD micro-tethys-platform

# Generate Conda Recipe With Constrained Dependencies
- name: Generate Conda Recipe - micro
run: |
cd ..
. ~/miniconda/etc/profile.d/conda.sh;
conda activate tethys;
tethys gen metayaml -p minor --micro --overwrite;
# Show Tethys Meta
- name: Show Tethys Meta - micro
run: |
cd ..
cat ./tethys/conda.recipe/meta.yaml
# Build Conda
- name: Build Conda - micro
run: |
cd ..
. ~/miniconda/etc/profile.d/conda.sh;
conda create -y -c conda-forge -n conda-build conda-build anaconda-client
conda activate conda-build
conda config --set anaconda_upload no
mkdir -p ~/conda-bld
conda-build -c tethysplatform -c conda-forge ./tethys/conda.recipe
# Upload to Anaconda Cloud
- name: Upload to Conda Release Channel - micro
if: ${{ steps.version.outputs.prerelease == '' }}
run: |
cd ..
. ~/miniconda/etc/profile.d/conda.sh;
conda activate tethys;
echo "Publishing to release channel...";
anaconda -t "${{ secrets.CONDA_UPLOAD_TOKEN }}" upload -u ${{ secrets.CONDA_UPLOAD_USER }} $CONDA_BLD_PATH/noarch/micro-tethys-platform*.tar.bz2 --force;
- name: Upload to Conda Dev Channel - micro
if: ${{ steps.version.outputs.prerelease != '' }}
run: |
cd ..
. ~/miniconda/etc/profile.d/conda.sh;
conda activate tethys;
echo "Publishing to dev channel...";
anaconda -t "${{ secrets.CONDA_UPLOAD_TOKEN }}" upload -u ${{ secrets.CONDA_UPLOAD_USER }} -l dev $CONDA_BLD_PATH/noarch/micro-tethys-platform*.tar.bz2 --force;
41 changes: 40 additions & 1 deletion .github/workflows/tethys.yml
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ jobs:
conda activate conda-build
conda config --set anaconda_upload no
mkdir -p ~/conda-bld
conda-build -c tethysplatform -c conda-forge ./tethys/conda.recipe
conda-build -c conda-forge ./tethys/conda.recipe
# Upload Conda No Pull Request No Tag
- name: Upload Conda No Tag
if: ${{ github.event_name != 'pull_request' }}
Expand All @@ -232,3 +232,42 @@ jobs:
if: ${{ github.event_name == 'pull_request' }}
run: |
echo "Uploading is skipped for pull requests."
# BUILD micro-tethys-platform

# Generate Conda Recipe Without Constrained Dependencies
- name: Generate Conda Recipe - micro
run: |
cd ..
. ~/miniconda/etc/profile.d/conda.sh;
conda activate tethys;
tethys gen metayaml --micro --overwrite;
# Show Tethys Meta
- name: Show Tethys Meta - micro
run: |
cd ..
cat ./tethys/conda.recipe/meta.yaml
# Build Conda
- name: Build Conda - micro
run: |
cd ..
. ~/miniconda/etc/profile.d/conda.sh;
conda create -y -c conda-forge -n conda-build conda-build anaconda-client
conda activate conda-build
conda config --set anaconda_upload no
mkdir -p ~/conda-bld
conda-build -c conda-forge ./tethys/conda.recipe
# Upload Conda No Pull Request No Tag
- name: Upload Conda No Tag - micro
if: ${{ github.event_name != 'pull_request' }}
run: |
cd ..
. ~/miniconda/etc/profile.d/conda.sh;
ls ~/conda-bld/noarch
conda activate conda-build
anaconda -t "${{ secrets.CONDA_UPLOAD_TOKEN }}" upload -u ${{ secrets.CONDA_UPLOAD_USER }} -l dev $CONDA_BLD_PATH/noarch/micro-tethys-platform*.tar.bz2 --force;
# No Upload if Pull Request
- name: No Upload - micro
if: ${{ github.event_name == 'pull_request' }}
run: |
echo "Uploading is skipped for pull requests."
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,5 @@ build/
dist/
tethys_portal/_version.py
# Required for docs build
git-lfs-*/*
git-lfs-*/*
/conda.recipe/meta.yaml
107 changes: 0 additions & 107 deletions conda.recipe/meta.yaml

This file was deleted.

17 changes: 16 additions & 1 deletion tests/unit_tests/test_tethys_cli/test_db_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -379,10 +379,25 @@ def test_db_command_createsuperuser(
f'Tethys Portal Superuser "{portal_superuser}" already exists.'
)

@mock.patch("tethys_cli.db_commands.create_portal_superuser")
@mock.patch("tethys_cli.db_commands.migrate_tethys_db")
@mock.patch("tethys_cli.db_commands.Path")
def test_db_command_configure_sqlite(
self, mock_Path, mock_migrate, mock_createsuperuser
):
mock_args = mock.MagicMock()
mock_args.command = "configure"
self.mock_process_args.return_value["db_engine"] = "sqlite"
db_command(mock_args)
kwargs = self._get_kwargs()
mock_Path.assert_called_with(kwargs["db_name"])
mock_migrate.assert_called_with(**self.options)
mock_createsuperuser.assert_called_with(**self.options)

@mock.patch("tethys_cli.db_commands.create_portal_superuser")
@mock.patch("tethys_cli.db_commands.migrate_tethys_db")
@mock.patch("tethys_cli.db_commands._prompt_if_error")
def test_db_command_configure(
def test_db_command_configure_postgres(
self, mock_prompt_err, mock_migrate, mock_createsuperuser
):
mock_args = mock.MagicMock()
Expand Down
32 changes: 32 additions & 0 deletions tests/unit_tests/test_tethys_portal/test_urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -411,3 +411,35 @@ def test_custom_register_controller_not_class_based_view(
self.assertEqual(tethys_portal.urls.register_controller_setting, "test")
self.assertEqual(tethys_portal.urls.register_controller, mock_controller)
mock_func_extractor.assert_called_once()

@override_settings(
ADDITIONAL_URLPATTERNS=["my.test.urlpatterns"],
PREFIX_URL=None,
LOGIN_URL=None,
)
@mock.patch(
"importlib.import_module", return_value=mock.MagicMock(urlpatterns=["re_path"])
)
def test_additional_urls(
self,
mock_import_module,
):
import tethys_portal.urls
from importlib import reload

reload(tethys_portal.urls)
mock_import_module.assert_called_with("my.test")
self.assertEqual(tethys_portal.urls.additional_url_patterns, ["re_path"])
self.assertEqual(tethys_portal.urls.urlpatterns[0], "re_path")

@override_settings(ADDITIONAL_URLPATTERNS=["my.test.urlpatterns"])
@mock.patch("tethys_portal.urls.logging.getLogger")
def test_additional_urls_exception(
self,
mock_logger,
):
import tethys_portal.urls
from importlib import reload

reload(tethys_portal.urls)
self.assertEqual(mock_logger().exception.call_count, 2)
14 changes: 12 additions & 2 deletions tethys_cli/gen_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,11 @@ def add_gen_parser(subparsers):
help='Level to pin dependencies when generating the meta.yaml. One of "major", "minor", '
'"patch", or "none". Defaults to "none".',
)
gen_parser.add_argument(
"--micro",
action="store_true",
help="Use micro-tethys dependencies when generating the meta.yaml.",
)
gen_parser.add_argument(
"--client-max-body-size",
dest="client_max_body_size",
Expand Down Expand Up @@ -196,6 +201,7 @@ def add_gen_parser(subparsers):
server_port=None,
overwrite=False,
pin_level="none",
micro=False,
ssl=False,
ssl_cert="",
ssl_key="",
Expand Down Expand Up @@ -424,7 +430,9 @@ def derive_version_from_conda_environment(dep_str, level="none"):


def gen_meta_yaml(args):
environment_file_path = os.path.join(TETHYS_SRC, "environment.yml")
filename = "min_env.yml" if args.micro else "environment.yml"
package_name = "micro-tethys-platform" if args.micro else "tethys-platform"
environment_file_path = os.path.join(TETHYS_SRC, filename)
with open(environment_file_path, "r") as env_file:
environment = yaml.safe_load(env_file)

Expand All @@ -441,7 +449,9 @@ def gen_meta_yaml(args):
run_requirements.append(dependency)

context = dict(
run_requirements=run_requirements, tethys_version=tethys_portal.__version__
run_requirements=run_requirements,
tethys_version=tethys_portal.__version__,
package_name=package_name,
)
return context

Expand Down
2 changes: 1 addition & 1 deletion tethys_cli/gen_templates/metayaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@


package:
name: tethys-platform
name: {{ package_name }}
version: {{ tethys_version }}

source:
Expand Down
6 changes: 3 additions & 3 deletions tethys_portal/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,12 @@
logger = logging.getLogger(f"tethys.{__name__}")


prefix_url = f"{settings.PREFIX_URL}"
login_url_setting = f"{settings.LOGIN_URL}"
prefix_url = settings.PREFIX_URL
login_url_setting = settings.LOGIN_URL
admin.site.login = staff_member_required(
admin.site.login,
redirect_field_name="",
login_url=f"{login_url_setting}",
login_url=login_url_setting,
)

admin.autodiscover()
Expand Down

0 comments on commit 601f5a3

Please sign in to comment.