예제 #1
0
    def test_push(self):
        """Tests standard push command"""
        ctx = Context()

        # Force the return of fake service
        self.mock_api_service.get_applications.return_value = self.GET_APP_RESPONSE

        a = Application.push(ctx,
                             source_directory=self.SOURCE_DIR,
                             name=self.APP_NAME,
                             bound_services=self.BOUND_SERVICES,
                             env=self.ENV)

        assert a == Application(self.APP_NAME, self.APP_ID, self.APP_STATE,
                                self.APP_INSTANCES, self.APP_URLS,
                                self.APP_BINDINGS)

        assert a._client == self.user_admin

        # Now push the application but with non-standard client
        a = Application.push(ctx,
                             source_directory=self.SOURCE_DIR,
                             name=self.APP_NAME,
                             bound_services=self.BOUND_SERVICES,
                             env=self.ENV,
                             client=self.user_luser)

        assert a == Application(self.APP_NAME, self.APP_ID, self.APP_STATE,
                                self.APP_INSTANCES, self.APP_URLS,
                                self.APP_BINDINGS)

        assert a._client == self.user_luser
예제 #2
0
    def test_push_fail(self):
        """Try pushing the app, but it doesn't appear in the response"""
        ctx = Context()

        # Force the return of fake service
        self.mock_api_service_bad.api_get_app_list.return_value = self.GET_APP_BAD_RESPONSE

        with pytest.raises(AssertionError):
            a = Application.push(ctx, self.SOURCE_DIR, self.APP_NAME,
                                 self.BOUND_SERVICES, self.ENV)
 def test_create_from_binary(self):
     context = Context()
     self.mock_api_service.create_offering_from_binary.return_value = POST_RESPONSE_ONE_PLAN
     offering = ServiceOffering.create_from_binary(context, jar_path=JAR_PATH, manifest_path=MANIFEST_PATH,
                                                   offering_path=OFFERING_PATH)
     assert type(offering) == ServiceOffering
     assert offering.label == OFFERING_LABEL
     self.mock_api_service.create_offering_from_binary.assert_called_with(jar_path=JAR_PATH,
                                                                          manifest_path=MANIFEST_PATH,
                                                                          offering_path=OFFERING_PATH,
                                                                          client=offering._client)
예제 #4
0
 def test_service_instance_url(self, service_instance_running):
     """
     Test retrieving url from metadata
     """
     context = Context()
     self.mock_api_service.create_service.return_value = self.get_service_with_state(
         self.RUNNING)
     service_instance = ServiceInstance.create(context,
                                               offering_id=self.OFFERING_ID,
                                               name=self.SERVICE_NAME,
                                               plan_id=self.SERVICE_PLAN_ID)
     assert service_instance.url == service_instance_running.url
예제 #5
0
    def test_push_not_created(self):
        """Try pushing the app, the push succedeed, but somehow the application
        isn't visible. Ensure the message is informative."""
        ctx = Context()

        # Force the return of fake service
        self.mock_api_service_bad.api_get_app_list.return_value = []

        with pytest.raises(AssertionError) as ex:
            a = Application.push(ctx, self.SOURCE_DIR, self.APP_NAME,
                                 self.BOUND_SERVICES, self.ENV)

        msg = "App " + self.APP_NAME + " has not been created on the Platform"
        assert msg in ex.__str__()
예제 #6
0
 def test_service_instance_create_with_plan_name(self,
                                                 service_instance_running):
     """
     Test create_with_plan_name command
     """
     context = Context()
     self.mock_api_service.get_offerings.return_value = self.GET_CATALOG_RESPONSE
     self.mock_api_service.create_service_instance.return_value = self.get_service_with_state(
         self.RUNNING)
     service_instance = ServiceInstance.create_with_name(
         context,
         offering_label=self.OFFERING_LABEL,
         name=self.SERVICE_NAME,
         plan_name=self.SERVICE_PLAN_NAME)
     assert service_instance == service_instance_running
예제 #7
0
    def test_push_tap_exception(self):
        """Try pushing the app, but exception was raised by TapCli"""
        ctx = Context()

        # Force the return of fake service
        self.mock_api_service.api_get_app_list.return_value = self.GET_APP_RESPONSE

        # Force the exception raising
        mock_TapCli = MagicMock()
        mock_TapCli.push.side_effect = Exception("Bang, bang!")
        self.mock_tap_cli_exception.return_value = mock_TapCli

        with pytest.raises(Exception):
            a = Application.push(ctx, self.SOURCE_DIR, self.APP_NAME,
                                 self.BOUND_SERVICES, self.ENV)

        self.mock_api_service.delete_application.assert_called_once_with(
            self.APP_ID, self.user_admin)
예제 #8
0
    def test_push_has_stopped(self):
        """Pushes an application that will be in stopped state. Verifies that
        the is_stopped property doesn't crash anything."""
        ctx = Context()

        # Force the return of fake service
        rep = copy.deepcopy(self.GET_APP_RESPONSE)
        rep.data[0]["state"] = "stopped"
        self.mock_api_service.get_applications.return_value = rep

        a = Application.push(ctx,
                             source_directory=self.SOURCE_DIR,
                             name=self.APP_NAME,
                             bound_services=self.BOUND_SERVICES,
                             env=self.ENV)

        assert a == Application(self.APP_NAME, self.APP_ID, "stopped",
                                self.APP_INSTANCES, self.APP_URLS,
                                self.APP_BINDINGS)
        assert a._client == self.user_admin
        assert a.is_stopped == True
        assert a.is_running == False
import config
from modules.command import run
from modules.constants import ApplicationPath
from modules.mongo_reporter._tap_info import TapInfo
from modules.tap_object_model import User
from modules.tap_object_model.flows import onboarding
from modules.test_names import TapObjectName
from tests.fixtures.context import Context
from tests.fixtures.fixtures import core_org, test_data_urls

logger = logging.getLogger(__name__)
logger.setLevel(logging.DEBUG)

CORE_ORG = core_org()
PERFORMANCE_CONTEXT = Context()


def build_sample_apps():
    logger.info('Building sample apps')
    for app_dir in [ApplicationPath.SAMPLE_JAVA_APP, ApplicationPath.SAMPLE_PYTHON_APP,
                    ApplicationPath.SAMPLE_NODEJS_APP, ApplicationPath.SAMPLE_GO_APP]:
        run(['./build.sh'], cwd=app_dir)


def create_users():
    logger.info('Create users')

    names = [TapObjectName(prefix='perf_user').as_email() for _ in range(config.num_clients)]
    for name in names:
        onboarding.onboard(context=PERFORMANCE_CONTEXT,