mirror of
https://github.com/frappe/bench.git
synced 2025-01-23 15:08:24 +00:00
test: app states creation & update
This commit is contained in:
parent
6609ad20c4
commit
03a435330b
@ -1,8 +1,11 @@
|
||||
import os
|
||||
import shutil
|
||||
import unittest
|
||||
|
||||
from bench.app import App
|
||||
from bench.bench import Bench
|
||||
from bench.utils import exec_cmd
|
||||
from bench.utils import exec_cmd, is_valid_frappe_branch
|
||||
from bench.utils.app import get_required_deps_url
|
||||
|
||||
|
||||
class TestUtils(unittest.TestCase):
|
||||
@ -42,3 +45,36 @@ class TestUtils(unittest.TestCase):
|
||||
self.assertTrue(is_valid_frappe_branch("https://github.com/frappe/erpnext", frappe_branch="version-13"))
|
||||
self.assertFalse(is_valid_frappe_branch("https://github.com/frappe/erpnext", frappe_branch="version-1"))
|
||||
|
||||
def test_app_states(self):
|
||||
bench_dir = "./sandbox"
|
||||
sites_dir = os.path.join(bench_dir, "sites")
|
||||
|
||||
if not os.path.exists(sites_dir):
|
||||
os.makedirs(sites_dir)
|
||||
|
||||
fake_bench = Bench(bench_dir)
|
||||
|
||||
fake_bench.apps.set_states()
|
||||
|
||||
self.assertTrue(hasattr(fake_bench.apps, "states"))
|
||||
self.assertTrue(os.path.exists(os.path.join(sites_dir, "apps_states.json")))
|
||||
|
||||
fake_bench.apps.states = {"frappe": {"resolution": None, "version": "14.0.0-dev"}}
|
||||
fake_bench.apps.update_apps_states()
|
||||
|
||||
self.assertEqual(fake_bench.apps.states, {})
|
||||
|
||||
frappe_path = os.path.join(bench_dir, "apps", "frappe", "frappe")
|
||||
|
||||
os.makedirs(frappe_path)
|
||||
|
||||
with open(os.path.join(frappe_path, "__init__.py"), "w+") as f:
|
||||
f.write("__version__ = '11.0'")
|
||||
|
||||
fake_bench.apps.update_apps_states("frappe")
|
||||
|
||||
self.assertIn("frappe", fake_bench.apps.states)
|
||||
self.assertIn("version", fake_bench.apps.states["frappe"])
|
||||
self.assertEqual("11.0", fake_bench.apps.states["frappe"]["version"])
|
||||
|
||||
shutil.rmtree(bench_dir)
|
||||
|
@ -107,7 +107,9 @@ def switch_to_develop(apps=None, bench_path=".", upgrade=True):
|
||||
|
||||
|
||||
def get_version_from_string(contents, field="__version__"):
|
||||
match = re.search(r"^(\s*%s\s*=\s*['\\\"])(.+?)(['\"])(?sm)" % field, contents)
|
||||
match = re.search(r"^(\s*%s\s*=\s*['\\\"])(.+?)(['\"])" % field, contents, flags=(re.S | re.M))
|
||||
if not match:
|
||||
raise Exception("No match was found")
|
||||
return match.group(2)
|
||||
|
||||
|
||||
@ -164,6 +166,7 @@ def get_current_branch(app, bench_path="."):
|
||||
repo_dir = get_repo_dir(app, bench_path=bench_path)
|
||||
return get_cmd_output("basename $(git symbolic-ref -q HEAD)", cwd=repo_dir)
|
||||
|
||||
|
||||
def get_required_deps_url(git_url, repo_name, branch, deps="hooks.py"):
|
||||
git_url = (
|
||||
git_url.replace(".git", "").replace("github.com", "raw.github.com")
|
||||
@ -172,6 +175,7 @@ def get_required_deps_url(git_url, repo_name, branch, deps="hooks.py"):
|
||||
git_url += f"/{branch}/{repo_name}/{deps}"
|
||||
return git_url
|
||||
|
||||
|
||||
def get_remote(app, bench_path="."):
|
||||
repo_dir = get_repo_dir(app, bench_path=bench_path)
|
||||
contents = subprocess.check_output(
|
||||
@ -208,11 +212,13 @@ def get_app_name(bench_path, repo_name):
|
||||
|
||||
return repo_name
|
||||
|
||||
|
||||
def check_existing_dir(bench_path, repo_name):
|
||||
cloned_path = os.path.join(bench_path, "apps", repo_name)
|
||||
dir_already_exists = os.path.isdir(cloned_path)
|
||||
return dir_already_exists, cloned_path
|
||||
|
||||
|
||||
def get_current_version(app, bench_path="."):
|
||||
current_version = None
|
||||
repo_dir = get_repo_dir(app, bench_path=bench_path)
|
||||
|
Loading…
x
Reference in New Issue
Block a user