From 601f5a3152e53667d697a6b6ed56d77fcd8bc397 Mon Sep 17 00:00:00 2001 From: sdc50 Date: Tue, 26 Sep 2023 12:03:22 -0600 Subject: [PATCH] tests add micro metayaml update ci --- .github/workflows/tethys-release.yml | 42 +++++++ .github/workflows/tethys.yml | 41 ++++++- .gitignore | 3 +- conda.recipe/meta.yaml | 107 ------------------ .../test_tethys_cli/test_db_commands.py | 17 ++- .../test_tethys_portal/test_urls.py | 32 ++++++ tethys_cli/gen_commands.py | 14 ++- tethys_cli/gen_templates/metayaml | 2 +- tethys_portal/urls.py | 6 +- 9 files changed, 148 insertions(+), 116 deletions(-) delete mode 100644 conda.recipe/meta.yaml diff --git a/.github/workflows/tethys-release.yml b/.github/workflows/tethys-release.yml index 20f9174cd..78a0ef038 100644 --- a/.github/workflows/tethys-release.yml +++ b/.github/workflows/tethys-release.yml @@ -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; diff --git a/.github/workflows/tethys.yml b/.github/workflows/tethys.yml index eddb9c422..e91e8bc45 100644 --- a/.github/workflows/tethys.yml +++ b/.github/workflows/tethys.yml @@ -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' }} @@ -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." diff --git a/.gitignore b/.gitignore index 23dcfa07b..4769a8d17 100644 --- a/.gitignore +++ b/.gitignore @@ -34,4 +34,5 @@ build/ dist/ tethys_portal/_version.py # Required for docs build -git-lfs-*/* \ No newline at end of file +git-lfs-*/* +/conda.recipe/meta.yaml diff --git a/conda.recipe/meta.yaml b/conda.recipe/meta.yaml deleted file mode 100644 index e1eccd748..000000000 --- a/conda.recipe/meta.yaml +++ /dev/null @@ -1,107 +0,0 @@ -# Conda Recipe for Tethys Platform -# WARNING: THIS IS A GENERATED FILE. DO NOT EDIT. -# TO CHANGE THIS FILE, SEE $TETHYS_SRC/tethys_cli/gen_templates/meta yaml - - -package: - name: tethys-platform - version: 3.4.1.dev24+gb092a0af.d20220421 - -source: - path: .. - -build: - number: 0 - string: {% if environ.get('GIT_DESCRIBE_NUMBER', 0)|int > 0 %}dev{{ GIT_BUILD_STR }}{% endif %} - noarch: python - script: python -m pip install --no-deps --ignore-installed . - entry_points: - - tethys = tethys_cli:tethys_command - -requirements: - build: - - python - - pbr - run: - - python - - pycrypto - - pyopenssl - - docker-py - - distro - - postgresql - - psycopg2 - - sqlalchemy - - geoalchemy2 - - plotly - - bokeh - - tethys_dataset_services>=2.0.0 - - hs_restclient - - owslib - - requests - - dask - - tethys_dask_scheduler>=1.0.2 - - service_identity - - condorpy - - siphon - - python-jose - - pyjwt<2.0.0 - - arrow - - isodate - - django=3.2.* - - channels=3.* - - daphne=3.* - - django-analytical - - django-axes - - django-filter - - djangorestframework - - django-bootstrap5 - - django-model-utils - - django-guardian - - django-gravatar2 - - django-mfa2 - - django-recaptcha2 - - django-simple-captcha - - django-session-security - - django-termsandconditions - - social-auth-app-django - - selenium - - coverage - - factory_boy - - pillow - - pip - - future - - flake8 - - git - - setuptools_scm - - openssl<3.0.0 - - conda - - -test: - imports: - - tethys_apps - - tethys_cli - - tethys_compute - - tethys_config - - tethys_gizmos - - tethys_portal - - tethys_quotas - - tethys_sdk - - tethys_services - -about: - license: BSD-2-Clause - license_family: BSD - license_file: LICENSE - summary: Primary Tethys Platform Django Site Project - description: | - Tethys Platform provides both a development environment - and a hosting environment for scientific web applications. - home: https://www.tethysplatform.org - doc_url: http://docs.tethysplatform.org - dev_url: https://github.com/tethysplatform/tethys - -extra: - recipe-maintainers: - - sdc50 - - swainn \ No newline at end of file diff --git a/tests/unit_tests/test_tethys_cli/test_db_commands.py b/tests/unit_tests/test_tethys_cli/test_db_commands.py index 34cf8f128..dc8436ec5 100644 --- a/tests/unit_tests/test_tethys_cli/test_db_commands.py +++ b/tests/unit_tests/test_tethys_cli/test_db_commands.py @@ -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() diff --git a/tests/unit_tests/test_tethys_portal/test_urls.py b/tests/unit_tests/test_tethys_portal/test_urls.py index 836a8eba4..fd3479cdd 100644 --- a/tests/unit_tests/test_tethys_portal/test_urls.py +++ b/tests/unit_tests/test_tethys_portal/test_urls.py @@ -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) diff --git a/tethys_cli/gen_commands.py b/tethys_cli/gen_commands.py index bfe4d2c7c..2610a9a5b 100644 --- a/tethys_cli/gen_commands.py +++ b/tethys_cli/gen_commands.py @@ -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", @@ -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="", @@ -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) @@ -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 diff --git a/tethys_cli/gen_templates/metayaml b/tethys_cli/gen_templates/metayaml index 5dcd418cd..9cc998f75 100644 --- a/tethys_cli/gen_templates/metayaml +++ b/tethys_cli/gen_templates/metayaml @@ -4,7 +4,7 @@ package: - name: tethys-platform + name: {{ package_name }} version: {{ tethys_version }} source: diff --git a/tethys_portal/urls.py b/tethys_portal/urls.py index be3515fb7..6beea748b 100644 --- a/tethys_portal/urls.py +++ b/tethys_portal/urls.py @@ -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()