예제 #1
0
    def testProduceProgramMetric(self):
        metric_key = {
            'gender': Gender.MALE,
            'methodology': MetricMethodologyType.PERSON,
            'year': 1999,
            'month': 3,
            'metric_type': ProgramMetricType.REFERRAL,
            'state_code': 'CA'
        }

        value = 10

        test_pipeline = TestPipeline()

        all_pipeline_options = PipelineOptions().get_all_options()

        job_timestamp = datetime.datetime.now().strftime(
            '%Y-%m-%d_%H_%M_%S.%f')
        all_pipeline_options['job_timestamp'] = job_timestamp

        output = (
            test_pipeline
            | beam.Create([(metric_key, value)])
            | 'Produce Program Metric' >> beam.ParDo(
                pipeline.ProduceProgramMetrics(), **all_pipeline_options))

        assert_that(output,
                    AssertMatchers.validate_program_referral_metric(value))

        test_pipeline.run()
예제 #2
0
    def testProduceProgramMetric_EmptyMetric(self):
        metric_key_dict = {}

        metric_key = json.dumps(json_serializable_metric_key(metric_key_dict),
                                sort_keys=True)

        value = 102

        test_pipeline = TestPipeline()

        all_pipeline_options = PipelineOptions().get_all_options()

        job_timestamp = datetime.datetime.now().strftime(
            '%Y-%m-%d_%H_%M_%S.%f')
        all_pipeline_options['job_timestamp'] = job_timestamp

        output = (
            test_pipeline
            | beam.Create([(metric_key, value)])
            | 'Produce Program Metric' >> beam.ParDo(
                pipeline.ProduceProgramMetrics(), **all_pipeline_options))

        assert_that(output, equal_to([]))

        test_pipeline.run()
예제 #3
0
    def testProduceProgramMetric(self):
        metric_key = {
            "gender": Gender.MALE,
            "year": 1999,
            "month": 3,
            "metric_type": ProgramMetricType.PROGRAM_REFERRAL,
            "state_code": "US_XX",
        }

        value = 10

        test_pipeline = TestPipeline()

        all_pipeline_options = PipelineOptions().get_all_options()

        job_timestamp = datetime.datetime.now().strftime("%Y-%m-%d_%H_%M_%S.%f")
        all_pipeline_options["job_timestamp"] = job_timestamp

        output = (
            test_pipeline
            | beam.Create([(metric_key, value)])
            | "Produce Program Metric"
            >> beam.ParDo(pipeline.ProduceProgramMetrics(), **all_pipeline_options)
        )

        assert_that(output, AssertMatchers.validate_program_referral_metric())

        test_pipeline.run()
예제 #4
0
    def testProduceProgramMetric_EmptyMetric(self):
        metric_key = {}

        value = 102

        test_pipeline = TestPipeline()

        all_pipeline_options = PipelineOptions().get_all_options()

        job_timestamp = datetime.datetime.now().strftime(
            '%Y-%m-%d_%H_%M_%S.%f')
        all_pipeline_options['job_timestamp'] = job_timestamp

        # This should never happen, and we want the pipeline to fail loudly if it does.
        with pytest.raises(ValueError):
            _ = (test_pipeline
                 | beam.Create([(metric_key, value)])
                 | 'Produce Program Metric' >> beam.ParDo(
                     pipeline.ProduceProgramMetrics(), **all_pipeline_options))

            test_pipeline.run()