# Path: tests/util/snapshot_test_utils.py
# def assert_snap_not_blank(snapshot_url):
#     """ Asserts snapshot is not blank"""
#     pixels = read_image_as_raster(snapshot_url)
#     nt.ok_(pixels is not None
#            and isinstance(pixels, list)
#            and len(set(pixels)) > 2,
#            msg="Invalid or blank snapshot: {0}".format(snapshot_url))
#     for pixel in set(pixels):
#         nt.ok_(isinstance(pixel, tuple),
#                msg="Invalid snapshot: {0}".format(snapshot_url))
# 
# def assert_snap_has_no_events(snapshot_url):
#     """ Asserts snapshot has no events"""
#     pixels = read_image_as_raster(snapshot_url)
#     for color in set(pixels):
#         r, g, b, a = color  # red, green, blue, alpha
#         nt.ok_(r != 255 or g != 230 and b != 230,
#                msg="Snapshot should not have events: {0}".format(snapshot_url))


import datetime
import os
import time
import unittest
import nose.tools as nt
import simplejson as json
import dogapi
from nose.plugins.attrib import attr
from nose.tools import assert_equal as eq
from nose.tools import assert_true as ok
from dogapi.exceptions import *
from tests.util.snapshot_test_utils import (
    assert_snap_not_blank, assert_snap_has_no_events
)
        graph_def = {
            "viz": "toplist",
            "requests": [{
                "q": "top(system.disk.free{*} by {device}, 10, 'mean', 'desc')",
                "style": {
                    "palette": "dog_classic"
                },
                "conditional_formats": [{
                    "palette": "red",
                    "comparator": ">",
                    "value": 50000000000
                }, {
                    "palette": "green",
                    "comparator": ">",
                    "value": 30000000000
                }]
            }]
        }
        graph_def = json.dumps(graph_def)
        snap = dog.graph_snapshot_from_def(graph_def, start, end)
        ok('snapshot_url' in snap, msg=snap)
        ok('graph_def' in snap, msg=snap)
        ok('metric_query' not in snap, msg=snap)
        ok('event_query' not in snap, msg=snap)
        eq(snap['graph_def'], graph_def)
        snapshot_url = snap['snapshot_url']
        while dog.snapshot_status(snapshot_url) != 200:
            time.sleep(2)
        if 'localhost' in dog.api_host:
            snapshot_url = 'http://%s%s' % (dog.api_host, snapshot_url)

# Path: tests/util/snapshot_test_utils.py
# def assert_snap_not_blank(snapshot_url):
#     """ Asserts snapshot is not blank"""
#     pixels = read_image_as_raster(snapshot_url)
#     nt.ok_(pixels is not None
#            and isinstance(pixels, list)
#            and len(set(pixels)) > 2,
#            msg="Invalid or blank snapshot: {0}".format(snapshot_url))
#     for pixel in set(pixels):
#         nt.ok_(isinstance(pixel, tuple),
#                msg="Invalid snapshot: {0}".format(snapshot_url))
# 
# def assert_snap_has_no_events(snapshot_url):
#     """ Asserts snapshot has no events"""
#     pixels = read_image_as_raster(snapshot_url)
#     for color in set(pixels):
#         r, g, b, a = color  # red, green, blue, alpha
#         nt.ok_(r != 255 or g != 230 and b != 230,
#                msg="Snapshot should not have events: {0}".format(snapshot_url))


# Path: tests/integration/test_dog_http_api.py
import datetime
import os
import time
import unittest
import nose.tools as nt
import simplejson as json
import dogapi
from nose.plugins.attrib import attr
from nose.tools import assert_equal as eq
from nose.tools import assert_true as ok
from dogapi.exceptions import *
from tests.util.snapshot_test_utils import (
    assert_snap_not_blank, assert_snap_has_no_events
)

        graph_def = {
            "viz": "toplist",
            "requests": [{
                "q": "top(system.disk.free{*} by {device}, 10, 'mean', 'desc')",
                "style": {
                    "palette": "dog_classic"
                },
                "conditional_formats": [{
                    "palette": "red",
                    "comparator": ">",
                    "value": 50000000000
                }, {
                    "palette": "green",
                    "comparator": ">",
                    "value": 30000000000
                }]
            }]
        }
        graph_def = json.dumps(graph_def)
        snap = dog.graph_snapshot_from_def(graph_def, start, end)
        ok('snapshot_url' in snap, msg=snap)
        ok('graph_def' in snap, msg=snap)
        ok('metric_query' not in snap, msg=snap)
        ok('event_query' not in snap, msg=snap)
        eq(snap['graph_def'], graph_def)
        snapshot_url = snap['snapshot_url']
        while dog.snapshot_status(snapshot_url) != 200:
            time.sleep(2)
        if 'localhost' in dog.api_host:
            snapshot_url = 'http://%s%s' % (dog.api_host, snapshot_url)

        assert_snap_not_blank(snapshot_url)