示例#1
0
def test_aggregate_and_send_metrics():
    responses.add(responses.POST, FULL_METRICS_URL, json={}, status=200)

    last_run_datetime = datetime.datetime.now() - datetime.timedelta(
        seconds=30)
    strategies = [RemoteAddress(parameters={"IPs": IP_LIST}), Default()]
    my_feature1 = Feature("My Feature1", True, strategies)
    my_feature1.yes_count = 1
    my_feature1.no_count = 1

    my_feature2 = Feature("My Feature2", True, strategies)
    my_feature2.yes_count = 2
    my_feature2.no_count = 2

    features = {"My Feature1": my_feature1, "My Feature 2": my_feature2}

    aggregate_and_send_metrics(URL, APP_NAME, INSTANCE_ID, CUSTOM_HEADERS,
                               features, last_run_datetime)

    assert len(responses.calls) == 1
    request = json.loads(responses.calls[0].request.body)

    assert len(request['bucket']["toggles"].keys()) == 2
    assert request['bucket']["toggles"]["My Feature1"]["yes"] == 1
    assert request['bucket']["toggles"]["My Feature1"]["no"] == 1
示例#2
0
def test_aggregate_and_send_metrics():
    responses.add(responses.POST, FULL_METRICS_URL, json={}, status=200)

    start_time = datetime.now(pytz.utc) - timedelta(seconds=60)
    cache = FileCache("TestCache")
    cache[METRIC_LAST_SENT_TIME] = start_time
    strategies = [RemoteAddress(parameters={"IPs": IP_LIST}), Default()]
    my_feature1 = Feature("My Feature1", True, strategies)
    my_feature1.yes_count = 1
    my_feature1.no_count = 1

    my_feature2 = Feature("My Feature2", True, strategies)
    my_feature2.yes_count = 2
    my_feature2.no_count = 2

    features = {"My Feature1": my_feature1, "My Feature 2": my_feature2}

    aggregate_and_send_metrics(URL, APP_NAME, INSTANCE_ID, CUSTOM_HEADERS,
                               CUSTOM_OPTIONS, features, cache)

    assert len(responses.calls) == 1
    request = json.loads(responses.calls[0].request.body)

    assert len(request['bucket']["toggles"].keys()) == 2
    assert request['bucket']["toggles"]["My Feature1"]["yes"] == 1
    assert request['bucket']["toggles"]["My Feature1"]["no"] == 1
    assert cache[METRIC_LAST_SENT_TIME] > start_time
示例#3
0
 def close(self):
     metrics_args = {
         "url": self.unleash_url,
         "app_name": self.unleash_app_name,
         "instance_id": self.unleash_instance_id,
         "custom_headers": self.unleash_custom_headers,
         "custom_options": self.unleash_custom_options,
         "features": self.features,
         "ondisk_cache": self.cache
     }
     aggregate_and_send_metrics(**metrics_args)
def test_no_metrics():
    responses.add(responses.POST, FULL_METRICS_URL, json={}, status=200)

    start_time = datetime.now(timezone.utc) - timedelta(seconds=60)
    cache = FileCache("TestCache")
    cache.set(METRIC_LAST_SENT_TIME, start_time)
    strategies = [RemoteAddress(parameters={"IPs": IP_LIST}), Default()]

    my_feature1 = Feature("My Feature1", True, strategies)
    my_feature1.yes_count = 0
    my_feature1.no_count = 0

    features = {"My Feature1": my_feature1}

    aggregate_and_send_metrics(URL, APP_NAME, INSTANCE_ID, CUSTOM_HEADERS,
                               CUSTOM_OPTIONS, features, cache)

    assert len(responses.calls) == 0