import logging

from ..base import common
from ..base.testcase import ShedTestCase

log = logging.getLogger(__name__)

emboss_repository_name = "emboss_0430"
emboss_repository_description = "EMBOSS tools for test 0430"
emboss_repository_long_description = "Long description of EMBOSS tools for test 0430"

freebayes_repository_name = "freebayes_0430"
freebayes_repository_description = "Freebayes tool for test 0430"
freebayes_repository_long_description = "Long description of Freebayes tool for test 0430"
"""
1. Create and populate repositories.
2. Browse Custom Datatypes.
3. Browse Tools.
4. Browse Repository Dependencies.
5. Browse Tool Dependencies.
"""


class TestToolShedBrowseUtilities(ShedTestCase):
    """Test browsing for Galaxy utilities."""

    def test_0000_initiate_users(self):
        """Create necessary user accounts and login as an admin user.

        Create all the user accounts that are needed for this test script to run independently of other tests.
        Previously created accounts will not be re-created.
        """
        self.login(email=common.test_user_1_email, username=common.test_user_1_name)
        self.login(email=common.admin_email, username=common.admin_username)

    def test_0010_create_emboss_repository(self):
        """Create and populate the emboss_0430 repository

        We are at step 1.
        Create the emboss_0430 repository, and populate it with tools.
        """
        category = self.create_category(
            name="Test 0430 Galaxy Utilities", description="Description of Test 0430 Galaxy Utilities category"
        )
        self.login(email=common.test_user_1_email, username=common.test_user_1_name)
        strings_displayed = self.expect_repo_created_strings(emboss_repository_name)
        emboss_repository = self.get_or_create_repository(
            name=emboss_repository_name,
            description=emboss_repository_description,
            long_description=emboss_repository_long_description,
            owner=common.test_user_1_name,
            category=category,
            strings_displayed=strings_displayed,
        )
        self.commit_tar_to_repository(
            emboss_repository,
            "emboss/emboss.tar",
            commit_message="Uploaded emboss.tar.",
        )

    def test_0020_create_tool_dependency_repository(self):
        """Create and populate the freebayes_0430 repository

        We are at step 1.
        Create and populate the repository that will have a tool dependency defined.
        """
        category = self.create_category(
            name="Test 0430 Galaxy Utilities", description="Description of Test 0430 Galaxy Utilities category"
        )
        self.login(email=common.test_user_1_email, username=common.test_user_1_name)
        strings_displayed = self.expect_repo_created_strings(freebayes_repository_name)
        repository = self.get_or_create_repository(
            name=freebayes_repository_name,
            description=freebayes_repository_description,
            long_description=freebayes_repository_long_description,
            owner=common.test_user_1_name,
            category=category,
            strings_displayed=strings_displayed,
        )
        self.commit_tar_to_repository(
            repository,
            "freebayes/freebayes.tar",
            commit_message="Uploaded freebayes.tar.",
        )
