Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implements Tethys Reactpy App Scaffold #1081

Open
wants to merge 38 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 34 commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
67b2098
Reactpy configured at the baseline-level
shawncrawley May 13, 2024
b16676e
Merge branch 'main' into tethys-reactpy
ckrew May 14, 2024
a585699
Added RESelectInput react component to create a reach dropdown just l…
ckrew May 16, 2024
debe2a4
Integrates reactpy and implements app scaffold
shawncrawley Aug 17, 2024
0c9ecc4
Merge branch 'main' into tethys-reactpy
shawncrawley Aug 17, 2024
f6cc1a9
Handle reactpy-django at app install level
shawncrawley Aug 19, 2024
9324df4
Bugfixes from fresh test
shawncrawley Aug 19, 2024
521eef0
Initial wave of tests and resulting refactors/fixes
shawncrawley Aug 23, 2024
55e31f9
Adds tests and test-based fixes
shawncrawley Aug 29, 2024
645e4de
Merge branch 'main' into tethys-reactpy
shawncrawley Aug 29, 2024
80eea3d
Fix broken tests on Windows, flake8 cleanup
shawncrawley Aug 29, 2024
408b7ab
Applies black formatting
shawncrawley Aug 29, 2024
fdfb0a5
Try fixing async test
shawncrawley Aug 29, 2024
dc93f59
Fix flake8 warning
shawncrawley Aug 29, 2024
5628657
Tweak test for macos
shawncrawley Aug 29, 2024
33e0632
Another tweak for tests on macos
shawncrawley Aug 29, 2024
4640634
Fix broken test from last commit
shawncrawley Aug 29, 2024
af5cb81
black reformatting
shawncrawley Aug 29, 2024
3e59a05
Unpin daphne version
shawncrawley Sep 5, 2024
3c67bcc
Merge branch 'main' into tethys-reactpy
shawncrawley Sep 6, 2024
8d48e47
Bugfix: Default arg must be passed to scaffold_command
shawncrawley Sep 11, 2024
79e44ad
applies suggested changes
shawncrawley Oct 3, 2024
64732c5
Merge branch 'main' into tethys-reactpy
shawncrawley Oct 3, 2024
b5493d2
Revert spot where os.path had been converted to pathlib.Path
shawncrawley Oct 3, 2024
4c9697b
Remove erroneous argument
shawncrawley Oct 3, 2024
ae1d688
Fix bug with pathlib update to static_finders
shawncrawley Oct 7, 2024
46b4f83
Update tests/unit_tests/test_tethys_apps/test_template_loaders.py
shawncrawley Oct 11, 2024
1bdcdcf
Update tethys_cli/cli_helpers.py
shawncrawley Oct 11, 2024
f7af003
Merge branch 'main' into tethys-reactpy
shawncrawley Oct 11, 2024
b6178b8
Merge branch 'main' into tethys-reactpy
swainn Oct 16, 2024
9122f42
Additional tweaks per feedback
shawncrawley Oct 17, 2024
305a910
black and flake8
shawncrawley Oct 17, 2024
0718fd5
remove file that was unintentionally committed
shawncrawley Oct 17, 2024
d898438
Fixes pyproject.toml_tmpl for reacpty scaffold
shawncrawley Oct 19, 2024
f0e00e9
Update tethys_apps/base/url_map.py
shawncrawley Oct 22, 2024
01bdf94
Implements latest feedback from @swainn
shawncrawley Oct 22, 2024
8a810af
Additional tweaks per feedback/tests
shawncrawley Oct 23, 2024
8ab53d4
Fix broken test
shawncrawley Oct 23, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/tethys.yml
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ jobs:
run: |
cd ..
. ~/miniconda/etc/profile.d/conda.sh;
conda create -y -c conda-forge -n conda-build conda-build anaconda-client
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
Expand Down Expand Up @@ -259,7 +259,7 @@ jobs:
run: |
cd ..
. ~/miniconda/etc/profile.d/conda.sh;
conda create -y -c conda-forge -n conda-build conda-build anaconda-client
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
Expand Down
12 changes: 6 additions & 6 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@
#
# All configuration values have a default; values that are commented out
# serve to show the default.
import os
import sys
import subprocess
from dataclasses import asdict
from os import environ
from pathlib import Path
from unittest import mock

Expand Down Expand Up @@ -106,7 +106,7 @@ def __getattr__(cls, name):
# patcher.start()

# Fixes django settings module problem
sys.path.insert(0, os.path.abspath(".."))
sys.path.insert(0, Path("..").absolute().resolve())

installed_apps = [
"django.contrib.admin",
Expand Down Expand Up @@ -165,7 +165,7 @@ def __getattr__(cls, name):
copyright = "2023, Tethys Platform"

# on_rtd is whether we are on readthedocs.org, this line of code grabbed from docs.readthedocs.org
on_rtd = os.environ.get("READTHEDOCS") == "True"
on_rtd = environ.get("READTHEDOCS") == "True"

# The version info for the project you're documenting, acts as replacement for
# |version| and |release|, also used in various other places throughout the
Expand All @@ -178,7 +178,7 @@ def __getattr__(cls, name):
print(f'Using simplified version "{version}"')

# Determine branch
git_directory = Path(__file__).parent.parent
git_directory = Path(__file__).parents[1]
ret = subprocess.run(
["git", "-C", git_directory, "rev-parse", "--abbrev-ref", "HEAD"],
capture_output=True,
Expand Down Expand Up @@ -256,10 +256,10 @@ def __getattr__(cls, name):
todo_emit_warnings = True

# Define the canonical URL if you are using a custom domain on Read the Docs
html_baseurl = os.environ.get("READTHEDOCS_CANONICAL_URL", "")
html_baseurl = environ.get("READTHEDOCS_CANONICAL_URL", "")

# Tell Jinja2 templates the build is running on Read the Docs
if os.environ.get("READTHEDOCS", "") == "True":
if environ.get("READTHEDOCS", "") == "True":
if "html_context" not in globals():
html_context = {}
html_context["READTHEDOCS"] = True
Expand Down
7 changes: 5 additions & 2 deletions environment.yml
shawncrawley marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ dependencies:

# core dependencies
- django>=3.2,<6
- channels
- daphne
- channels["daphne"]
shawncrawley marked this conversation as resolved.
Show resolved Hide resolved
- setuptools_scm
- pip
- requests # required by lots of things
Expand Down Expand Up @@ -105,3 +104,7 @@ dependencies:
- factory_boy
- flake8
- flake8-bugbear

# reactpy dependencies
- pip:
- reactpy-django
shawncrawley marked this conversation as resolved.
Show resolved Hide resolved
3 changes: 1 addition & 2 deletions micro_environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@ dependencies:

# core dependencies
- django>=3.2,<6
- channels
- daphne
- channels["daphne"]
- setuptools_scm
- pip
- requests # required by lots of things
Expand Down
2 changes: 1 addition & 1 deletion tests/apps/tethysapp-test_app/install-with-post.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ requirements:
- geojson
- shapely
post:
- ./test.sh
- ./test.py
1 change: 1 addition & 0 deletions tests/apps/tethysapp-test_app/test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
print("test")
1 change: 0 additions & 1 deletion tests/apps/tethysapp-test_app/test.sh

This file was deleted.

1 change: 1 addition & 0 deletions tests/coverage.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
[run]
source = $TETHYS_TEST_DIR/../tethys_apps
$TETHYS_TEST_DIR/../tethys_cli
$TETHYS_TEST_DIR/../tethys_components
$TETHYS_TEST_DIR/../tethys_compute
$TETHYS_TEST_DIR/../tethys_config
$TETHYS_TEST_DIR/../tethys_gizmos
Expand Down
6 changes: 3 additions & 3 deletions tests/unit_tests/test_tethys_apps/test_admin.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import os
from pathlib import Path
import unittest
from unittest import mock
from django.db.utils import ProgrammingError
Expand Down Expand Up @@ -47,8 +47,8 @@ class TestTethysAppAdmin(unittest.TestCase):
def setUp(self):
from tethys_apps.models import TethysApp

self.src_dir = os.path.dirname(os.path.dirname(os.path.dirname(__file__)))
self.root_app_path = os.path.join(self.src_dir, "apps", "tethysapp-test_app")
self.src_dir = Path(__file__).parents[1]
self.root_app_path = self.src_dir / "apps" / "tethysapp-test_app"
self.app_model = TethysApp(name="admin_test_app", package="admin_test_app")
self.app_model.save()
self.proxy_app_model = ProxyApp(
Expand Down
34 changes: 34 additions & 0 deletions tests/unit_tests/test_tethys_apps/test_base/test_app_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from django.db.utils import ProgrammingError
from django.test import RequestFactory, override_settings
from django.core.exceptions import ValidationError, ObjectDoesNotExist
from argparse import Namespace

from tethys_apps.exceptions import (
TethysAppSettingDoesNotExist,
Expand Down Expand Up @@ -1543,3 +1544,36 @@ def test_remove_from_db_2(self, mock_ta, mock_log):

# Check tethys log error
mock_log.error.assert_called()

def test_navigation_links_not_auto(self):
app = tethys_app_base.TethysAppBase()
app.nav_links = ["test", "1", "2", "3"]
links = app.navigation_links
self.assertListEqual(links, app.nav_links)

def test_navigation_links_auto_excluded_page(self):
app = tethys_app_base.TethysAppBase()
app.nav_links = "auto"
app.index = "home"
app.root_url = "test-app"

app._registered_url_maps = [
Namespace(name="exclude_page", title="Exclude Page", index=-1),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are these argparse.Namespaces? Seems like they should be simple dicts.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just wanted a mock-like instance of UrlMap... I should have just used a mock.MagicMock object, lol. I'll swap it for that.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Turns out I must've chosen Namespace for a reason. Using mock.MagicMock causes the tests to fail because mocking the property name cannot be done on initialization (see mock docs). While I could have broken it out into two steps, it seemed like using Namespace shouldn't be a big deal. Let me know if you disagree.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Try using the UrlMaps for the test instead of the Namespace.

Namespace(name="last_page", title="Last Page", index=3),
Namespace(name="third_page", title="Third Page", index=2),
Namespace(name="second_page", title="Second Page", index=1),
Namespace(name="home", title="Home", index=0),
]

links = app.navigation_links

self.assertListEqual(
links,
[
{"title": "Home", "href": "/apps/test-app/"},
{"title": "Second Page", "href": "/apps/test-app/second-page/"},
{"title": "Third Page", "href": "/apps/test-app/third-page/"},
{"title": "Last Page", "href": "/apps/test-app/last-page/"},
],
)
self.assertEqual(links, app.nav_links)
4 changes: 2 additions & 2 deletions tests/unit_tests/test_tethys_apps/test_base/test_consumer.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import os
import json
import asyncio
from os import environ

from tethys_sdk.testing import TethysTestCase
from channels.testing import WebsocketCommunicator
Expand All @@ -15,7 +15,7 @@ def test_consumer(self):
asyncio.set_event_loop(event_loop)

async def run_test():
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "tethys_portal.settings")
environ.setdefault("DJANGO_SETTINGS_MODULE", "tethys_portal.settings")
settings.CHANNEL_LAYERS = {}

communicator = WebsocketCommunicator(
Expand Down
Loading
Loading