Exemple #1
0
    def test_m_delayed_operation_failure(self):
        """Example showing an asynchronous operation failure."""
        context = citest.base.ExecutionContext()
        key = self.make_key('InvalidKey')
        expect_value = 'Unexpected Value'

        operation = http_agent.HttpDeleteOperation(
            title='Delayed 404',
            status_class=KeystoreStatus,
            data=json.JSONEncoder().encode(expect_value),
            path='/delete/' + key + '?async&delay=1')
        builder = st.HttpContractBuilder(self.scenario.agent)
        (builder.new_clause_builder('Never Checks For Value').get_url_path(
            '/lookup/' + key).contains_path_eq('', expect_value))
        contract = builder.build()

        test = st.OperationContract(operation, contract)
        with self.assertRaises(AssertionError):
            self.run_test_case(test, context=context)

        # citest wrote into the context the 'OperationStatus'
        # Normally this is so we can write predicates that look into it
        # using lambda expressions for defered bindings. In this case we'll
        # look at it to show that the status we got back had the delayed error we
        # anticipated in it.
        status = context['OperationStatus']
        self.assertEqual('ERROR', status.current_state)
        self.assertEqual('KeyError', status.error.split(' ', 1)[0])
Exemple #2
0
    def test_c_put_string_with_async_request_timeout_ok(self):
        """Example writes a string value asynchronously then checks for it.

    The request is asynchronous so its final status is not immediately known.
    We'll inform citest of the application protocol so it can wait for the
    request to complete, then observe the results.
    """
        key = self.make_key('MyTimeoutKey')
        expect_value = 'My Timeout Value'

        operation = http_agent.HttpPostOperation(
            title='Writing Key Value Asynchronously',
            status_class=KeystoreStatus,
            data=json.JSONEncoder().encode(expect_value),
            path='/put/' + key + '?async&delay=2.5',
            max_wait_secs=2)

        builder = st.HttpContractBuilder(self.scenario.agent)
        (builder.new_clause_builder(
            'Check Key Value',
            retryable_for_secs=1).get_url_path('/lookup/' +
                                               key).contains_path_eq(
                                                   '', expect_value))
        contract = builder.build()

        test = st.OperationContract(operation, contract)
        self.run_test_case(test, timeout_ok=True)
  def create_bake_docker_pipeline(self):
    name = 'BakeDocker'
    self.docker_pipeline_id = name
    bake_stage = self.make_bake_stage(
        package='vim', providerType='docker', region='global')

    pipeline_spec = dict(
      name=name,
      stages=[bake_stage],
      triggers=[self.make_jenkins_trigger()],
      application=self.TEST_APP,
      stageCounter=1,
      parallel=True,
      index=0,
      limitConcurrent=True,
      executionEngine='v2',
      appConfig={}
    )
    payload = self.agent.make_json_payload_from_kwargs(**pipeline_spec)

    builder = st.HttpContractBuilder(self.agent)
    (builder.new_clause_builder('Has Pipeline')
       .get_url_path(
           'applications/{app}/pipelineConfigs'.format(app=self.TEST_APP))
       .contains_path_value(None, pipeline_spec))

    return st.OperationContract(
        self.new_post_operation(
            title='create_bake_docker_pipeline', data=payload, path='pipelines',
            status_class=st.SynchronousHttpOperationStatus),
        contract=builder.build())
Exemple #4
0
    def test_a_put_string_eventual_correctness(self):
        """Example writes a value that is not immediately observable.

    The request itself is synchronous, but the server does not make
    the value immediately available so observer may need to retry.
    """
        key = self.make_key('MyEventualCorrectnessKey')
        expect_value = 'My Eventual-Correctness Value'

        # Our server is really going to use an asynchronous protocol,
        # but this test is ignoring that and treating the put at face value.
        # It will attempt to observe a few times until eventually it sees what
        # we were expecting to eventually see.
        operation = http_agent.HttpPostOperation(
            title='Writing Key Value',
            data=json.JSONEncoder().encode(expect_value),
            path='/put/' + key + '?async')
        builder = st.HttpContractBuilder(self.scenario.agent)
        (builder.new_clause_builder(
            'Check Key Value',
            retryable_for_secs=3).get_url_path('/lookup/' +
                                               key).contains_path_eq(
                                                   '', expect_value))
        contract = builder.build()

        test = st.OperationContract(operation, contract)
        self.run_test_case(test)
  def create_deploy_upsert_load_balancer_pipeline(self):
    name = 'promoteServerGroupPipeline'
    self.pipeline_id = name
    deploy_stage = self.make_deploy_stage()
    upsert_load_balancer_stage = self.make_upsert_load_balancer_stage()

    pipeline_spec = dict(
        name=name,
        stages=[deploy_stage, upsert_load_balancer_stage],
        triggers=[],
        application=self.TEST_APP,
        stageCounter=2,
        parallel=True,
        limitConcurrent=True,
        appConfig={},
        index=0
    )

    payload = self.agent.make_json_payload_from_kwargs(**pipeline_spec)

    builder = st.HttpContractBuilder(self.agent)
    (builder.new_clause_builder('Has Pipeline',
                                retryable_for_secs=5)
     .get_url_path('applications/{0}/pipelineConfigs'.format(self.TEST_APP))
     .contains_path_value(None, pipeline_spec))

    return st.OperationContract(
      self.new_post_operation(
        title='create_deploy_upsert_load_balancer_pipeline', data=payload, path='pipelines',
        status_class=st.SynchronousHttpOperationStatus),
      contract=builder.build())
Exemple #6
0
  def test_j_just_observe_variants(self):
    """Example checks a contract without an operation."""
    key = self.make_key('MyDictKey')
    context = citest.base.ExecutionContext()

    builder = st.HttpContractBuilder(self.scenario.agent)
    (builder.new_clause_builder('Check Key Value using contains_path_eq')
     .get_url_path('/lookup/' + key)
     .contains_path_eq('a', 'A'))

    # The above is syntactic sugar for this
    (builder.new_clause_builder('Check Key Value using EXPECT')
     .get_url_path('/lookup/' + key)
     .EXPECT(jp.PathPredicate('a', jp.STR_EQ('A'))))

    # Multiple clauses are implicitly anded together.
    (builder.new_clause_builder('Check Multiple Key Values using contains_path_eq')
     .get_url_path('/lookup/' + key)
     .contains_path_eq('a', 'A')
     .contains_path_eq('b', 'B'))

    # This is a more explicit way to say the above.
    (builder.new_clause_builder('Check Multiple Key Values using AND')
     .get_url_path('/lookup/' + key)
     .EXPECT(jp.PathPredicate('a', jp.STR_EQ('A')))
     .AND(jp.PathPredicate('b', jp.STR_EQ('B'))))

    contract = builder.build()
    results = contract.verify(context)
    self.assertTrue(results)
Exemple #7
0
    def submit_pipeline_contract(self, name, stages):
        s = self.scenario
        job = {
            'keepWaitingPipelines': 'false',
            'application': s.TEST_APP,
            'name': name,
            'lastModifiedBy': 'anonymous',
            'limitConcurrent': 'true',
            'parallel': 'true',
            'stages': stages,
        }
        payload = s.agent.make_json_payload_from_kwargs(**job)
        expect_match = {
            key: jp.EQUIVALENT(value)
            for key, value in job.items()
        }
        expect_match['stages'] = jp.LIST_MATCHES([
            jp.DICT_MATCHES(
                {key: jp.EQUIVALENT(value)
                 for key, value in stage.items()}) for stage in stages
        ])

        builder = st.HttpContractBuilder(s.agent)
        (builder.new_clause_builder(
            'Has Pipeline', retryable_for_secs=15).get_url_path(
                'applications/{app}/pipelineConfigs'.format(
                    app=s.TEST_APP)).contains_match(expect_match))
        return st.OperationContract(s.new_post_operation(
            title='save_pipeline_operation',
            data=payload,
            path='pipelines',
            status_class=st.SynchronousHttpOperationStatus),
                                    contract=builder.build())
Exemple #8
0
    def delete_pipeline(self, pipeline_id):
        """Create OperationContract that delete target pipeline
        Args:
            pipeline_id: [str] The name of the pipeline to be delete

        To verify the operation, we just check that the pipeline
        with the given name was deleted.
        """

        builder = st.HttpContractBuilder(self.agent)
        (builder.new_clause_builder(
            "Has Pipeline", retryable_for_secs=5).get_url_path(
                "applications/{app}/pipelineConfigs".format(
                    app=self.TEST_APP)).excludes_path_value(
                        "name", pipeline_id))

        return st.OperationContract(
            self.new_delete_operation(
                title="delete pipeline",
                data="",
                path=("pipelines/{app}/{pl}".format(app=self.TEST_APP,
                                                    pl=pipeline_id)),
                status_class=st.SynchronousHttpOperationStatus,
            ),
            contract=builder.build(),
        )
    def create_disable_and_destroy_pipeline(self):
        """Create OperationContract that create the disable and destroy pipeline

        To verify the operation, we just check that the disable and destroy pipeline
        with the default name was created.
        """

        name = 'DisableAndDestroy'
        self.destroy_pipeline_id = name
        disable_stage = self.make_azure_disable_group_stage()
        destroy_stage = self.make_azure_destroy_group_stage(
            requisiteStage=["DISABLE"])

        pipeline_spec = dict(stages=[disable_stage, destroy_stage],
                             stageCounter=2,
                             triggers=[],
                             limitConcurrent=True,
                             keepWaitingPipelines=False,
                             name=name,
                             application=self.TEST_APP)

        payload = self.agent.make_json_payload_from_kwargs(**pipeline_spec)

        builder = st.HttpContractBuilder(self.agent)
        (builder.new_clause_builder('Has Pipeline').get_url_path(
            'applications/{app}/pipelineConfigs'.format(
                app=self.TEST_APP)).contains_path_value(None, {"name": name}))

        return st.OperationContract(self.new_post_operation(
            title="create destroy pipeline",
            data=payload,
            path='pipelines',
            status_class=st.SynchronousHttpOperationStatus),
                                    contract=builder.build())
Exemple #10
0
    def create_find_image_pipeline(self):
        name = 'findImagePipeline'
        self.pipeline_id = name
        smoke_stage = self.make_smoke_stage()
        deploy_stage = self.make_deploy_stage(imageSource='FINDIMAGE',
                                              requisiteStages=['FINDIMAGE'])

        pipeline_spec = dict(name=name,
                             stages=[smoke_stage, deploy_stage],
                             triggers=[],
                             application=self.TEST_APP,
                             stageCounter=2,
                             parallel=True,
                             limitConcurrent=True,
                             executionEngine='v2',
                             appConfig={},
                             index=0)

        payload = self.agent.make_json_payload_from_kwargs(**pipeline_spec)

        builder = st.HttpContractBuilder(self.agent)
        (builder.new_clause_builder(
            'Has Pipeline', retryable_for_secs=5).get_url_path(
                'applications/{app}/pipelineConfigs'.format(
                    app=self.TEST_APP)).contains_path_value(
                        None, pipeline_spec))

        return st.OperationContract(self.new_post_operation(
            title='create_find_image_pipeline',
            data=payload,
            path='pipelines',
            status_class=st.SynchronousHttpOperationStatus),
                                    contract=builder.build())
Exemple #11
0
  def test_d_use_context_for_unknown_value(self):
    """Example uses dynamic return result from operation to check value."""
    key = self.make_key('MyRandomKey')
    operation = http_agent.HttpPostOperation(
        title='Generating Key Value',
        data=json.JSONEncoder().encode(''),
        path='/put_random/' + key)
    builder = st.HttpContractBuilder(self.scenario.agent)
    (builder.new_clause_builder('Check Key Value')
     .get_url_path('/lookup/' + key)
     .contains_path_eq('', lambda context: context['EXPECT']))
    contract = builder.build()

    def extractor(operation_status, context):
      """Helper function that populates context with value from status.

      This is so we can write our contract in terms of a value not known
      until we perform the actual operation.
      """
      response = operation_status.raw_http_response
      context.set_snapshotable('EXPECT', response.output)

    test = st.OperationContract(operation, contract,
                                status_extractor=extractor)
    self.run_test_case(test)
    def create_bake_and_deploy_google_pipeline(self):
        name = 'BakeAndDeployGoogle'
        self.google_bake_pipeline_id = name
        bake_stage = self.make_bake_stage(package='vim',
                                          providerType='gce',
                                          region='global')
        deploy_stage = self.make_deploy_google_stage(requisiteStages=['BAKE'])

        pipeline_spec = dict(name=name,
                             stages=[bake_stage, deploy_stage],
                             triggers=[self.make_jenkins_trigger()],
                             application=self.TEST_APP,
                             stageCounter=2,
                             parallel=True,
                             limitConcurrent=True,
                             appConfig={})

        payload = self.agent.make_json_payload_from_kwargs(**pipeline_spec)

        builder = st.HttpContractBuilder(self.agent)
        (builder.new_clause_builder(
            'Has Pipeline', retryable_for_secs=5).get_url_path(
                'applications/{app}/pipelineConfigs'.format(
                    app=self.TEST_APP)).contains_path_value(
                        None, pipeline_spec))

        return st.OperationContract(self.new_post_operation(
            title='create_bake_google_pipeline',
            data=payload,
            path='pipelines',
            status_class=st.SynchronousHttpOperationStatus),
                                    contract=builder.build())
    def create_bake_and_deploy_aws_pipeline(self):
        name = 'BakeAndDeployAws'
        self.aws_bake_pipeline_id = name
        bake_stage = self.make_bake_stage(
            package='vim',
            providerType='aws',
            regions=[self.bindings['TEST_AWS_REGION']],
            vmType='hvm',
            storeType='ebs')
        # FIXME(jacobkiefer): this is creating a gce deploy stage in an aws
        # pipeline. Not good.
        deploy_stage = self.make_deploy_google_stage(requisiteStages=['BAKE'])

        pipeline_spec = dict(name=name,
                             stages=[bake_stage, deploy_stage],
                             triggers=[self.make_jenkins_trigger()],
                             application=self.TEST_APP,
                             stageCounter=2,
                             parallel=True)
        payload = self.agent.make_json_payload_from_kwargs(**pipeline_spec)

        builder = st.HttpContractBuilder(self.agent)
        (builder.new_clause_builder(
            'Has Pipeline', retryable_for_secs=5).get_url_path(
                'applications/{app}/pipelineConfigs'.format(
                    app=self.TEST_APP)).contains_path_value(
                        None, pipeline_spec))

        return st.OperationContract(self.new_post_operation(
            title='create_bake_aws_pipeline',
            data=payload,
            path='pipelines',
            status_class=st.SynchronousHttpOperationStatus),
                                    contract=builder.build())
  def create_deploy_pipeline(self):
    name = 'GcsToGaePubsubDeploy'
    self.pipeline_id = name

    pipeline_spec = self.make_pipeline_spec(name)
    payload = self.agent.make_json_payload_from_kwargs(**pipeline_spec)

    pipeline_config_path = 'applications/{app}/pipelineConfigs'.format(app=self.TEST_APP)
    builder = st.HttpContractBuilder(self.agent)
    (builder.new_clause_builder('Has Pipeline', retryable_for_secs=15)
     .get_url_path(pipeline_config_path)
     .EXPECT(
       jp.LIST_MATCHES([self.make_dict_matcher(pipeline_spec)])))

    # Need to query Gate for the id of the pipeline we just created...
    def create_pipeline_id_extractor(_ignored, context):
      pipeline_config_resp = self.agent.get(pipeline_config_path)
      pipeline_config_list = json.JSONDecoder().decode(pipeline_config_resp.output)
      found = next((x for x in pipeline_config_list if x['name'] == self.pipeline_id), None)
      if (found is not None):
        context['pipelineId'] = found['id'] # I don't know how to reference this later, so I'm saving it in self for now.
        self.__pipeline_id = found['id'] # I don't know how to reference this later, so I'm saving it in self for now.
        logging.info('Created pipeline config with id: %s', context['pipelineId'])

    return st.OperationContract(
      self.new_post_operation(
        title='create_gcs_gae_pubsub_pipeline', data=payload, path='pipelines',
        status_class=st.SynchronousHttpOperationStatus),
      contract=builder.build(),
      status_extractor=create_pipeline_id_extractor)
Exemple #15
0
    def test_b_put_string_with_async_request(self):
        """Example writes a string value asynchronously then checks for it.

    The request is asynchronous so its final status is not immediately known.
    We'll inform citest of the application protocol so it can wait for the
    request to complete, then observe the results.
    """
        key = self.make_key('MyAsyncKey')
        expect_value = 'My Async Value'

        operation = http_agent.HttpPostOperation(
            title='Writing Key Value Asynchronously',
            status_class=KeystoreStatus,
            data=json.JSONEncoder().encode(expect_value),
            path='/put/' + key + '?async&delay=1.5')

        # For our server, we expect that the observer will be able to see
        # the value immediately once the operation finishes even though the
        # operation itself will take 1.5 seconds to complete (after the original
        # HTTP POST operation completes).
        builder = st.HttpContractBuilder(self.scenario.agent)
        (builder.new_clause_builder('Check Key Value').get_url_path(
            '/lookup/' + key).contains_path_eq('', expect_value))
        contract = builder.build()

        test = st.OperationContract(operation, contract)
        self.run_test_case(test)
Exemple #16
0
    def save_delete_daemonset_pipeline(self):
        delete_stage = self.make_delete_stage_daemonset()
        job = dict(appConfig={},
                   keepWaitingPipelines='false',
                   application=self.TEST_APP,
                   name='daemonset-delete-pipeline',
                   lastModifiedBy='anonymous',
                   limitConcurrent='true',
                   parallel='true',
                   stages=[delete_stage])
        payload = self.agent.make_json_payload_from_kwargs(**job)
        expect_match = {
            key: jp.EQUIVALENT(value)
            for key, value in job.items()
        }
        expect_match['stages'] = jp.LIST_MATCHES([
            jp.DICT_MATCHES({
                key: jp.EQUIVALENT(value)
                for key, value in delete_stage.items()
            })
        ])

        builder = st.HttpContractBuilder(self.agent)
        (builder.new_clause_builder(
            'Has Pipeline', retryable_for_secs=15).get_url_path(
                'applications/{app}/pipelineConfigs'.format(
                    app=self.TEST_APP)).contains_match(expect_match))
        return st.OperationContract(self.new_post_operation(
            title='create_delete daemonset',
            data=payload,
            path='pipelines',
            status_class=st.SynchronousHttpOperationStatus),
                                    contract=builder.build())
    def create_disable_and_destroy_aws_pipeline(self):
        name = 'DisableAndDestroyAws'
        self.aws_destroy_pipeline_id = name
        disable_stage = self.make_disable_group_stage(
            cloudProvider='aws', regions=[self.bindings['TEST_AWS_REGION']])
        destroy_stage = self.make_destroy_group_stage(
            cloudProvider='aws',
            zones=[self.bindings['TEST_AWS_ZONE']],
            requisiteStages=['DISABLE'])

        pipeline_spec = dict(name=name,
                             stages=[disable_stage, destroy_stage],
                             triggers=[self.make_jenkins_trigger()],
                             application=self.TEST_APP,
                             stageCounter=2,
                             parallel=True)
        payload = self.agent.make_json_payload_from_kwargs(**pipeline_spec)

        builder = st.HttpContractBuilder(self.agent)
        (builder.new_clause_builder(
            'Has Pipeline', retryable_for_secs=5).get_url_path(
                'applications/{app}/pipelineConfigs'.format(
                    app=self.TEST_APP)).contains_path_value(
                        None, pipeline_spec))

        return st.OperationContract(self.new_post_operation(
            title='create_destroy_aws_pipeline',
            data=payload,
            path='pipelines',
            status_class=st.SynchronousHttpOperationStatus),
                                    contract=builder.build())
    def create_bake_docker_pipeline(self):
        name = "BakeDocker"
        self.docker_pipeline_id = name
        bake_stage = self.make_bake_stage(package="libatm1",
                                          providerType="docker",
                                          region="global")

        pipeline_spec = dict(
            name=name,
            stages=[bake_stage],
            triggers=[self.make_jenkins_trigger()],
            application=self.TEST_APP,
            stageCounter=1,
            parallel=True,
            limitConcurrent=True,
            appConfig={},
        )
        payload = self.agent.make_json_payload_from_kwargs(**pipeline_spec)

        builder = st.HttpContractBuilder(self.agent)
        (builder.new_clause_builder(
            "Has Pipeline", retryable_for_secs=5).get_url_path(
                "applications/{app}/pipelineConfigs".format(
                    app=self.TEST_APP)).contains_path_value(
                        None, pipeline_spec))

        return st.OperationContract(
            self.new_post_operation(
                title="create_bake_docker_pipeline",
                data=payload,
                path="pipelines",
                status_class=st.SynchronousHttpOperationStatus,
            ),
            contract=builder.build(),
        )
Exemple #19
0
  def create_app(self):
    builder = st.HttpContractBuilder(self.agent)
    (builder.new_clause_builder('Has Application', retryable_for_secs=60)
       .get_url_path('applications')
       .contains_path_value('name', self.TEST_APP))

    return st.OperationContract(
        self.agent.make_create_app_operation(
            bindings=self.bindings, application=self.TEST_APP),
        builder.build())
Exemple #20
0
  def test_l_unexpected_observe_error(self):
    """Example showing what happens when a contract fails."""
    key = self.make_key('InvalidKey')
    context = citest.base.ExecutionContext()

    builder = st.HttpContractBuilder(self.scenario.agent)
    (builder.new_clause_builder('Expect Not Found Error')
     .get_url_path('/lookup/' + key)
     .contains_path_eq('a', 'A'))
    contract = builder.build()
    results = contract.verify(context)
    self.assertFalse(results)
  def create_app(self):
    builder = st.HttpContractBuilder(self.agent)
    (builder.new_clause_builder('Has Application', retryable_for_secs=60)
       .get_url_path('applications')
       .contains_path_value('name', self.TEST_APP))

    return st.OperationContract(
        self.agent.make_create_app_operation(
            bindings=self.bindings, application=self.TEST_APP,
            account_name=self.bindings['SPINNAKER_GOOGLE_ACCOUNT'],
            cloud_providers="gce,aws"),
        builder.build())
Exemple #22
0
  def test_k_expect_observe_error(self):
    """Example expects the observation itself to fail."""
    key = self.make_key('InvalidKey')
    context = citest.base.ExecutionContext()

    builder = st.HttpContractBuilder(self.scenario.agent)
    (builder.new_clause_builder('Expect Not Found Error')
     .get_url_path('/lookup/' + key)
     .EXPECT(st.HttpObservationFailureVerifier('Expect 404', 404)))
    contract = builder.build()
    results = contract.verify(context)
    self.assertTrue(results)
Exemple #23
0
  def test_j_just_observe(self):
    """Example checks a contract without an operation."""
    key = self.make_key('MyDictKey')
    context = citest.base.ExecutionContext()

    builder = st.HttpContractBuilder(self.scenario.agent)
    (builder.new_clause_builder('Check Key Value')
     .get_url_path('/lookup/' + key)
     .contains_path_eq('a', 'A'))
    contract = builder.build()
    results = contract.verify(context)
    self.assertTrue(results)
Exemple #24
0
  def test_k_expect_observe_error(self):
    """Example expects the observation itself to fail."""
    key = self.make_key('InvalidKey')
    context = citest.base.ExecutionContext()

    builder = st.HttpContractBuilder(self.scenario.agent)
    (builder.new_clause_builder('Expect Not Found Error')
     .get_url_path('/lookup/' + key)
     .EXPECT(ov_factory.error_list_contains(
         st.HttpAgentErrorPredicate(st.HttpResponsePredicate(http_code=404)))))
    contract = builder.build()
    results = contract.verify(context)
    self.assertTrue(results)
    def delete_pipeline(self, pipeline_id):
        payload = self.agent.make_json_payload_from_kwargs(id=pipeline_id)
        path = os.path.join('pipelines', self.TEST_APP, pipeline_id)

        builder = st.HttpContractBuilder(self.agent)
        (builder.new_clause_builder('Has Pipeline').get_url_path(
            'applications/{app}/pipelineConfigs'.format(
                app=self.TEST_APP)).excludes_path_value('name', pipeline_id))

        return st.OperationContract(self.new_delete_operation(
            title='delete_bake_pipeline',
            data=payload,
            path=path,
            status_class=st.SynchronousHttpOperationStatus),
                                    contract=builder.build())
Exemple #26
0
  def test_multiple(self):
    key = self.make_key('MyDictKey')
    expect_value = {'a': 'A', 'b': 'B', 'c': 'C'}
    operation = http_agent.HttpPostOperation(
        title='Writing Key Value',
        data=json.JSONEncoder().encode(expect_value),
        path='/put/' + key)

    context = citest.base.ExecutionContext()
    builder = st.HttpContractBuilder(self.scenario.agent)
    (builder.new_clause_builder('Check Multiple Key Values using contains_path_eq')
     .get_url_path('/lookup/' + key)
     .contains_path_eq('a', 'A')
     .contains_path_eq('b', 'B'))
    contract = builder.build()
    test = st.OperationContract(operation, contract)
    self.run_test_case(test)
Exemple #27
0
  def test_m_failure(self):
    """Example showing a typical test failure."""
    key = self.make_key('MyRandomKey')
    expect_value = 'My Key Value'

    operation = http_agent.HttpPostOperation(
        title='Writing Key Value',
        data=json.JSONEncoder().encode(expect_value),
        path='/put/' + key)
    builder = st.HttpContractBuilder(self.scenario.agent)
    (builder.new_clause_builder('Check For Wrong Value')
     .get_url_path('/lookup/' + key)
     .contains_path_eq('', 'Not ' + expect_value))
    contract = builder.build()

    test = st.OperationContract(operation, contract)
    self.run_test_case(test)
Exemple #28
0
  def test_a_put_string(self):
    """Example writes a string value then checks for it."""
    key = self.make_key('MyStringKey')
    expect_value = 'My Key Value'

    operation = http_agent.HttpPostOperation(
        title='Writing Key Value',
        data=json.JSONEncoder().encode(expect_value),
        path='/put/' + key)
    builder = st.HttpContractBuilder(self.scenario.agent)
    (builder.new_clause_builder('Check Key Value')
     .get_url_path('/lookup/' + key)
     .contains_path_eq('', expect_value))
    contract = builder.build()

    test = st.OperationContract(operation, contract)
    self.run_test_case(test)
Exemple #29
0
    def create_find_image_pipeline(self):
        name = 'findImagePipeline'
        self.pipeline_id = name
        smoke_stage = self.make_smoke_stage()
        deploy_stage = self.make_deploy_stage(imageSource='FINDIMAGE',
                                              requisiteStages=['FINDIMAGE'])

        pipeline_spec = dict(name=name,
                             stages=[smoke_stage, deploy_stage],
                             triggers=[],
                             application=self.TEST_APP,
                             stageCounter=2,
                             parallel=True,
                             limitConcurrent=True,
                             appConfig={},
                             index=0)

        payload = self.agent.make_json_payload_from_kwargs(**pipeline_spec)
        expect_match = {
            key: jp.EQUIVALENT(value)
            for key, value in pipeline_spec.items()
        }
        expect_match['stages'] = jp.LIST_MATCHES([
            jp.DICT_MATCHES({
                key: jp.EQUIVALENT(value)
                for key, value in smoke_stage.items()
            }),
            jp.DICT_MATCHES({
                key: jp.EQUIVALENT(value)
                for key, value in deploy_stage.items()
            })
        ])

        builder = st.HttpContractBuilder(self.agent)
        (builder.new_clause_builder(
            'Has Pipeline', retryable_for_secs=5).get_url_path(
                'applications/{app}/pipelineConfigs'.format(
                    app=self.TEST_APP)).contains_match(expect_match))

        return st.OperationContract(self.new_post_operation(
            title='create_find_image_pipeline',
            data=payload,
            path='pipelines',
            status_class=st.SynchronousHttpOperationStatus),
                                    contract=builder.build())
Exemple #30
0
  def test_b_put_dict(self):
    """Example writes a dict value then checks for parts of it."""
    key = self.make_key('MyDictKey')
    expect_value = {'a': 'A', 'b': 'B', 'c': 'C'}

    operation = http_agent.HttpPostOperation(
        title='Writing Key Value',
        data=json.JSONEncoder().encode(expect_value),
        path='/put/' + key)
    builder = st.HttpContractBuilder(self.scenario.agent)
    (builder.new_clause_builder('Check Key Value')
     .get_url_path('/lookup/' + key)
     .contains_match({'a': jp.EQUIVALENT('A'),
                      'b': jp.EQUIVALENT('B')}))
    contract = builder.build()

    test = st.OperationContract(operation, contract)
    self.run_test_case(test)