2022-06-27 09:10:21 +02:00
|
|
|
import json
|
|
|
|
import os
|
|
|
|
import shutil
|
|
|
|
import subprocess
|
|
|
|
import sys
|
2022-05-26 13:49:31 +02:00
|
|
|
import unittest
|
|
|
|
|
2022-06-27 09:10:21 +02:00
|
|
|
from cpl_core.utils import String
|
2022-12-01 23:23:48 +01:00
|
|
|
from unittests_cli.abc.command_test_case import CommandTestCase
|
2022-06-27 09:10:21 +02:00
|
|
|
from unittests_cli.constants import PLAYGROUND_PATH
|
|
|
|
from unittests_shared.cli_commands import CLICommands
|
|
|
|
|
2022-05-26 13:49:31 +02:00
|
|
|
|
2022-12-01 23:23:48 +01:00
|
|
|
class UpdateTestCase(CommandTestCase):
|
|
|
|
def __init__(self, method_name: str):
|
|
|
|
CommandTestCase.__init__(self, method_name)
|
2023-02-20 15:55:20 +01:00
|
|
|
self._source = "install-test-source"
|
|
|
|
self._project_file = f"src/{String.convert_to_snake_case(self._source)}/{self._source}.json"
|
2022-06-27 09:10:21 +02:00
|
|
|
|
2023-02-20 15:55:20 +01:00
|
|
|
self._old_version = "1.7.1"
|
|
|
|
self._old_package_name = "discord.py"
|
|
|
|
self._old_package = f"{self._old_package_name}=={self._old_version}"
|
2022-06-27 09:10:21 +02:00
|
|
|
|
2022-09-12 18:07:37 +02:00
|
|
|
# todo: better way to do shit required
|
2023-04-04 21:36:10 +02:00
|
|
|
self._new_version = "2.2.2"
|
2023-02-20 15:55:20 +01:00
|
|
|
self._new_package_name = "discord.py"
|
|
|
|
self._new_package = f"{self._new_package_name}=={self._new_version}"
|
2022-06-27 09:10:21 +02:00
|
|
|
|
2022-12-01 23:23:48 +01:00
|
|
|
def setUp(self):
|
|
|
|
CLICommands.uninstall(self._old_package)
|
|
|
|
CLICommands.uninstall(self._new_package)
|
|
|
|
os.chdir(PLAYGROUND_PATH)
|
|
|
|
# create projects
|
2023-02-20 15:55:20 +01:00
|
|
|
CLICommands.new("console", self._source, "--ab", "--s")
|
2022-12-01 23:23:48 +01:00
|
|
|
os.chdir(os.path.join(os.getcwd(), self._source))
|
|
|
|
CLICommands.install(self._old_package)
|
|
|
|
|
2022-06-27 09:10:21 +02:00
|
|
|
def _get_project_settings(self):
|
2023-02-20 15:55:20 +01:00
|
|
|
with open(os.path.join(os.getcwd(), self._project_file), "r", encoding="utf-8") as cfg:
|
2022-06-27 09:10:21 +02:00
|
|
|
# load json
|
|
|
|
project_json = json.load(cfg)
|
|
|
|
cfg.close()
|
|
|
|
|
|
|
|
return project_json
|
|
|
|
|
|
|
|
def _save_project_settings(self, settings: dict):
|
2023-02-20 15:55:20 +01:00
|
|
|
with open(os.path.join(os.getcwd(), self._project_file), "w", encoding="utf-8") as project_file:
|
2022-06-27 09:10:21 +02:00
|
|
|
project_file.write(json.dumps(settings, indent=2))
|
|
|
|
project_file.close()
|
|
|
|
|
|
|
|
def _get_installed_packages(self) -> dict:
|
2023-02-20 15:55:20 +01:00
|
|
|
reqs = subprocess.check_output([sys.executable, "-m", "pip", "freeze"])
|
|
|
|
return dict([tuple(r.decode().split("==")) for r in reqs.split()])
|
2022-06-27 09:10:21 +02:00
|
|
|
|
|
|
|
def test_install_package(self):
|
|
|
|
settings = self._get_project_settings()
|
|
|
|
self.assertNotEqual(settings, {})
|
2023-02-20 15:55:20 +01:00
|
|
|
self.assertIn("ProjectSettings", settings)
|
|
|
|
self.assertIn("Dependencies", settings["ProjectSettings"])
|
|
|
|
self.assertIn(self._old_package, settings["ProjectSettings"]["Dependencies"])
|
2022-06-27 09:10:21 +02:00
|
|
|
packages = self._get_installed_packages()
|
|
|
|
self.assertIn(self._old_package_name, packages)
|
|
|
|
self.assertEqual(self._old_version, packages[self._old_package_name])
|
|
|
|
|
|
|
|
CLICommands.update()
|
|
|
|
|
|
|
|
settings = self._get_project_settings()
|
|
|
|
self.assertNotEqual(settings, {})
|
2023-02-20 15:55:20 +01:00
|
|
|
self.assertIn("ProjectSettings", settings)
|
|
|
|
self.assertIn("Dependencies", settings["ProjectSettings"])
|
|
|
|
self.assertIn(self._new_package, settings["ProjectSettings"]["Dependencies"])
|
2022-06-27 09:10:21 +02:00
|
|
|
packages = self._get_installed_packages()
|
|
|
|
self.assertIn(self._new_package_name, packages)
|
|
|
|
self.assertEqual(self._new_version, packages[self._new_package_name])
|