pax_global_header00006660000000000000000000000064146362126120014515gustar00rootroot0000000000000052 comment=636dca9b2f0b8d6a383739df3715ac4877e05ac9 PyFlume-0.8.7/000077500000000000000000000000001463621261200131125ustar00rootroot00000000000000PyFlume-0.8.7/.github/000077500000000000000000000000001463621261200144525ustar00rootroot00000000000000PyFlume-0.8.7/.github/workflows/000077500000000000000000000000001463621261200165075ustar00rootroot00000000000000PyFlume-0.8.7/.github/workflows/python-package.yml000066400000000000000000000015561463621261200221530ustar00rootroot00000000000000# This workflow will install Python dependencies, run tests and lint with a variety of Python versions # For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions name: Package Validation and Tests on: [push, pull_request] jobs: build: runs-on: ubuntu-latest strategy: matrix: python-version: [3.11, 3.12] steps: - uses: actions/checkout@v2 - name: Set up Python ${{ matrix.python-version }} uses: actions/setup-python@v2 with: python-version: ${{ matrix.python-version }} - name: wemake-python-styleguide uses: wemake-services/wemake-python-styleguide@0.19.2 - name: Install dependencies run: | python -m pip install --upgrade pip python -m pip install tox - name: Test with tox run: | python -m tox PyFlume-0.8.7/.github/workflows/python-public-prerelease.yml000066400000000000000000000020061463621261200241520ustar00rootroot00000000000000# This workflows will upload a Python Package using Twine when a release is created # For more information see: https://help.github.com/en/actions/language-and-framework-guides/using-python-with-github-actions#publishing-to-package-registries name: Upload Python Package Prerelease on: release: types: [prereleased] jobs: deploy: runs-on: ubuntu-latest permissions: # IMPORTANT: this permission is mandatory for trusted publishing id-token: write steps: - uses: actions/checkout@v2 - name: Set up Python uses: actions/setup-python@v2 with: python-version: '3.x' - name: Install dependencies run: | python -m pip install --upgrade pip pip install setuptools wheel twine - name: Build run: | python setup.py sdist # retrieve your distributions here - name: Publish package distributions to TestPyPI uses: pypa/gh-action-pypi-publish@release/v1 with: repository-url: https://test.pypi.org/legacy/ PyFlume-0.8.7/.github/workflows/python-public-release.yml000066400000000000000000000016731463621261200234540ustar00rootroot00000000000000# This workflows will upload a Python Package using Twine when a release is created # For more information see: https://help.github.com/en/actions/language-and-framework-guides/using-python-with-github-actions#publishing-to-package-registries name: Upload Python Package Release on: release: types: [released] jobs: deploy: runs-on: ubuntu-latest permissions: # IMPORTANT: this permission is mandatory for trusted publishing id-token: write steps: - uses: actions/checkout@v2 - name: Set up Python uses: actions/setup-python@v2 with: python-version: '3.x' - name: Install dependencies run: | python -m pip install --upgrade pip pip install setuptools wheel twine - name: Build run: | python setup.py sdist # retrieve your distributions here - name: Publish package distributions to PyPI uses: pypa/gh-action-pypi-publish@release/v1 PyFlume-0.8.7/.gitignore000066400000000000000000000002141463621261200150770ustar00rootroot00000000000000flume_token flume.log build/* dist/* pyflume/__pycache__ PyFlume.egg-info .idea/* .vscode .vscode/* .tox .tox/* *pyc __pycache__PyFlume-0.8.7/LICENSE000066400000000000000000000021031463621261200141130ustar00rootroot00000000000000MIT License Copyright (c) 2019 Chris Mandich Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. PyFlume-0.8.7/README.md000066400000000000000000000045311463621261200143740ustar00rootroot00000000000000# Flume API Integration ## Overview The Flume API Integration provides a comprehensive set of classes and methods to interact with various Flume endpoints. This integration allows developers to retrieve and manage notifications, usage alerts, devices, leak alerts, data, and authentication within the Flume environment. ## Retrieve API Key You can find your Client ID and Client Secret under "API Access" on the [settings page](https://portal.flumewater.com/settings). These credentials are essential for interacting with the Flume API. ## Modules Below are the details of each module, each documented in its corresponding file: ### Notifications Retrieve notifications from the Flume API, including filtering based on the read status. - [Read the Notifications documentation](https://github.com/ChrisMandich/PyFlume/blob/master/docs/notifications.md) ### Usage Alerts Manage and retrieve usage alert notifications from the Flume API. - [Read the Usage Alerts documentation](https://github.com/ChrisMandich/PyFlume/blob/master/docs/usage.md) ### Devices Retrieve information related to Flume devices, including their list from the API. - [Read the Devices documentation](https://github.com/ChrisMandich/PyFlume/blob/master/docs/devices.md) ### Leak Alerts Manage and retrieve leak notifications from the Flume API. - [Read the Leak Alerts documentation](https://github.com/ChrisMandich/PyFlume/blob/master/docs/leak.md) ### Data Retrieval Retrieve and update data from the Flume API, working with authentication and various data endpoints. - [Read the Data Retrieval documentation](https://github.com/ChrisMandich/PyFlume/blob/master/docs/data.md) ### Authentication Authentication module to handle tokens and user credentials within the Flume environment. - [Read the Authentication documentation](https://github.com/ChrisMandich/PyFlume/blob/master/docs/auth.md) ## Getting Started To get started with the Flume API Integration, refer to the individual documentation files for each module. They provide detailed information on dependencies, initialization, methods, and example usage. For any questions or additional support, please refer to the official Flume API documentation or contact the development team. ## Contributing Feel free to contribute to the codebase by opening issues, submitting pull requests, or suggesting improvements.PyFlume-0.8.7/docs/000077500000000000000000000000001463621261200140425ustar00rootroot00000000000000PyFlume-0.8.7/docs/auth.md000066400000000000000000000027231463621261200153310ustar00rootroot00000000000000 # FlumeAuth ## Overview `FlumeAuth` is a Python class designed to interact with Flume API Authentication. This class facilitates the authentication process with the API by handling token retrieval, refreshing, verification, and managing related credentials. ## Dependencies - pyjwt ## Initialization To initialize the FlumeAuth object, you'll need the following parameters: - `username`: Username to authenticate. - `password`: Password to authenticate. - `client_id`: API client id. - `client_secret`: API client secret. - `flume_token`: (Optional) Pass a Flume token to the variable. - `http_session`: (Optional) Requests Session() object. - `timeout`: (Optional) Requests timeout for throttling. Default value is specified in DEFAULT_TIMEOUT. ## Methods Token Retrieval and Management `token` Property that returns the current JWT token. `refresh_token()` Method to refresh the authorization token for the session. `retrieve_token()` Method to return the authorization token for the session. ## Internals There are also some internal methods that handle loading and verifying the token, such as _load_token(token) and _request_token(payload). These are used internally by the class to manage the token lifecycle. ## Example: ```python import pyflume auth = pyflume.FlumeAuth( username='your_username', password='your_password', client_id='client_id', client_secret='client_secret' ) auth.retrieve_token() print(auth.token) # Prints the current JWT token ```PyFlume-0.8.7/docs/data.md000066400000000000000000000034621463621261200153020ustar00rootroot00000000000000# FlumeData ## Overview FlumeData is a Python class responsible for retrieving and updating data from the Flume API. It works in tandem with the FlumeAuth class for authentication and provides an interface to interact with various Flume data endpoints. ## Dependencies - ratelimit - requests - Python ≥ 3.9 or the backports.zoneinfo package for earlier versions. ## Initialization To initialize the FlumeData object, you'll need the following parameters: - `flume_auth`: FlumeAuth object for authentication. - `device_id`: Flume device id. - `device_tz`: Timezone of the device. - `scan_interval`: Duration of the scan (e.g., 60 minutes). - `update_on_init`: (Optional) Whether to update on initialization. Default is True. - `http_session`: (Optional) Requests Session() object. - `timeout`: (Optional) Requests timeout for throttling. Default value is specified in DEFAULT_TIMEOUT. - `query_payload`: (Optional) Specific query payload to request for the device. ## Methods Update Methods `update()` Method to return updated values for the session. Adheres to API call limits. `update_force()` Method to return updated values for the session without auto-retry or limits. ## Internals There are also some internal methods that handle the generation of the API query payload and other functionalities. Most users will not need to interact with these directly. ## Example ```python import pyflume from datetime import timedelta auth = pyflume.FlumeAuth( username='your_username', password='your_password', client_id='client_id', client_secret='client_secret' ) auth.retrieve_token() data = pyflume.FlumeData( flume_auth=auth, device_id='your_device_id', device_tz='your_timezone', scan_interval=timedelta(minutes=60) ) data.update() print(data.values) # Prints the current data values ```PyFlume-0.8.7/docs/devices.md000066400000000000000000000021561463621261200160120ustar00rootroot00000000000000# FlumeDeviceList ## Overview FlumeDeviceList is a Python class designed to retrieve the Flume device list from the Flume API. It leverages the authentication handled by FlumeAuth and provides an interface to access the list of devices associated with the user account. ## Dependencies - requests ## Initialization To initialize the FlumeDeviceList object, you'll need the following parameters: - `flume_auth`: FlumeAuth object for authentication. - `http_session`: (Optional) Requests Session() object. - `timeout`: (Optional) Requests timeout for throttling. The default value is specified in DEFAULT_TIMEOUT. ## Methods Device Retrieval `get_devices()` Method to return all available devices from the Flume API. This method fetches the JSON device list. Example ```python import pyflume auth = pyflume.FlumeAuth( username='your_username', password='your_password', client_id='client_id', client_secret='client_secret' ) auth.retrieve_token() device_list_obj = pyflume.FlumeDeviceList( flume_auth=auth ) device_list = device_list_obj.get_devices() print(device_list) # Prints the JSON device list ```PyFlume-0.8.7/docs/leak.md000066400000000000000000000025511463621261200153030ustar00rootroot00000000000000# FlumeLeakList ## Overview FlumeLeakList is a Python class designed to retrieve leak notifications from the Flume API. The class can query leak alerts for specific devices and provides control over the state of the notification list (read or not read). ## Dependencies - requests ## Initialization To initialize the FlumeLeakList object, you'll need the following parameters: - `flume_auth`: FlumeAuth object for authentication. - `device_id`: The Device ID to query. - `http_session`: (Optional) Requests Session() object. - `timeout`: (Optional) Requests timeout for throttling. The default value is specified in DEFAULT_TIMEOUT. - `read`: (Optional) State of leak notification list; specifies if they have been read or not read. Default is "false." ## Methods Leak Notification Retrieval `get_leaks()` Method to return all leak alerts from devices owned by the user. This method fetches the JSON list of leak notifications, sorted in ascending order. ## Example ```python import pyflume auth = pyflume.FlumeAuth( username='your_username', password='your_password', client_id='client_id', client_secret='client_secret' ) auth.retrieve_token() leak_list_obj = pyflume.FlumeLeakList( flume_auth=auth, device_id='your_device_id' ) leak_alert_list = leak_list_obj.get_leaks() print(leak_alert_list) # Prints the JSON list of leak notifications ```PyFlume-0.8.7/docs/notifications.md000066400000000000000000000040071463621261200172360ustar00rootroot00000000000000# FlumeNotificationList ## Overview FlumeNotificationList is a Python class for retrieving notifications from the Flume API. This class allows querying of notifications from devices owned by the user and provides control over the state of the notification list (read or not read). ## Dependencies - requests ## Initialization To initialize the FlumeNotificationList object, you'll need the following parameters: - `flume_auth`: FlumeAuth object for authentication. - `http_session`: (Optional) Requests Session() object. - `timeout`: (Optional) Requests timeout for throttling. The default value is specified in DEFAULT_TIMEOUT. - `read`: (Optional) State of notification list; specifies if they have been read or not read. Default is "false." ## Methods Notification Retrieval `get_notifications()` Method to return all notifications from devices owned by the user. This method fetches a JSON dictionary containing the notification messages. `get_next_notifications()` Method to return the next page of notifications from devices owned by the user. Raises a ValueError if no next page is available. Raises: - `ValueError`: If no next page is available. `_has_next_page(response_json)` Returns True if the next page exists. Used internally to handle pagination. `_get_notification_request(api_url, query_string)` Make an API request to get usage alerts from the Flume API. ## Example ```python import pyflume auth = pyflume.FlumeAuth( username='your_username', password='your_password', client_id='client_id', client_secret='client_secret' ) auth.retrieve_token() notification_list_obj = pyflume.FlumeNotificationList( flume_auth=auth ) notification_list = notification_list_obj.get_notifications() print(notification_list) # Prints the JSON dictionary of notifications ``` For subsequent pages: ```python if notification_list_obj.has_next: next_page_notifications = notification_list_obj.get_next_notifications() print(next_page_notifications) # Prints the JSON list of notifications for the next page ```PyFlume-0.8.7/docs/usage.md000066400000000000000000000037631463621261200155010ustar00rootroot00000000000000# FlumeUsageAlertList ## Overview FlumeUsageAlertList is a Python class designed to retrieve usage alert notifications from the Flume API. This class enables querying of usage alerts from devices owned by the user and provides control over the state of the usage alert list (read or not read). ## Dependencies - requests ## Initialization To initialize the FlumeUsageAlertList object, you'll need the following parameters: - `flume_auth`: FlumeAuth object for authentication. - `http_session`: (Optional) Requests Session() object. - `timeout`: (Optional) Requests timeout for throttling. The default value is specified in DEFAULT_TIMEOUT. - `read`: (Optional) State of usage alert list; specifies if they have been read or not read. Default is "false." ## Methods Usage Alert Retrieval `get_usage_alerts()` Method to return all usage alerts from devices owned by the user. This method fetches a JSON list containing the usage alerts. `get_next_usage_alerts()` Method to return the next page of usage alerts from devices owned by the user. This method fetches a JSON list containing the usage alerts for the next page. Raises: - `ValueError`: If no next page is available. `_has_next_page(response_json)` Returns True if the next page exists. Used internally to handle pagination. `_get_usage_request(api_url, query_string)` Makes an API request to get usage alerts from the Flume API. ## Example ```python import pyflume auth = pyflume.FlumeAuth( username='your_username', password='your_password', client_id='client_id', client_secret='client_secret' ) auth.retrieve_token() usage_alert_list_obj = pyflume.FlumeUsageAlertList( flume_auth=auth ) usage_alert_list = usage_alert_list_obj.get_usage_alerts() print(usage_alert_list) # Prints the JSON list of usage alerts ``` For subsequent pages: ```python if usage_alert_list_obj.has_next: next_page_alerts = usage_alert_list_obj.get_next_usage_alerts() print(next_page_alerts) # Prints the JSON list of usage alerts for the next page ```PyFlume-0.8.7/pyflume/000077500000000000000000000000001463621261200145735ustar00rootroot00000000000000PyFlume-0.8.7/pyflume/__init__.py000066400000000000000000000007461463621261200167130ustar00rootroot00000000000000"""Authenticates to Flume API, returns a list of devices and allows you to pull the latest sensor results over a period of time.""" from .auth import FlumeAuth # noqa: WPS300, F401 from .data import FlumeData # noqa: WPS300, F401 from .devices import FlumeDeviceList # noqa: WPS300, F401 from .leak import FlumeLeakList # noqa: WPS300, F401 from .notifications import FlumeNotificationList # noqa: WPS300, F401 from .usage import FlumeUsageAlertList # noqa: WPS300, F401 PyFlume-0.8.7/pyflume/auth.py000066400000000000000000000111471463621261200161120ustar00rootroot00000000000000"""Authenticates to Flume API.""" from datetime import datetime, timedelta import json import jwt # install pyjwt from requests import Session from .constants import DEFAULT_TIMEOUT, URL_OAUTH_TOKEN # noqa: WPS300 from .utils import configure_logger, flume_response_error # noqa: WPS300 # Configure logging LOGGER = configure_logger(__name__) class FlumeAuth: # noqa: WPS214 """Interact with API Authentication.""" def __init__( # noqa: WPS211 self, username, password, client_id, client_secret, flume_token=None, http_session=None, timeout=DEFAULT_TIMEOUT, ): """ Initialize the data object. Args: username: Username to authenticate. password: Password to authenticate. client_id: API client id. client_secret: API client secret. flume_token: Pass flume token to variable. http_session: Requests Session() timeout: Requests timeout for throttling. """ self._creds = { "client_id": client_id, "client_secret": client_secret, "username": username, "password": password, } if http_session is None: self._http_session = Session() else: self._http_session = http_session self._timeout = timeout self._token = None self._decoded_token = None self.user_id = None self.authorization_header = None self._load_token(flume_token) self._verify_token() @property def token(self): """ Return authorization token for session. Returns: Returns the current JWT token. """ return self._token def refresh_token(self): """Refresh authorization token for session.""" payload = { "grant_type": "refresh_token", "refresh_token": self._token["refresh_token"], "client_id": self._creds["client_id"], "client_secret": self._creds["client_secret"], } self._load_token(self._request_token(payload)) def retrieve_token(self): """Return authorization token for session.""" payload = dict({"grant_type": "password"}, **self._creds) self._load_token(self._request_token(payload)) def _load_token(self, token): """ Update _token, decode token, user_id and auth header. Args: token: Authentication bearer token to be decoded. """ jwt_options = {"verify_signature": False} self._token = token try: self._decoded_token = jwt.decode( self._token["access_token"], options=jwt_options, ) except jwt.exceptions.DecodeError: LOGGER.debug("Poorly formatted Access Token, fetching token using _creds") self.retrieve_token() except TypeError: LOGGER.debug("Token TypeError, fetching token using _creds") self.retrieve_token() self.user_id = self._decoded_token["user_id"] self.authorization_header = { "authorization": "Bearer {0}".format(self._token.get("access_token")), } def _request_token(self, payload): """ Request Authorization Payload. Args: payload: Request payload to get token request. Returns: Return response Authentication Bearer token from request. """ headers = {"content-type": "application/json"} response = self._http_session.request( "POST", URL_OAUTH_TOKEN, json=payload, headers=headers, timeout=self._timeout, ) LOGGER.debug("Token Payload: %s", payload) # noqa: WPS323 LOGGER.debug("Token Response: %s", response.text) # noqa: WPS323 # Check for response errors. flume_response_error( "Can't get token for user {0}".format(self._creds.get("username")), response, ) return json.loads(response.text)["data"][0] def _verify_token(self): """Check to see if token is expiring in 12 hours.""" token_expiration = datetime.fromtimestamp(self._decoded_token["exp"]) time_difference = datetime.now() + timedelta(hours=12) # noqa: WPS432 LOGGER.debug("Token expiration time: %s", token_expiration) # noqa: WPS323 LOGGER.debug("Token comparison time: %s", time_difference) # noqa: WPS323 if token_expiration <= time_difference: self.refresh_token() PyFlume-0.8.7/pyflume/constants.py000066400000000000000000000012321463621261200171570ustar00rootroot00000000000000"""Constants to support PyFlume.""" # Time-related constants API_LIMIT = 60 DEFAULT_TIMEOUT = 30 # Operation constants CONST_OPERATION = "SUM" CONST_UNIT_OF_MEASUREMENT = "GALLONS" # Base URL API_BASE_URL = "https://api.flumetech.com" # Endpoints URL_OAUTH_TOKEN = f"{API_BASE_URL}/oauth/token" API_QUERY_URL = f"{API_BASE_URL}/users/{{user_id}}/devices/{{device_id}}/query" API_DEVICES_URL = f"{API_BASE_URL}/users/{{user_id}}/devices" API_NOTIFICATIONS_URL = f"{API_BASE_URL}/users/{{user_id}}/notifications" API_LEAK_URL = f"{API_BASE_URL}/users/{{user_id}}/devices/{{device_id}}/leaks/active" API_USAGE_URL = f"{API_BASE_URL}/users/{{user_id}}/usage-alerts" PyFlume-0.8.7/pyflume/data.py000066400000000000000000000163011463621261200160570ustar00rootroot00000000000000"""Retrieve data from Flume API.""" from datetime import datetime, timedelta, timezone from ratelimit import limits, sleep_and_retry from requests import Session from .constants import ( # noqa: WPS300 API_LIMIT, API_QUERY_URL, CONST_OPERATION, CONST_UNIT_OF_MEASUREMENT, DEFAULT_TIMEOUT, ) from .utils import ( # noqa: WPS300 configure_logger, flume_response_error, format_start_month, format_start_today, format_start_week, format_time, ) try: from zoneinfo import ZoneInfo # noqa: WPS433 except ImportError: # Python < 3.9 from backports.zoneinfo import ZoneInfo # noqa: WPS433,WPS440 # Configure logging LOGGER = configure_logger(__name__) class FlumeData: """Get the latest data and update the states.""" def __init__( # noqa: WPS211 self, flume_auth, device_id, device_tz, scan_interval, update_on_init=True, http_session=None, timeout=DEFAULT_TIMEOUT, query_payload=None, ): """ Initialize the data object. Args: flume_auth: Authentication object. device_id: flume device id. device_tz: timezone of device scan_interval: duration of scan, ex: 60 minutes. update_on_init: update on initialization. http_session: Requests Session() timeout: Requests timeout for throttling. query_payload: Specific query_payload to request for device. """ self._timeout = timeout self._flume_auth = flume_auth self._scan_interval = scan_interval self.device_id = device_id self.device_tz = device_tz self.values = {} # noqa: WPS110 if query_payload is None: self.query_payload = self._generate_api_query_payload( self._scan_interval, device_tz, ) else: self.query_payload = query_payload if http_session is None: self._http_session = Session() else: self._http_session = http_session self._query_keys = [ query["request_id"] for query in self.query_payload["queries"] ] if update_on_init: self.update() @sleep_and_retry @limits(calls=2, period=API_LIMIT) def update(self): """ Return updated value for session. Returns: Returns status of update """ return self.update_force() def update_force(self): """Return updated value for session without auto retry or limits.""" self.query_payload = self._generate_api_query_payload( self._scan_interval, self.device_tz, ) url = API_QUERY_URL.format( user_id=self._flume_auth.user_id, device_id=self.device_id, ) response = self._http_session.post( url, json=self.query_payload, headers=self._flume_auth.authorization_header, timeout=self._timeout, ) LOGGER.debug("Update URL: %s", url) # noqa: WPS323 LOGGER.debug("Update query_payload: %s", self.query_payload) # noqa: WPS323 LOGGER.debug("Update Response: %s", response.text) # noqa: WPS323 # Check for response errors. flume_response_error( "Can't update flume data for user id {0}".format(self._flume_auth.user_id), response, ) responses = response.json()["data"][0] # Step 1: Initialize an empty dictionary values_dict = {} # Step 2: Loop through each key in self._query_keys for key in self._query_keys: # Step 3: Check the length of the responses for the current key if len(responses[key]) == 1: # Step 4: Assign the value to the dictionary if the condition is met values_dict[key] = responses[key][0]["value"] else: # Step 5: Assign None to the dictionary if the condition is not met values_dict[key] = None # Step 6: Assign the result to self.values self.values = values_dict # noqa: WPS110 def _generate_api_query_payload(self, scan_interval, device_tz): """Generate API Query payload to support getting data from Flume API. Args: scan_interval (_type_): Interval to scan. device_tz (_type_): Time Zone of Flume device. Returns: JSON: API Query to retrieve API details. """ datetime_localtime = datetime.now(timezone.utc).astimezone(ZoneInfo(device_tz)) queries = [ { "request_id": "current_interval", "bucket": "MIN", "since_datetime": format_time( (datetime_localtime - scan_interval).replace(second=0), ), "until_datetime": format_time(datetime_localtime.replace(second=0)), "operation": CONST_OPERATION, "units": CONST_UNIT_OF_MEASUREMENT, }, { "request_id": "today", "bucket": "DAY", "since_datetime": format_start_today(datetime_localtime), "until_datetime": format_time(datetime_localtime), "operation": CONST_OPERATION, "units": CONST_UNIT_OF_MEASUREMENT, }, { "request_id": "week_to_date", "bucket": "DAY", "since_datetime": format_start_week(datetime_localtime), "until_datetime": format_time(datetime_localtime), "operation": CONST_OPERATION, "units": CONST_UNIT_OF_MEASUREMENT, }, { "request_id": "month_to_date", "bucket": "MON", "since_datetime": format_start_month(datetime_localtime), "until_datetime": format_time(datetime_localtime), "units": CONST_UNIT_OF_MEASUREMENT, }, { "request_id": "last_60_min", "bucket": "MIN", "since_datetime": format_time( datetime_localtime - timedelta(minutes=60), ), "until_datetime": format_time(datetime_localtime), "operation": CONST_OPERATION, "units": CONST_UNIT_OF_MEASUREMENT, }, { "request_id": "last_24_hrs", "bucket": "HR", "since_datetime": format_time(datetime_localtime - timedelta(hours=24)), "until_datetime": format_time(datetime_localtime), "operation": CONST_OPERATION, "units": CONST_UNIT_OF_MEASUREMENT, }, { "request_id": "last_30_days", "bucket": "DAY", "since_datetime": format_time( datetime_localtime - timedelta(days=30), # noqa: WPS432 ), "until_datetime": format_time(datetime_localtime), "operation": CONST_OPERATION, "units": CONST_UNIT_OF_MEASUREMENT, }, ] return {"queries": queries} PyFlume-0.8.7/pyflume/devices.py000066400000000000000000000032141463621261200165670ustar00rootroot00000000000000"""Retrieve Devices from Flume API.""" from requests import Session from .constants import API_DEVICES_URL, DEFAULT_TIMEOUT # noqa: WPS300 from .utils import configure_logger, flume_response_error # noqa: WPS300 # Configure logging LOGGER = configure_logger(__name__) class FlumeDeviceList: """Get Flume Device List from API.""" def __init__( self, flume_auth, http_session=None, timeout=DEFAULT_TIMEOUT, ): """ Initialize the data object. Args: flume_auth: Authentication object. http_session: Requests Session() timeout: Requests timeout for throttling. """ self._timeout = timeout self._flume_auth = flume_auth if http_session is None: self._http_session = Session() else: self._http_session = http_session self.device_list = self.get_devices() def get_devices(self): """ Return all available devices from Flume API. Returns: Json device list. """ url = API_DEVICES_URL.format(user_id=self._flume_auth.user_id) query_string = {"user": "true", "location": "true"} response = self._http_session.request( "GET", url, headers=self._flume_auth.authorization_header, params=query_string, timeout=self._timeout, ) LOGGER.debug("get_devices Response: %s", response.text) # noqa: WPS323 # Check for response errors. flume_response_error("Impossible to retreive devices", response) return response.json()["data"] PyFlume-0.8.7/pyflume/leak.py000066400000000000000000000040721463621261200160640ustar00rootroot00000000000000"""Retrieve leak notifications from Flume API.""" from requests import Session from .constants import API_LEAK_URL, DEFAULT_TIMEOUT # noqa: WPS300 from .utils import configure_logger, flume_response_error # noqa: WPS300 # Configure logging LOGGER = configure_logger(__name__) class FlumeLeakList: """Get Flume Flume Leak Notifications from API.""" def __init__( # noqa: WPS211 self, flume_auth, device_id, http_session=None, timeout=DEFAULT_TIMEOUT, read="false", ): """ Initialize the data object. Args: flume_auth: Authentication object. device_id: The Device ID to query. http_session: Requests Session() timeout: Requests timeout for throttling. read: state of leak notification list, have they been read, not read. """ self._timeout = timeout self._flume_auth = flume_auth self._read = read self.device_id = device_id if http_session is None: self._http_session = Session() else: self._http_session = http_session self.leak_alert_list = self.get_leaks() def get_leaks(self): """Return all leak alerts from devices owned by the user. Returns: Returns JSON list of leak notifications. """ url = API_LEAK_URL.format( user_id=self._flume_auth.user_id, device_id=self.device_id, ) query_string = { "limit": "50", "offset": "0", "sort_direction": "ASC", "read": self._read, } response = self._http_session.request( "GET", url, headers=self._flume_auth.authorization_header, params=query_string, timeout=self._timeout, ) LOGGER.debug(f"get_leaks Response: {response.text}") # Check for response errors. flume_response_error("Impossible to retrieve leak alerts", response) return response.json()["data"] PyFlume-0.8.7/pyflume/notifications.py000066400000000000000000000101711463621261200200160ustar00rootroot00000000000000"""Retrieve notifications from Flume API.""" from typing import Any, Dict, Optional from requests import Session from .constants import ( # noqa: WPS300 API_BASE_URL, API_NOTIFICATIONS_URL, DEFAULT_TIMEOUT, ) from .utils import configure_logger, flume_response_error # noqa: WPS300 # Configure logging LOGGER = configure_logger(__name__) class FlumeNotificationList: """Get Flume Notifications list from API.""" def __init__( # noqa: WPS211 self, flume_auth, http_session: Optional[Session] = None, timeout: int = DEFAULT_TIMEOUT, read: str = "false", sort_direction: str = "ASC", ) -> None: """ Initialize the FlumeNotificationList object. Args: flume_auth: Authentication object. http_session: Optional Requests Session(). timeout: Requests timeout for throttling, default DEFAULT_TIMEOUT. read: state of notification list, default "false". sort_direction: Which direction to sort notifications on, default "ASC". """ self._timeout = timeout self._flume_auth = flume_auth self._read = read self._sort_direction = sort_direction self._http_session = http_session or Session() self.has_next = False self.next_page = None self.notification_list = self.get_notifications() def get_notifications(self) -> Dict[str, Any]: """Return all notifications from devices owned by the user. Returns: Dict[str, Any]: Notification JSON message from API. """ api_url = API_NOTIFICATIONS_URL.format(user_id=self._flume_auth.user_id) query_string = { "limit": "50", "offset": "0", "sort_direction": self._sort_direction, "read": self._read, } return self._get_notification_request(api_url, query_string) def get_next_notifications(self): """Return next page of notification from devices owned by the user. Returns: Returns JSON list of notifications. Raises: ValueError: If no next page is available. """ if self.has_next: api_url = f"{API_BASE_URL}{self.next_page}" query_string = {} else: raise ValueError("No next page available.") return self._get_notification_request(api_url, query_string) def _has_next_page(self, response_json): """Return True if the next page exists. Args: response_json (Object): Response from API. Returns: Boolean: Returns true if next page exists, False if not. """ if response_json is None or response_json.get("pagination") is None: return False return ( "next" in response_json["pagination"] and response_json["pagination"]["next"] is not None ) def _get_notification_request(self, api_url, query_string): """Make an API request to get usage alerts from the Flume API. Args: api_url (string): URL for request query_string (object): query string options Returns: object: Reponse in JSON format from API. """ response = self._http_session.request( "GET", api_url, headers=self._flume_auth.authorization_header, params=query_string, timeout=self._timeout, ) LOGGER.debug(f"_get_notification_request Response: {response.text}") # Check for response errors. flume_response_error("Impossible to retrieve notifications", response) response_json = response.json() if self._has_next_page(response_json): self.next_page = response_json["pagination"]["next"] self.has_next = True LOGGER.debug( f"Next page for Notification results: {self.next_page}", ) else: self.has_next = False self.next_page = None LOGGER.debug("No further pages for Notification results.") return response_json["data"] PyFlume-0.8.7/pyflume/usage.py000066400000000000000000000074501463621261200162570ustar00rootroot00000000000000"""Retrieve usage alert notifications from Flume API.""" from requests import Session from .constants import API_BASE_URL, API_USAGE_URL, DEFAULT_TIMEOUT # noqa: WPS300 from .utils import configure_logger, flume_response_error # noqa: WPS300 # Configure logging LOGGER = configure_logger(__name__) class FlumeUsageAlertList: """Get Flume Usage Alert list from API.""" def __init__( self, flume_auth, http_session=None, timeout=DEFAULT_TIMEOUT, read="false", ): """ Initialize the data object. Args: flume_auth: Authentication object. http_session: Requests Session() timeout: Requests timeout for throttling. read: state of usage alert list, have they been read, not read. """ self._timeout = timeout self._flume_auth = flume_auth self._read = read if http_session is None: self._http_session = Session() else: self._http_session = http_session self.has_next = None self.next_page = None self.usage_alert_list = self.get_usage_alerts() def get_usage_alerts(self): """Return initial page of usage alerts from devices owned by the user. Returns: Returns JSON list of usage alerts. """ api_url = API_USAGE_URL.format(user_id=self._flume_auth.user_id) query_string = { "limit": "50", "offset": "0", "sort_direction": "ASC", "read": self._read, } return self._get_usage_request(api_url, query_string) def get_next_usage_alerts(self): """Return next page of usage alerts from devices owned by the user. Returns: Returns JSON list of usage alerts. Raises: ValueError: If no next page is available. """ if self.has_next: api_url = f"{API_BASE_URL}{self.next_page}" query_string = {} else: raise ValueError("No next page available.") return self._get_usage_request(api_url, query_string) def _has_next_page(self, response_json): """Return True if the next page exists. Args: response_json (Object): Response from API. Returns: Boolean: Returns true if next page exists, False if not. """ if response_json is None or response_json.get("pagination") is None: return False return ( "next" in response_json["pagination"] and response_json["pagination"]["next"] is not None ) def _get_usage_request(self, api_url, query_string): """Make an API request to get usage alerts from the Flume API. Args: api_url (string): URL for request query_string (object): query string options Returns: object: Reponse in JSON format from API. """ response = self._http_session.request( "GET", api_url, headers=self._flume_auth.authorization_header, params=query_string, timeout=self._timeout, ) LOGGER.debug(f"_get_usage_request Response: {response.text}") # Check for response errors. flume_response_error("Impossible to retrieve usage alert", response) response_json = response.json() if self._has_next_page(response_json): self.next_page = response_json["pagination"]["next"] self.has_next = True LOGGER.debug( f"Next page for Usage results: {self.next_page}", ) else: self.has_next = False self.next_page = None LOGGER.debug("No further pages for Usage results.") return response_json["data"] PyFlume-0.8.7/pyflume/utils.py000066400000000000000000000062161463621261200163120ustar00rootroot00000000000000"""All functions to support Flume App.""" from datetime import datetime, timedelta import json import logging def configure_logger(name): """Configure and return a custom logger for the given name. Args: name (string): Name of logger Returns: object: Logger Handler """ logger = logging.getLogger(name) logger.setLevel(logging.INFO) logger_handler = logging.StreamHandler() formatter = logging.Formatter( "{asctime} - {name} - {levelname} - {message}", style="{", ) logger_handler.setFormatter(formatter) logger.addHandler(logger_handler) return logger def format_time(time): """ Format time based on strftime. Args: time: Expected time as datetime.datetime class Returns: Formatted time. """ return time.replace(second=0).strftime("%Y-%m-%d %H:%M:%S") # noqa: WPS323 def format_start_today(time): """ Format time starting at 00:00:00 provided datetime. Args: time: Expected time as datetime.datetime class Returns: Formatted time. """ return format_time(datetime.combine(time, datetime.min.time())) def format_start_month(time): """ Format time starting at the first of the month for provided datetime. Args: time: Expected time as datetime.datetime class Returns: Formatted time. """ return format_time( datetime.combine( time.replace(day=1), datetime.min.time(), ), ) def format_start_week(time): """ Format time starting at the start of week for provided datetime. Args: time: Expected time as datetime.datetime class Returns: Formatted time. """ return format_time( datetime.combine( time - timedelta(days=time.weekday()), datetime.min.time(), ), ) class FlumeResponseError(Exception): """ Exception raised for errors in the Flume response. Attributes: message -- explanation of the error """ def flume_response_error(message, response): """Define a function to handle response errors from the Flume API. Args: message (string): Message received as error response (string): Response received as error Raises: FlumeResponseError: Exception raised when the status code is not 200. """ # If the response code is 200 (OK), no error has occurred, so return immediately if response.status_code == 200: # noqa: WPS432 return # If the response code is 400 (Bad Request), retrieve the detailed error message if response.status_code == 400: # noqa: WPS432 error_message = json.loads(response.text)["detailed"][0] else: # For other error codes, retrieve the general error message error_message = json.loads(response.text)["message"] # Raise a custom exception with a formatted message containing the error details raise FlumeResponseError( "Message:{0}.\nResponse code returned:{1}.\nError message returned:{2}.".format( message, response.status_code, error_message, ), ) PyFlume-0.8.7/setup.cfg000066400000000000000000000033011463621261200147300ustar00rootroot00000000000000[tool:pytest] testpaths = tests [flake8] exclude = .venv,.git,.tox,docs,venv,bin,lib,deps,build doctests = True # To work with Black max-module-members = 10 max-line-length = 88 # E501: line too long # W503: Line break occurred before a binary operator # E203: Whitespace before ':' # D202: No blank lines allowed after function docstring # W504: line break after binary operator # WPS402: Found `noqa` comments overuse # WPS226: Found string constant over-use # WPS204: Found overused expression # WPS412: Found `__init__.py` module with logic # Q000: Quote doesn't project setting # WPS305: Found `f` string # I001: isort found an import in the wrong position # WPS100: Found wrong module name # WPS300: Found local folder import # WPS235: Found too many imported names from a module # WPS218: Found too many `assert` statements ignore = E501, W503, E203, D202, W504, WPS402, WPS226, WPS204, WPS412, Q000, WPS305, I001, WPS100, WPS300, WPS235, WPS218 [isort] # https://github.com/timothycrosley/isort # https://github.com/timothycrosley/isort/wiki/isort-Settings # splits long import on multiple lines indented by 4 spaces multi_line_output = 3 include_trailing_comma=True force_grid_wrap=0 use_parentheses=True line_length=88 indent = " " # by default isort don't check module indexes not_skip = __init__.py # will group `import x` and `from x import` of the same module. force_sort_within_sections = true sections = FUTURE,STDLIB,INBETWEENS,THIRDPARTY,FIRSTPARTY,LOCALFOLDER default_section = THIRDPARTY known_first_party = homeassistant,tests forced_separate = tests combine_as_imports = true PyFlume-0.8.7/setup.py000066400000000000000000000015271463621261200146310ustar00rootroot00000000000000"""PyFlume setuptools for PyPi.""" import setuptools with open("README.md", "r") as fh: long_description = fh.read() setuptools.setup( name="PyFlume", version="0.8.7", author="ChrisMandich", author_email="Chris@Mandich.net", description="Package to integrate with Flume Sensor", long_description_content_type="text/markdown", long_description=long_description, url="https://github.com/ChrisMandich/PyFlume", packages=setuptools.find_packages(exclude=["tests", "tests.*"]), classifiers=[ "Programming Language :: Python :: 3", "License :: OSI Approved :: MIT License", "Operating System :: OS Independent", ], install_requires=[ "pyjwt", "ratelimit", "requests", 'backports.zoneinfo; python_version<"3.9"', ], ) PyFlume-0.8.7/tests/000077500000000000000000000000001463621261200142545ustar00rootroot00000000000000PyFlume-0.8.7/tests/__init__.py000066400000000000000000000000311463621261200163570ustar00rootroot00000000000000"""PyFlume __init__ .""" PyFlume-0.8.7/tests/constants.py000066400000000000000000000014461463621261200166470ustar00rootroot00000000000000"""Support constants for test_*.""" from datetime import timedelta from types import MappingProxyType CONST_TOKEN_FILE = "token.json" # noqa: S105 CONST_HTTP_METHOD_POST = "post" CONST_USERNAME = "username" # noqa: S105 CONST_PASSWORD = "password" # noqa: S105 CONST_CLIENT_ID = "client_id" # noqa: S105 CONST_CLIENT_SECRET = "client_secret" # noqa: S105 CONST_USER_ID = "user_id" CONST_FLUME_TOKEN = MappingProxyType( { "token_type": "bearer", "expires_in": 604800, "refresh_token": "fdb8fdbecf1d03ce5e6125c067733c0d51de209c", "access_token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyX2lkIjoidXNlcl9pZCIsImV4cCI6Mjk5OTk5OTk5OTcsIngiOiJ5eiJ9.utb2yzcMImBFhDx_mssC_HU0mbfo0D_-VAQOetw5_h0", }, ) CONST_SCAN_INTERVAL = timedelta(minutes=1) # Using datetime PyFlume-0.8.7/tests/fixtures/000077500000000000000000000000001463621261200161255ustar00rootroot00000000000000PyFlume-0.8.7/tests/fixtures/devices.json000066400000000000000000000033761463621261200204530ustar00rootroot00000000000000{ "http_message" : "OK", "code" : 602, "pagination" : null, "message" : "Request OK", "count" : 1, "success" : true, "detailed" : null, "data" : [ { "type" : 2, "user_id" : 1111, "bridge_id" : "6248148189204194444", "description" : null, "registered" : true, "added_datetime" : "2017-03-16T14:30:13.284Z", "id" : "6248148189204194987", "name" : null, "location" : { "state" : "CA", "tz" : "America/Los_Angeles", "user_id" : 1111, "id" : 1, "building_type" : "SINGLE_FAMILY_HOME", "city" : "San Luis Obispo", "installation" : "DONE", "address" : "1 Flume Drive", "usage_profile" : { "irrigation" : "GARDEN_HOSE", "bathrooms" : "3", "score" : 1, "irrigation_max_cycle" : 60, "residents" : "1", "irrigation_freq" : "2_PER_WEEK", "id" : 117 }, "primary_location" : true, "address_2" : null, "country" : "United States", "name" : "Primary Residence", "postal_code" : "93401" }, "oriented" : true, "last_seen" : "2017-04-13T01:31:36.000Z", "user" : { "first_name" : "Flume", "signup_datetime" : "2016-12-01T00:12:19.928Z", "id" : 1111, "email_address" : "support@flumetech.com", "type" : "USER", "phone" : "4444444444", "last_name" : "Tech", "status" : "Active" } } ], "http_code" : 200 } PyFlume-0.8.7/tests/fixtures/leak.json000066400000000000000000000003671463621261200177420ustar00rootroot00000000000000{ "success": true, "code": 602, "message": "Request OK", "http_code": 200, "http_message": "OK", "detailed": null, "data": [ { "active": true } ], "count": 1, "pagination": null }PyFlume-0.8.7/tests/fixtures/notification.json000066400000000000000000000021031463621261200215020ustar00rootroot00000000000000{ "success": true, "code": 602, "message": "Request OK", "http_code": 200, "http_message": "OK", "detailed": null, "data": [ { "id": 111111, "device_id": "6248148189204194987", "user_id": 1111, "type": 1, "message": "Low Flow Leak triggered at Home. Water has been running for 2 hours averaging 0.43 gallons every minute.", "created_datetime": "2020-01-15T16:33:39.000Z", "title": "Potential Leak Detected!", "read": true, "extra": { "query": { "request_id": "SYSTEM_TRIGGERED_USAGE_ALERT", "since_datetime": "2020-01-15 06:33:59", "until_datetime": "2020-01-15 08:33:59", "tz": "America/Los_Angeles", "bucket": "MIN", "raw": false, "group_multiplier": 2, "device_id": [ "6248148189204194987" ] } }, "event_rule": "Low Flow Leak" } ], "count": 1, "pagination":{ "next":"/users/1111/notifications?offset=1&limit=1", "prev":null } }PyFlume-0.8.7/tests/fixtures/notification_next.json000066400000000000000000000021031463621261200225400ustar00rootroot00000000000000{ "success": true, "code": 602, "message": "Request OK", "http_code": 200, "http_message": "OK", "detailed": null, "data": [ { "id": 111111, "device_id": "6248148189204194987", "user_id": 1111, "type": 1, "message": "Low Flow Leak triggered at Home. Water has been running for 2 hours averaging 0.43 gallons every minute.", "created_datetime": "2020-01-15T16:33:39.000Z", "title": "Potential Leak Detected!", "read": true, "extra": { "query": { "request_id": "SYSTEM_TRIGGERED_USAGE_ALERT", "since_datetime": "2020-01-15 06:33:59", "until_datetime": "2020-01-15 08:33:59", "tz": "America/Los_Angeles", "bucket": "MIN", "raw": false, "group_multiplier": 2, "device_id": [ "6248148189204194987" ] } }, "event_rule": "Low Flow Leak" } ], "count": 1, "pagination":{ "next":null, "prev":"/users/1111/notifications?offset=1&limit=1" } }PyFlume-0.8.7/tests/fixtures/notification_nopage.json000066400000000000000000000017671463621261200230520ustar00rootroot00000000000000{ "success": true, "code": 602, "message": "Request OK", "http_code": 200, "http_message": "OK", "detailed": null, "data": [ { "id": 111111, "device_id": "6248148189204194987", "user_id": 1111, "type": 1, "message": "Low Flow Leak triggered at Home. Water has been running for 2 hours averaging 0.43 gallons every minute.", "created_datetime": "2020-01-15T16:33:39.000Z", "title": "Potential Leak Detected!", "read": true, "extra": { "query": { "request_id": "SYSTEM_TRIGGERED_USAGE_ALERT", "since_datetime": "2020-01-15 06:33:59", "until_datetime": "2020-01-15 08:33:59", "tz": "America/Los_Angeles", "bucket": "MIN", "raw": false, "group_multiplier": 2, "device_id": [ "6248148189204194987" ] } }, "event_rule": "Low Flow Leak" } ], "count": 1, "pagination": null }PyFlume-0.8.7/tests/fixtures/query.json000066400000000000000000000015471463621261200201740ustar00rootroot00000000000000{ "success": true, "code": 602, "message": "Request OK", "http_code": 200, "http_message": "OK", "detailed": null, "data": [ { "current_interval": [ { "value": 14.38855184 } ], "today": [ { "value": 56.6763912 } ], "week_to_date": [ { "value": 1406.07065872 } ], "month_to_date": [ { "datetime": "2020-05-01 00:00:00", "value": 56.6763912 } ], "last_60_min": [ { "value": 14.38855184 } ], "last_24_hrs": [ { "value": 258.9557672 } ], "last_30_days": [ { "value": 5433.56753264 } ] } ], "count": 0, "pagination": null }PyFlume-0.8.7/tests/fixtures/token.json000066400000000000000000000010411463621261200201340ustar00rootroot00000000000000{ "http_code" : 200, "code" : 602, "detailed" : null, "message" : "Request OK", "count" : 1, "success" : true, "data" : [ { "token_type" : "bearer", "expires_in" : 604800, "refresh_token" : "fdb8fdbecf1d03ce5e6125c067733c0d51de209c", "access_token" : "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyX2lkIjoidXNlcl9pZCIsImV4cCI6Mjk5OTk5OTk5OTcsIngiOiJ5eiJ9.utb2yzcMImBFhDx_mssC_HU0mbfo0D_-VAQOetw5_h0" } ], "http_message" : "OK", "pagination" : null } PyFlume-0.8.7/tests/fixtures/usage.json000066400000000000000000000643261463621261200201370ustar00rootroot00000000000000{ "success": true, "code": 602, "message": "Request OK", "http_code": 200, "http_message": "OK", "detailed": null, "data": [ { "id": 5243137, "device_id": "6248148189204194987", "triggered_datetime": "2022-06-22T12:41:00.000Z", "flume_leak": false, "query": { "request_id": "SYSTEM_TRIGGERED_USAGE_ALERT", "until_datetime": "2022-06-22 05:42:00", "tz": "America/Los_Angeles", "bucket": "MIN", "since_datetime": "2022-06-22 05:27:00" }, "event_rule_name": "High Flow Alert" }, { "id": 5255122, "device_id": "6248148189204194987", "triggered_datetime": "2022-06-23T11:14:00.000Z", "flume_leak": false, "query": { "request_id": "SYSTEM_TRIGGERED_USAGE_ALERT", "until_datetime": "2022-06-23 04:15:00", "tz": "America/Los_Angeles", "bucket": "MIN", "since_datetime": "2022-06-23 04:00:00" }, "event_rule_name": "High Flow Alert" }, { "id": 5257651, "device_id": "6248148189204194987", "triggered_datetime": "2022-06-23T13:30:00.000Z", "flume_leak": false, "query": { "request_id": "SYSTEM_TRIGGERED_USAGE_ALERT", "until_datetime": "2022-06-23 06:31:00", "tz": "America/Los_Angeles", "bucket": "MIN", "since_datetime": "2022-06-23 06:16:00" }, "event_rule_name": "High Flow Alert" }, { "id": 5270444, "device_id": "6248148189204194987", "triggered_datetime": "2022-06-24T12:41:00.000Z", "flume_leak": false, "query": { "request_id": "SYSTEM_TRIGGERED_USAGE_ALERT", "until_datetime": "2022-06-24 05:42:00", "tz": "America/Los_Angeles", "bucket": "MIN", "since_datetime": "2022-06-24 05:27:00" }, "event_rule_name": "High Flow Alert" }, { "id": 5274373, "device_id": "6248148189204194987", "triggered_datetime": "2022-06-24T18:17:00.000Z", "flume_leak": false, "query": { "request_id": "SYSTEM_TRIGGERED_USAGE_ALERT", "until_datetime": "2022-06-24 11:18:00", "tz": "America/Los_Angeles", "bucket": "MIN", "since_datetime": "2022-06-24 11:03:00" }, "event_rule_name": "High Flow Alert" }, { "id": 5283712, "device_id": "6248148189204194987", "triggered_datetime": "2022-06-25T12:40:00.000Z", "flume_leak": false, "query": { "request_id": "SYSTEM_TRIGGERED_USAGE_ALERT", "until_datetime": "2022-06-25 05:41:00", "tz": "America/Los_Angeles", "bucket": "MIN", "since_datetime": "2022-06-25 05:26:00" }, "event_rule_name": "High Flow Alert" }, { "id": 5296972, "device_id": "6248148189204194987", "triggered_datetime": "2022-06-26T13:09:00.000Z", "flume_leak": false, "query": { "request_id": "SYSTEM_TRIGGERED_USAGE_ALERT", "until_datetime": "2022-06-26 06:10:00", "tz": "America/Los_Angeles", "bucket": "MIN", "since_datetime": "2022-06-26 05:55:00" }, "event_rule_name": "High Flow Alert" }, { "id": 5310367, "device_id": "6248148189204194987", "triggered_datetime": "2022-06-27T12:41:00.000Z", "flume_leak": false, "query": { "request_id": "SYSTEM_TRIGGERED_USAGE_ALERT", "until_datetime": "2022-06-27 05:42:00", "tz": "America/Los_Angeles", "bucket": "MIN", "since_datetime": "2022-06-27 05:27:00" }, "event_rule_name": "High Flow Alert" }, { "id": 5323808, "device_id": "6248148189204194987", "triggered_datetime": "2022-06-28T13:07:00.000Z", "flume_leak": false, "query": { "request_id": "SYSTEM_TRIGGERED_USAGE_ALERT", "until_datetime": "2022-06-28 06:08:00", "tz": "America/Los_Angeles", "bucket": "MIN", "since_datetime": "2022-06-28 05:53:00" }, "event_rule_name": "High Flow Alert" }, { "id": 5351044, "device_id": "6248148189204194987", "triggered_datetime": "2022-06-29T11:13:00.000Z", "flume_leak": false, "query": { "request_id": "SYSTEM_TRIGGERED_USAGE_ALERT", "until_datetime": "2022-06-29 04:14:00", "tz": "America/Los_Angeles", "bucket": "MIN", "since_datetime": "2022-06-29 03:59:00" }, "event_rule_name": "High Flow Alert" }, { "id": 5359491, "device_id": "6248148189204194987", "triggered_datetime": "2022-07-01T11:14:00.000Z", "flume_leak": false, "query": { "request_id": "SYSTEM_TRIGGERED_USAGE_ALERT", "until_datetime": "2022-07-01 04:15:00", "tz": "America/Los_Angeles", "bucket": "MIN", "since_datetime": "2022-07-01 04:00:00" }, "event_rule_name": "High Flow Alert" }, { "id": 5361864, "device_id": "6248148189204194987", "triggered_datetime": "2022-07-01T13:29:00.000Z", "flume_leak": false, "query": { "request_id": "SYSTEM_TRIGGERED_USAGE_ALERT", "until_datetime": "2022-07-01 06:30:00", "tz": "America/Los_Angeles", "bucket": "MIN", "since_datetime": "2022-07-01 06:15:00" }, "event_rule_name": "High Flow Alert" }, { "id": 5373614, "device_id": "6248148189204194987", "triggered_datetime": "2022-07-02T12:43:00.000Z", "flume_leak": false, "query": { "request_id": "SYSTEM_TRIGGERED_USAGE_ALERT", "until_datetime": "2022-07-02 05:44:00", "tz": "America/Los_Angeles", "bucket": "MIN", "since_datetime": "2022-07-02 05:29:00" }, "event_rule_name": "High Flow Alert" }, { "id": 5384498, "device_id": "6248148189204194987", "triggered_datetime": "2022-07-03T11:13:00.000Z", "flume_leak": false, "query": { "request_id": "SYSTEM_TRIGGERED_USAGE_ALERT", "until_datetime": "2022-07-03 04:14:00", "tz": "America/Los_Angeles", "bucket": "MIN", "since_datetime": "2022-07-03 03:59:00" }, "event_rule_name": "High Flow Alert" }, { "id": 5411226, "device_id": "6248148189204194987", "triggered_datetime": "2022-07-05T11:13:00.000Z", "flume_leak": false, "query": { "request_id": "SYSTEM_TRIGGERED_USAGE_ALERT", "until_datetime": "2022-07-05 04:14:00", "tz": "America/Los_Angeles", "bucket": "MIN", "since_datetime": "2022-07-05 03:59:00" }, "event_rule_name": "High Flow Alert" }, { "id": 5413585, "device_id": "6248148189204194987", "triggered_datetime": "2022-07-05T13:24:00.000Z", "flume_leak": false, "query": { "request_id": "SYSTEM_TRIGGERED_USAGE_ALERT", "until_datetime": "2022-07-05 06:25:00", "tz": "America/Los_Angeles", "bucket": "MIN", "since_datetime": "2022-07-05 06:10:00" }, "event_rule_name": "High Flow Alert" }, { "id": 5426430, "device_id": "6248148189204194987", "triggered_datetime": "2022-07-06T12:45:00.000Z", "flume_leak": false, "query": { "request_id": "SYSTEM_TRIGGERED_USAGE_ALERT", "until_datetime": "2022-07-06 05:46:00", "tz": "America/Los_Angeles", "bucket": "MIN", "since_datetime": "2022-07-06 05:31:00" }, "event_rule_name": "High Flow Alert" }, { "id": 5437976, "device_id": "6248148189204194987", "triggered_datetime": "2022-07-07T11:13:00.000Z", "flume_leak": false, "query": { "request_id": "SYSTEM_TRIGGERED_USAGE_ALERT", "until_datetime": "2022-07-07 04:14:00", "tz": "America/Los_Angeles", "bucket": "MIN", "since_datetime": "2022-07-07 03:59:00" }, "event_rule_name": "High Flow Alert" }, { "id": 5440080, "device_id": "6248148189204194987", "triggered_datetime": "2022-07-07T13:13:00.000Z", "flume_leak": false, "query": { "request_id": "SYSTEM_TRIGGERED_USAGE_ALERT", "until_datetime": "2022-07-07 06:14:00", "tz": "America/Los_Angeles", "bucket": "MIN", "since_datetime": "2022-07-07 05:59:00" }, "event_rule_name": "High Flow Alert" }, { "id": 5453334, "device_id": "6248148189204194987", "triggered_datetime": "2022-07-08T12:46:00.000Z", "flume_leak": false, "query": { "request_id": "SYSTEM_TRIGGERED_USAGE_ALERT", "until_datetime": "2022-07-08 05:47:00", "tz": "America/Los_Angeles", "bucket": "MIN", "since_datetime": "2022-07-08 05:32:00" }, "event_rule_name": "High Flow Alert" }, { "id": 5465242, "device_id": "6248148189204194987", "triggered_datetime": "2022-07-09T11:14:00.000Z", "flume_leak": false, "query": { "request_id": "SYSTEM_TRIGGERED_USAGE_ALERT", "until_datetime": "2022-07-09 04:15:00", "tz": "America/Los_Angeles", "bucket": "MIN", "since_datetime": "2022-07-09 04:00:00" }, "event_rule_name": "High Flow Alert" }, { "id": 5467031, "device_id": "6248148189204194987", "triggered_datetime": "2022-07-09T13:14:00.000Z", "flume_leak": false, "query": { "request_id": "SYSTEM_TRIGGERED_USAGE_ALERT", "until_datetime": "2022-07-09 06:15:00", "tz": "America/Los_Angeles", "bucket": "MIN", "since_datetime": "2022-07-09 06:00:00" }, "event_rule_name": "High Flow Alert" }, { "id": 5480078, "device_id": "6248148189204194987", "triggered_datetime": "2022-07-10T13:11:00.000Z", "flume_leak": false, "query": { "request_id": "SYSTEM_TRIGGERED_USAGE_ALERT", "until_datetime": "2022-07-10 06:12:00", "tz": "America/Los_Angeles", "bucket": "MIN", "since_datetime": "2022-07-10 05:57:00" }, "event_rule_name": "High Flow Alert" }, { "id": 5492257, "device_id": "6248148189204194987", "triggered_datetime": "2022-07-11T11:13:00.000Z", "flume_leak": false, "query": { "request_id": "SYSTEM_TRIGGERED_USAGE_ALERT", "until_datetime": "2022-07-11 04:14:00", "tz": "America/Los_Angeles", "bucket": "MIN", "since_datetime": "2022-07-11 03:59:00" }, "event_rule_name": "High Flow Alert" }, { "id": 5494981, "device_id": "6248148189204194987", "triggered_datetime": "2022-07-11T13:22:00.000Z", "flume_leak": false, "query": { "request_id": "SYSTEM_TRIGGERED_USAGE_ALERT", "until_datetime": "2022-07-11 06:23:00", "tz": "America/Los_Angeles", "bucket": "MIN", "since_datetime": "2022-07-11 06:08:00" }, "event_rule_name": "High Flow Alert" }, { "id": 5521358, "device_id": "6248148189204194987", "triggered_datetime": "2022-07-13T11:13:00.000Z", "flume_leak": false, "query": { "request_id": "SYSTEM_TRIGGERED_USAGE_ALERT", "until_datetime": "2022-07-13 04:14:00", "tz": "America/Los_Angeles", "bucket": "MIN", "since_datetime": "2022-07-13 03:59:00" }, "event_rule_name": "High Flow Alert" }, { "id": 5537687, "device_id": "6248148189204194987", "triggered_datetime": "2022-07-14T12:49:00.000Z", "flume_leak": false, "query": { "request_id": "SYSTEM_TRIGGERED_USAGE_ALERT", "until_datetime": "2022-07-14 05:50:00", "tz": "America/Los_Angeles", "bucket": "MIN", "since_datetime": "2022-07-14 05:35:00" }, "event_rule_name": "High Flow Alert" }, { "id": 5549658, "device_id": "6248148189204194987", "triggered_datetime": "2022-07-15T11:13:00.000Z", "flume_leak": false, "query": { "request_id": "SYSTEM_TRIGGERED_USAGE_ALERT", "until_datetime": "2022-07-15 04:14:00", "tz": "America/Los_Angeles", "bucket": "MIN", "since_datetime": "2022-07-15 03:59:00" }, "event_rule_name": "High Flow Alert" }, { "id": 5551885, "device_id": "6248148189204194987", "triggered_datetime": "2022-07-15T13:13:00.000Z", "flume_leak": false, "query": { "request_id": "SYSTEM_TRIGGERED_USAGE_ALERT", "until_datetime": "2022-07-15 06:14:00", "tz": "America/Los_Angeles", "bucket": "MIN", "since_datetime": "2022-07-15 05:59:00" }, "event_rule_name": "High Flow Alert" }, { "id": 5564244, "device_id": "6248148189204194987", "triggered_datetime": "2022-07-16T12:50:00.000Z", "flume_leak": false, "query": { "request_id": "SYSTEM_TRIGGERED_USAGE_ALERT", "until_datetime": "2022-07-16 05:51:00", "tz": "America/Los_Angeles", "bucket": "MIN", "since_datetime": "2022-07-16 05:36:00" }, "event_rule_name": "High Flow Alert" }, { "id": 5575597, "device_id": "6248148189204194987", "triggered_datetime": "2022-07-17T11:12:00.000Z", "flume_leak": false, "query": { "request_id": "SYSTEM_TRIGGERED_USAGE_ALERT", "until_datetime": "2022-07-17 04:13:00", "tz": "America/Los_Angeles", "bucket": "MIN", "since_datetime": "2022-07-17 03:58:00" }, "event_rule_name": "High Flow Alert" }, { "id": 5591234, "device_id": "6248148189204194987", "triggered_datetime": "2022-07-18T12:51:00.000Z", "flume_leak": false, "query": { "request_id": "SYSTEM_TRIGGERED_USAGE_ALERT", "until_datetime": "2022-07-18 05:52:00", "tz": "America/Los_Angeles", "bucket": "MIN", "since_datetime": "2022-07-18 05:37:00" }, "event_rule_name": "High Flow Alert" }, { "id": 5603583, "device_id": "6248148189204194987", "triggered_datetime": "2022-07-19T11:13:00.000Z", "flume_leak": false, "query": { "request_id": "SYSTEM_TRIGGERED_USAGE_ALERT", "until_datetime": "2022-07-19 04:14:00", "tz": "America/Los_Angeles", "bucket": "MIN", "since_datetime": "2022-07-19 03:59:00" }, "event_rule_name": "High Flow Alert" }, { "id": 5606381, "device_id": "6248148189204194987", "triggered_datetime": "2022-07-19T13:29:00.000Z", "flume_leak": false, "query": { "request_id": "SYSTEM_TRIGGERED_USAGE_ALERT", "until_datetime": "2022-07-19 06:30:00", "tz": "America/Los_Angeles", "bucket": "MIN", "since_datetime": "2022-07-19 06:15:00" }, "event_rule_name": "High Flow Alert" }, { "id": 5620785, "device_id": "6248148189204194987", "triggered_datetime": "2022-07-20T12:52:00.000Z", "flume_leak": false, "query": { "request_id": "SYSTEM_TRIGGERED_USAGE_ALERT", "until_datetime": "2022-07-20 05:53:00", "tz": "America/Los_Angeles", "bucket": "MIN", "since_datetime": "2022-07-20 05:38:00" }, "event_rule_name": "High Flow Alert" }, { "id": 5634037, "device_id": "6248148189204194987", "triggered_datetime": "2022-07-21T11:13:00.000Z", "flume_leak": false, "query": { "request_id": "SYSTEM_TRIGGERED_USAGE_ALERT", "until_datetime": "2022-07-21 04:14:00", "tz": "America/Los_Angeles", "bucket": "MIN", "since_datetime": "2022-07-21 03:59:00" }, "event_rule_name": "High Flow Alert" }, { "id": 5636547, "device_id": "6248148189204194987", "triggered_datetime": "2022-07-21T13:20:00.000Z", "flume_leak": false, "query": { "request_id": "SYSTEM_TRIGGERED_USAGE_ALERT", "until_datetime": "2022-07-21 06:21:00", "tz": "America/Los_Angeles", "bucket": "MIN", "since_datetime": "2022-07-21 06:06:00" }, "event_rule_name": "High Flow Alert" }, { "id": 5651243, "device_id": "6248148189204194987", "triggered_datetime": "2022-07-22T12:54:00.000Z", "flume_leak": false, "query": { "request_id": "SYSTEM_TRIGGERED_USAGE_ALERT", "until_datetime": "2022-07-22 05:55:00", "tz": "America/Los_Angeles", "bucket": "MIN", "since_datetime": "2022-07-22 05:40:00" }, "event_rule_name": "High Flow Alert" }, { "id": 5663989, "device_id": "6248148189204194987", "triggered_datetime": "2022-07-23T11:12:00.000Z", "flume_leak": false, "query": { "request_id": "SYSTEM_TRIGGERED_USAGE_ALERT", "until_datetime": "2022-07-23 04:13:00", "tz": "America/Los_Angeles", "bucket": "MIN", "since_datetime": "2022-07-23 03:58:00" }, "event_rule_name": "High Flow Alert" }, { "id": 5679244, "device_id": "6248148189204194987", "triggered_datetime": "2022-07-24T12:54:00.000Z", "flume_leak": false, "query": { "request_id": "SYSTEM_TRIGGERED_USAGE_ALERT", "until_datetime": "2022-07-24 05:55:00", "tz": "America/Los_Angeles", "bucket": "MIN", "since_datetime": "2022-07-24 05:40:00" }, "event_rule_name": "High Flow Alert" }, { "id": 5691434, "device_id": "6248148189204194987", "triggered_datetime": "2022-07-25T11:13:00.000Z", "flume_leak": false, "query": { "request_id": "SYSTEM_TRIGGERED_USAGE_ALERT", "until_datetime": "2022-07-25 04:14:00", "tz": "America/Los_Angeles", "bucket": "MIN", "since_datetime": "2022-07-25 03:59:00" }, "event_rule_name": "High Flow Alert" }, { "id": 5720925, "device_id": "6248148189204194987", "triggered_datetime": "2022-07-27T11:12:00.000Z", "flume_leak": false, "query": { "request_id": "SYSTEM_TRIGGERED_USAGE_ALERT", "until_datetime": "2022-07-27 04:13:00", "tz": "America/Los_Angeles", "bucket": "MIN", "since_datetime": "2022-07-27 03:58:00" }, "event_rule_name": "High Flow Alert" }, { "id": 5723700, "device_id": "6248148189204194987", "triggered_datetime": "2022-07-27T13:27:00.000Z", "flume_leak": false, "query": { "request_id": "SYSTEM_TRIGGERED_USAGE_ALERT", "until_datetime": "2022-07-27 06:28:00", "tz": "America/Los_Angeles", "bucket": "MIN", "since_datetime": "2022-07-27 06:13:00" }, "event_rule_name": "High Flow Alert" }, { "id": 5737526, "device_id": "6248148189204194987", "triggered_datetime": "2022-07-28T12:58:00.000Z", "flume_leak": false, "query": { "request_id": "SYSTEM_TRIGGERED_USAGE_ALERT", "until_datetime": "2022-07-28 05:59:00", "tz": "America/Los_Angeles", "bucket": "MIN", "since_datetime": "2022-07-28 05:44:00" }, "event_rule_name": "High Flow Alert" }, { "id": 5749779, "device_id": "6248148189204194987", "triggered_datetime": "2022-07-29T11:12:00.000Z", "flume_leak": false, "query": { "request_id": "SYSTEM_TRIGGERED_USAGE_ALERT", "until_datetime": "2022-07-29 04:13:00", "tz": "America/Los_Angeles", "bucket": "MIN", "since_datetime": "2022-07-29 03:58:00" }, "event_rule_name": "High Flow Alert" }, { "id": 5752512, "device_id": "6248148189204194987", "triggered_datetime": "2022-07-29T13:27:00.000Z", "flume_leak": false, "query": { "request_id": "SYSTEM_TRIGGERED_USAGE_ALERT", "until_datetime": "2022-07-29 06:28:00", "tz": "America/Los_Angeles", "bucket": "MIN", "since_datetime": "2022-07-29 06:13:00" }, "event_rule_name": "High Flow Alert" }, { "id": 5765668, "device_id": "6248148189204194987", "triggered_datetime": "2022-07-30T12:59:00.000Z", "flume_leak": false, "query": { "request_id": "SYSTEM_TRIGGERED_USAGE_ALERT", "until_datetime": "2022-07-30 06:00:00", "tz": "America/Los_Angeles", "bucket": "MIN", "since_datetime": "2022-07-30 05:45:00" }, "event_rule_name": "High Flow Alert" }, { "id": 5777345, "device_id": "6248148189204194987", "triggered_datetime": "2022-07-31T11:12:00.000Z", "flume_leak": false, "query": { "request_id": "SYSTEM_TRIGGERED_USAGE_ALERT", "until_datetime": "2022-07-31 04:13:00", "tz": "America/Los_Angeles", "bucket": "MIN", "since_datetime": "2022-07-31 03:58:00" }, "event_rule_name": "High Flow Alert" }, { "id": 5779249, "device_id": "6248148189204194987", "triggered_datetime": "2022-07-31T13:18:00.000Z", "flume_leak": false, "query": { "request_id": "SYSTEM_TRIGGERED_USAGE_ALERT", "until_datetime": "2022-07-31 06:19:00", "tz": "America/Los_Angeles", "bucket": "MIN", "since_datetime": "2022-07-31 06:04:00" }, "event_rule_name": "High Flow Alert" }, { "id": 5793493, "device_id": "6248148189204194987", "triggered_datetime": "2022-08-01T13:00:00.000Z", "flume_leak": false, "query": { "request_id": "SYSTEM_TRIGGERED_USAGE_ALERT", "until_datetime": "2022-08-01 06:01:00", "tz": "America/Los_Angeles", "bucket": "MIN", "since_datetime": "2022-08-01 05:46:00" }, "event_rule_name": "High Flow Alert" } ], "count": 122, "pagination": { "next": "/users/1111/usage-alerts?offset=50&limit=50", "prev": null } }PyFlume-0.8.7/tests/fixtures/usage_next.json000066400000000000000000000643261463621261200211750ustar00rootroot00000000000000{ "success": true, "code": 602, "message": "Request OK", "http_code": 200, "http_message": "OK", "detailed": null, "data": [ { "id": 5243137, "device_id": "6248148189204194987", "triggered_datetime": "2022-06-22T12:41:00.000Z", "flume_leak": false, "query": { "request_id": "SYSTEM_TRIGGERED_USAGE_ALERT", "until_datetime": "2022-06-22 05:42:00", "tz": "America/Los_Angeles", "bucket": "MIN", "since_datetime": "2022-06-22 05:27:00" }, "event_rule_name": "High Flow Alert" }, { "id": 5255122, "device_id": "6248148189204194987", "triggered_datetime": "2022-06-23T11:14:00.000Z", "flume_leak": false, "query": { "request_id": "SYSTEM_TRIGGERED_USAGE_ALERT", "until_datetime": "2022-06-23 04:15:00", "tz": "America/Los_Angeles", "bucket": "MIN", "since_datetime": "2022-06-23 04:00:00" }, "event_rule_name": "High Flow Alert" }, { "id": 5257651, "device_id": "6248148189204194987", "triggered_datetime": "2022-06-23T13:30:00.000Z", "flume_leak": false, "query": { "request_id": "SYSTEM_TRIGGERED_USAGE_ALERT", "until_datetime": "2022-06-23 06:31:00", "tz": "America/Los_Angeles", "bucket": "MIN", "since_datetime": "2022-06-23 06:16:00" }, "event_rule_name": "High Flow Alert" }, { "id": 5270444, "device_id": "6248148189204194987", "triggered_datetime": "2022-06-24T12:41:00.000Z", "flume_leak": false, "query": { "request_id": "SYSTEM_TRIGGERED_USAGE_ALERT", "until_datetime": "2022-06-24 05:42:00", "tz": "America/Los_Angeles", "bucket": "MIN", "since_datetime": "2022-06-24 05:27:00" }, "event_rule_name": "High Flow Alert" }, { "id": 5274373, "device_id": "6248148189204194987", "triggered_datetime": "2022-06-24T18:17:00.000Z", "flume_leak": false, "query": { "request_id": "SYSTEM_TRIGGERED_USAGE_ALERT", "until_datetime": "2022-06-24 11:18:00", "tz": "America/Los_Angeles", "bucket": "MIN", "since_datetime": "2022-06-24 11:03:00" }, "event_rule_name": "High Flow Alert" }, { "id": 5283712, "device_id": "6248148189204194987", "triggered_datetime": "2022-06-25T12:40:00.000Z", "flume_leak": false, "query": { "request_id": "SYSTEM_TRIGGERED_USAGE_ALERT", "until_datetime": "2022-06-25 05:41:00", "tz": "America/Los_Angeles", "bucket": "MIN", "since_datetime": "2022-06-25 05:26:00" }, "event_rule_name": "High Flow Alert" }, { "id": 5296972, "device_id": "6248148189204194987", "triggered_datetime": "2022-06-26T13:09:00.000Z", "flume_leak": false, "query": { "request_id": "SYSTEM_TRIGGERED_USAGE_ALERT", "until_datetime": "2022-06-26 06:10:00", "tz": "America/Los_Angeles", "bucket": "MIN", "since_datetime": "2022-06-26 05:55:00" }, "event_rule_name": "High Flow Alert" }, { "id": 5310367, "device_id": "6248148189204194987", "triggered_datetime": "2022-06-27T12:41:00.000Z", "flume_leak": false, "query": { "request_id": "SYSTEM_TRIGGERED_USAGE_ALERT", "until_datetime": "2022-06-27 05:42:00", "tz": "America/Los_Angeles", "bucket": "MIN", "since_datetime": "2022-06-27 05:27:00" }, "event_rule_name": "High Flow Alert" }, { "id": 5323808, "device_id": "6248148189204194987", "triggered_datetime": "2022-06-28T13:07:00.000Z", "flume_leak": false, "query": { "request_id": "SYSTEM_TRIGGERED_USAGE_ALERT", "until_datetime": "2022-06-28 06:08:00", "tz": "America/Los_Angeles", "bucket": "MIN", "since_datetime": "2022-06-28 05:53:00" }, "event_rule_name": "High Flow Alert" }, { "id": 5351044, "device_id": "6248148189204194987", "triggered_datetime": "2022-06-29T11:13:00.000Z", "flume_leak": false, "query": { "request_id": "SYSTEM_TRIGGERED_USAGE_ALERT", "until_datetime": "2022-06-29 04:14:00", "tz": "America/Los_Angeles", "bucket": "MIN", "since_datetime": "2022-06-29 03:59:00" }, "event_rule_name": "High Flow Alert" }, { "id": 5359491, "device_id": "6248148189204194987", "triggered_datetime": "2022-07-01T11:14:00.000Z", "flume_leak": false, "query": { "request_id": "SYSTEM_TRIGGERED_USAGE_ALERT", "until_datetime": "2022-07-01 04:15:00", "tz": "America/Los_Angeles", "bucket": "MIN", "since_datetime": "2022-07-01 04:00:00" }, "event_rule_name": "High Flow Alert" }, { "id": 5361864, "device_id": "6248148189204194987", "triggered_datetime": "2022-07-01T13:29:00.000Z", "flume_leak": false, "query": { "request_id": "SYSTEM_TRIGGERED_USAGE_ALERT", "until_datetime": "2022-07-01 06:30:00", "tz": "America/Los_Angeles", "bucket": "MIN", "since_datetime": "2022-07-01 06:15:00" }, "event_rule_name": "High Flow Alert" }, { "id": 5373614, "device_id": "6248148189204194987", "triggered_datetime": "2022-07-02T12:43:00.000Z", "flume_leak": false, "query": { "request_id": "SYSTEM_TRIGGERED_USAGE_ALERT", "until_datetime": "2022-07-02 05:44:00", "tz": "America/Los_Angeles", "bucket": "MIN", "since_datetime": "2022-07-02 05:29:00" }, "event_rule_name": "High Flow Alert" }, { "id": 5384498, "device_id": "6248148189204194987", "triggered_datetime": "2022-07-03T11:13:00.000Z", "flume_leak": false, "query": { "request_id": "SYSTEM_TRIGGERED_USAGE_ALERT", "until_datetime": "2022-07-03 04:14:00", "tz": "America/Los_Angeles", "bucket": "MIN", "since_datetime": "2022-07-03 03:59:00" }, "event_rule_name": "High Flow Alert" }, { "id": 5411226, "device_id": "6248148189204194987", "triggered_datetime": "2022-07-05T11:13:00.000Z", "flume_leak": false, "query": { "request_id": "SYSTEM_TRIGGERED_USAGE_ALERT", "until_datetime": "2022-07-05 04:14:00", "tz": "America/Los_Angeles", "bucket": "MIN", "since_datetime": "2022-07-05 03:59:00" }, "event_rule_name": "High Flow Alert" }, { "id": 5413585, "device_id": "6248148189204194987", "triggered_datetime": "2022-07-05T13:24:00.000Z", "flume_leak": false, "query": { "request_id": "SYSTEM_TRIGGERED_USAGE_ALERT", "until_datetime": "2022-07-05 06:25:00", "tz": "America/Los_Angeles", "bucket": "MIN", "since_datetime": "2022-07-05 06:10:00" }, "event_rule_name": "High Flow Alert" }, { "id": 5426430, "device_id": "6248148189204194987", "triggered_datetime": "2022-07-06T12:45:00.000Z", "flume_leak": false, "query": { "request_id": "SYSTEM_TRIGGERED_USAGE_ALERT", "until_datetime": "2022-07-06 05:46:00", "tz": "America/Los_Angeles", "bucket": "MIN", "since_datetime": "2022-07-06 05:31:00" }, "event_rule_name": "High Flow Alert" }, { "id": 5437976, "device_id": "6248148189204194987", "triggered_datetime": "2022-07-07T11:13:00.000Z", "flume_leak": false, "query": { "request_id": "SYSTEM_TRIGGERED_USAGE_ALERT", "until_datetime": "2022-07-07 04:14:00", "tz": "America/Los_Angeles", "bucket": "MIN", "since_datetime": "2022-07-07 03:59:00" }, "event_rule_name": "High Flow Alert" }, { "id": 5440080, "device_id": "6248148189204194987", "triggered_datetime": "2022-07-07T13:13:00.000Z", "flume_leak": false, "query": { "request_id": "SYSTEM_TRIGGERED_USAGE_ALERT", "until_datetime": "2022-07-07 06:14:00", "tz": "America/Los_Angeles", "bucket": "MIN", "since_datetime": "2022-07-07 05:59:00" }, "event_rule_name": "High Flow Alert" }, { "id": 5453334, "device_id": "6248148189204194987", "triggered_datetime": "2022-07-08T12:46:00.000Z", "flume_leak": false, "query": { "request_id": "SYSTEM_TRIGGERED_USAGE_ALERT", "until_datetime": "2022-07-08 05:47:00", "tz": "America/Los_Angeles", "bucket": "MIN", "since_datetime": "2022-07-08 05:32:00" }, "event_rule_name": "High Flow Alert" }, { "id": 5465242, "device_id": "6248148189204194987", "triggered_datetime": "2022-07-09T11:14:00.000Z", "flume_leak": false, "query": { "request_id": "SYSTEM_TRIGGERED_USAGE_ALERT", "until_datetime": "2022-07-09 04:15:00", "tz": "America/Los_Angeles", "bucket": "MIN", "since_datetime": "2022-07-09 04:00:00" }, "event_rule_name": "High Flow Alert" }, { "id": 5467031, "device_id": "6248148189204194987", "triggered_datetime": "2022-07-09T13:14:00.000Z", "flume_leak": false, "query": { "request_id": "SYSTEM_TRIGGERED_USAGE_ALERT", "until_datetime": "2022-07-09 06:15:00", "tz": "America/Los_Angeles", "bucket": "MIN", "since_datetime": "2022-07-09 06:00:00" }, "event_rule_name": "High Flow Alert" }, { "id": 5480078, "device_id": "6248148189204194987", "triggered_datetime": "2022-07-10T13:11:00.000Z", "flume_leak": false, "query": { "request_id": "SYSTEM_TRIGGERED_USAGE_ALERT", "until_datetime": "2022-07-10 06:12:00", "tz": "America/Los_Angeles", "bucket": "MIN", "since_datetime": "2022-07-10 05:57:00" }, "event_rule_name": "High Flow Alert" }, { "id": 5492257, "device_id": "6248148189204194987", "triggered_datetime": "2022-07-11T11:13:00.000Z", "flume_leak": false, "query": { "request_id": "SYSTEM_TRIGGERED_USAGE_ALERT", "until_datetime": "2022-07-11 04:14:00", "tz": "America/Los_Angeles", "bucket": "MIN", "since_datetime": "2022-07-11 03:59:00" }, "event_rule_name": "High Flow Alert" }, { "id": 5494981, "device_id": "6248148189204194987", "triggered_datetime": "2022-07-11T13:22:00.000Z", "flume_leak": false, "query": { "request_id": "SYSTEM_TRIGGERED_USAGE_ALERT", "until_datetime": "2022-07-11 06:23:00", "tz": "America/Los_Angeles", "bucket": "MIN", "since_datetime": "2022-07-11 06:08:00" }, "event_rule_name": "High Flow Alert" }, { "id": 5521358, "device_id": "6248148189204194987", "triggered_datetime": "2022-07-13T11:13:00.000Z", "flume_leak": false, "query": { "request_id": "SYSTEM_TRIGGERED_USAGE_ALERT", "until_datetime": "2022-07-13 04:14:00", "tz": "America/Los_Angeles", "bucket": "MIN", "since_datetime": "2022-07-13 03:59:00" }, "event_rule_name": "High Flow Alert" }, { "id": 5537687, "device_id": "6248148189204194987", "triggered_datetime": "2022-07-14T12:49:00.000Z", "flume_leak": false, "query": { "request_id": "SYSTEM_TRIGGERED_USAGE_ALERT", "until_datetime": "2022-07-14 05:50:00", "tz": "America/Los_Angeles", "bucket": "MIN", "since_datetime": "2022-07-14 05:35:00" }, "event_rule_name": "High Flow Alert" }, { "id": 5549658, "device_id": "6248148189204194987", "triggered_datetime": "2022-07-15T11:13:00.000Z", "flume_leak": false, "query": { "request_id": "SYSTEM_TRIGGERED_USAGE_ALERT", "until_datetime": "2022-07-15 04:14:00", "tz": "America/Los_Angeles", "bucket": "MIN", "since_datetime": "2022-07-15 03:59:00" }, "event_rule_name": "High Flow Alert" }, { "id": 5551885, "device_id": "6248148189204194987", "triggered_datetime": "2022-07-15T13:13:00.000Z", "flume_leak": false, "query": { "request_id": "SYSTEM_TRIGGERED_USAGE_ALERT", "until_datetime": "2022-07-15 06:14:00", "tz": "America/Los_Angeles", "bucket": "MIN", "since_datetime": "2022-07-15 05:59:00" }, "event_rule_name": "High Flow Alert" }, { "id": 5564244, "device_id": "6248148189204194987", "triggered_datetime": "2022-07-16T12:50:00.000Z", "flume_leak": false, "query": { "request_id": "SYSTEM_TRIGGERED_USAGE_ALERT", "until_datetime": "2022-07-16 05:51:00", "tz": "America/Los_Angeles", "bucket": "MIN", "since_datetime": "2022-07-16 05:36:00" }, "event_rule_name": "High Flow Alert" }, { "id": 5575597, "device_id": "6248148189204194987", "triggered_datetime": "2022-07-17T11:12:00.000Z", "flume_leak": false, "query": { "request_id": "SYSTEM_TRIGGERED_USAGE_ALERT", "until_datetime": "2022-07-17 04:13:00", "tz": "America/Los_Angeles", "bucket": "MIN", "since_datetime": "2022-07-17 03:58:00" }, "event_rule_name": "High Flow Alert" }, { "id": 5591234, "device_id": "6248148189204194987", "triggered_datetime": "2022-07-18T12:51:00.000Z", "flume_leak": false, "query": { "request_id": "SYSTEM_TRIGGERED_USAGE_ALERT", "until_datetime": "2022-07-18 05:52:00", "tz": "America/Los_Angeles", "bucket": "MIN", "since_datetime": "2022-07-18 05:37:00" }, "event_rule_name": "High Flow Alert" }, { "id": 5603583, "device_id": "6248148189204194987", "triggered_datetime": "2022-07-19T11:13:00.000Z", "flume_leak": false, "query": { "request_id": "SYSTEM_TRIGGERED_USAGE_ALERT", "until_datetime": "2022-07-19 04:14:00", "tz": "America/Los_Angeles", "bucket": "MIN", "since_datetime": "2022-07-19 03:59:00" }, "event_rule_name": "High Flow Alert" }, { "id": 5606381, "device_id": "6248148189204194987", "triggered_datetime": "2022-07-19T13:29:00.000Z", "flume_leak": false, "query": { "request_id": "SYSTEM_TRIGGERED_USAGE_ALERT", "until_datetime": "2022-07-19 06:30:00", "tz": "America/Los_Angeles", "bucket": "MIN", "since_datetime": "2022-07-19 06:15:00" }, "event_rule_name": "High Flow Alert" }, { "id": 5620785, "device_id": "6248148189204194987", "triggered_datetime": "2022-07-20T12:52:00.000Z", "flume_leak": false, "query": { "request_id": "SYSTEM_TRIGGERED_USAGE_ALERT", "until_datetime": "2022-07-20 05:53:00", "tz": "America/Los_Angeles", "bucket": "MIN", "since_datetime": "2022-07-20 05:38:00" }, "event_rule_name": "High Flow Alert" }, { "id": 5634037, "device_id": "6248148189204194987", "triggered_datetime": "2022-07-21T11:13:00.000Z", "flume_leak": false, "query": { "request_id": "SYSTEM_TRIGGERED_USAGE_ALERT", "until_datetime": "2022-07-21 04:14:00", "tz": "America/Los_Angeles", "bucket": "MIN", "since_datetime": "2022-07-21 03:59:00" }, "event_rule_name": "High Flow Alert" }, { "id": 5636547, "device_id": "6248148189204194987", "triggered_datetime": "2022-07-21T13:20:00.000Z", "flume_leak": false, "query": { "request_id": "SYSTEM_TRIGGERED_USAGE_ALERT", "until_datetime": "2022-07-21 06:21:00", "tz": "America/Los_Angeles", "bucket": "MIN", "since_datetime": "2022-07-21 06:06:00" }, "event_rule_name": "High Flow Alert" }, { "id": 5651243, "device_id": "6248148189204194987", "triggered_datetime": "2022-07-22T12:54:00.000Z", "flume_leak": false, "query": { "request_id": "SYSTEM_TRIGGERED_USAGE_ALERT", "until_datetime": "2022-07-22 05:55:00", "tz": "America/Los_Angeles", "bucket": "MIN", "since_datetime": "2022-07-22 05:40:00" }, "event_rule_name": "High Flow Alert" }, { "id": 5663989, "device_id": "6248148189204194987", "triggered_datetime": "2022-07-23T11:12:00.000Z", "flume_leak": false, "query": { "request_id": "SYSTEM_TRIGGERED_USAGE_ALERT", "until_datetime": "2022-07-23 04:13:00", "tz": "America/Los_Angeles", "bucket": "MIN", "since_datetime": "2022-07-23 03:58:00" }, "event_rule_name": "High Flow Alert" }, { "id": 5679244, "device_id": "6248148189204194987", "triggered_datetime": "2022-07-24T12:54:00.000Z", "flume_leak": false, "query": { "request_id": "SYSTEM_TRIGGERED_USAGE_ALERT", "until_datetime": "2022-07-24 05:55:00", "tz": "America/Los_Angeles", "bucket": "MIN", "since_datetime": "2022-07-24 05:40:00" }, "event_rule_name": "High Flow Alert" }, { "id": 5691434, "device_id": "6248148189204194987", "triggered_datetime": "2022-07-25T11:13:00.000Z", "flume_leak": false, "query": { "request_id": "SYSTEM_TRIGGERED_USAGE_ALERT", "until_datetime": "2022-07-25 04:14:00", "tz": "America/Los_Angeles", "bucket": "MIN", "since_datetime": "2022-07-25 03:59:00" }, "event_rule_name": "High Flow Alert" }, { "id": 5720925, "device_id": "6248148189204194987", "triggered_datetime": "2022-07-27T11:12:00.000Z", "flume_leak": false, "query": { "request_id": "SYSTEM_TRIGGERED_USAGE_ALERT", "until_datetime": "2022-07-27 04:13:00", "tz": "America/Los_Angeles", "bucket": "MIN", "since_datetime": "2022-07-27 03:58:00" }, "event_rule_name": "High Flow Alert" }, { "id": 5723700, "device_id": "6248148189204194987", "triggered_datetime": "2022-07-27T13:27:00.000Z", "flume_leak": false, "query": { "request_id": "SYSTEM_TRIGGERED_USAGE_ALERT", "until_datetime": "2022-07-27 06:28:00", "tz": "America/Los_Angeles", "bucket": "MIN", "since_datetime": "2022-07-27 06:13:00" }, "event_rule_name": "High Flow Alert" }, { "id": 5737526, "device_id": "6248148189204194987", "triggered_datetime": "2022-07-28T12:58:00.000Z", "flume_leak": false, "query": { "request_id": "SYSTEM_TRIGGERED_USAGE_ALERT", "until_datetime": "2022-07-28 05:59:00", "tz": "America/Los_Angeles", "bucket": "MIN", "since_datetime": "2022-07-28 05:44:00" }, "event_rule_name": "High Flow Alert" }, { "id": 5749779, "device_id": "6248148189204194987", "triggered_datetime": "2022-07-29T11:12:00.000Z", "flume_leak": false, "query": { "request_id": "SYSTEM_TRIGGERED_USAGE_ALERT", "until_datetime": "2022-07-29 04:13:00", "tz": "America/Los_Angeles", "bucket": "MIN", "since_datetime": "2022-07-29 03:58:00" }, "event_rule_name": "High Flow Alert" }, { "id": 5752512, "device_id": "6248148189204194987", "triggered_datetime": "2022-07-29T13:27:00.000Z", "flume_leak": false, "query": { "request_id": "SYSTEM_TRIGGERED_USAGE_ALERT", "until_datetime": "2022-07-29 06:28:00", "tz": "America/Los_Angeles", "bucket": "MIN", "since_datetime": "2022-07-29 06:13:00" }, "event_rule_name": "High Flow Alert" }, { "id": 5765668, "device_id": "6248148189204194987", "triggered_datetime": "2022-07-30T12:59:00.000Z", "flume_leak": false, "query": { "request_id": "SYSTEM_TRIGGERED_USAGE_ALERT", "until_datetime": "2022-07-30 06:00:00", "tz": "America/Los_Angeles", "bucket": "MIN", "since_datetime": "2022-07-30 05:45:00" }, "event_rule_name": "High Flow Alert" }, { "id": 5777345, "device_id": "6248148189204194987", "triggered_datetime": "2022-07-31T11:12:00.000Z", "flume_leak": false, "query": { "request_id": "SYSTEM_TRIGGERED_USAGE_ALERT", "until_datetime": "2022-07-31 04:13:00", "tz": "America/Los_Angeles", "bucket": "MIN", "since_datetime": "2022-07-31 03:58:00" }, "event_rule_name": "High Flow Alert" }, { "id": 5779249, "device_id": "6248148189204194987", "triggered_datetime": "2022-07-31T13:18:00.000Z", "flume_leak": false, "query": { "request_id": "SYSTEM_TRIGGERED_USAGE_ALERT", "until_datetime": "2022-07-31 06:19:00", "tz": "America/Los_Angeles", "bucket": "MIN", "since_datetime": "2022-07-31 06:04:00" }, "event_rule_name": "High Flow Alert" }, { "id": 5793493, "device_id": "6248148189204194987", "triggered_datetime": "2022-08-01T13:00:00.000Z", "flume_leak": false, "query": { "request_id": "SYSTEM_TRIGGERED_USAGE_ALERT", "until_datetime": "2022-08-01 06:01:00", "tz": "America/Los_Angeles", "bucket": "MIN", "since_datetime": "2022-08-01 05:46:00" }, "event_rule_name": "High Flow Alert" } ], "count": 122, "pagination": { "next": null, "prev": "/users/1111/usage-alerts?offset=50&limit=50" } }PyFlume-0.8.7/tests/fixtures/usage_nopage.json000066400000000000000000000641771463621261200214740ustar00rootroot00000000000000{ "success": true, "code": 602, "message": "Request OK", "http_code": 200, "http_message": "OK", "detailed": null, "data": [ { "id": 5243137, "device_id": "6248148189204194987", "triggered_datetime": "2022-06-22T12:41:00.000Z", "flume_leak": false, "query": { "request_id": "SYSTEM_TRIGGERED_USAGE_ALERT", "until_datetime": "2022-06-22 05:42:00", "tz": "America/Los_Angeles", "bucket": "MIN", "since_datetime": "2022-06-22 05:27:00" }, "event_rule_name": "High Flow Alert" }, { "id": 5255122, "device_id": "6248148189204194987", "triggered_datetime": "2022-06-23T11:14:00.000Z", "flume_leak": false, "query": { "request_id": "SYSTEM_TRIGGERED_USAGE_ALERT", "until_datetime": "2022-06-23 04:15:00", "tz": "America/Los_Angeles", "bucket": "MIN", "since_datetime": "2022-06-23 04:00:00" }, "event_rule_name": "High Flow Alert" }, { "id": 5257651, "device_id": "6248148189204194987", "triggered_datetime": "2022-06-23T13:30:00.000Z", "flume_leak": false, "query": { "request_id": "SYSTEM_TRIGGERED_USAGE_ALERT", "until_datetime": "2022-06-23 06:31:00", "tz": "America/Los_Angeles", "bucket": "MIN", "since_datetime": "2022-06-23 06:16:00" }, "event_rule_name": "High Flow Alert" }, { "id": 5270444, "device_id": "6248148189204194987", "triggered_datetime": "2022-06-24T12:41:00.000Z", "flume_leak": false, "query": { "request_id": "SYSTEM_TRIGGERED_USAGE_ALERT", "until_datetime": "2022-06-24 05:42:00", "tz": "America/Los_Angeles", "bucket": "MIN", "since_datetime": "2022-06-24 05:27:00" }, "event_rule_name": "High Flow Alert" }, { "id": 5274373, "device_id": "6248148189204194987", "triggered_datetime": "2022-06-24T18:17:00.000Z", "flume_leak": false, "query": { "request_id": "SYSTEM_TRIGGERED_USAGE_ALERT", "until_datetime": "2022-06-24 11:18:00", "tz": "America/Los_Angeles", "bucket": "MIN", "since_datetime": "2022-06-24 11:03:00" }, "event_rule_name": "High Flow Alert" }, { "id": 5283712, "device_id": "6248148189204194987", "triggered_datetime": "2022-06-25T12:40:00.000Z", "flume_leak": false, "query": { "request_id": "SYSTEM_TRIGGERED_USAGE_ALERT", "until_datetime": "2022-06-25 05:41:00", "tz": "America/Los_Angeles", "bucket": "MIN", "since_datetime": "2022-06-25 05:26:00" }, "event_rule_name": "High Flow Alert" }, { "id": 5296972, "device_id": "6248148189204194987", "triggered_datetime": "2022-06-26T13:09:00.000Z", "flume_leak": false, "query": { "request_id": "SYSTEM_TRIGGERED_USAGE_ALERT", "until_datetime": "2022-06-26 06:10:00", "tz": "America/Los_Angeles", "bucket": "MIN", "since_datetime": "2022-06-26 05:55:00" }, "event_rule_name": "High Flow Alert" }, { "id": 5310367, "device_id": "6248148189204194987", "triggered_datetime": "2022-06-27T12:41:00.000Z", "flume_leak": false, "query": { "request_id": "SYSTEM_TRIGGERED_USAGE_ALERT", "until_datetime": "2022-06-27 05:42:00", "tz": "America/Los_Angeles", "bucket": "MIN", "since_datetime": "2022-06-27 05:27:00" }, "event_rule_name": "High Flow Alert" }, { "id": 5323808, "device_id": "6248148189204194987", "triggered_datetime": "2022-06-28T13:07:00.000Z", "flume_leak": false, "query": { "request_id": "SYSTEM_TRIGGERED_USAGE_ALERT", "until_datetime": "2022-06-28 06:08:00", "tz": "America/Los_Angeles", "bucket": "MIN", "since_datetime": "2022-06-28 05:53:00" }, "event_rule_name": "High Flow Alert" }, { "id": 5351044, "device_id": "6248148189204194987", "triggered_datetime": "2022-06-29T11:13:00.000Z", "flume_leak": false, "query": { "request_id": "SYSTEM_TRIGGERED_USAGE_ALERT", "until_datetime": "2022-06-29 04:14:00", "tz": "America/Los_Angeles", "bucket": "MIN", "since_datetime": "2022-06-29 03:59:00" }, "event_rule_name": "High Flow Alert" }, { "id": 5359491, "device_id": "6248148189204194987", "triggered_datetime": "2022-07-01T11:14:00.000Z", "flume_leak": false, "query": { "request_id": "SYSTEM_TRIGGERED_USAGE_ALERT", "until_datetime": "2022-07-01 04:15:00", "tz": "America/Los_Angeles", "bucket": "MIN", "since_datetime": "2022-07-01 04:00:00" }, "event_rule_name": "High Flow Alert" }, { "id": 5361864, "device_id": "6248148189204194987", "triggered_datetime": "2022-07-01T13:29:00.000Z", "flume_leak": false, "query": { "request_id": "SYSTEM_TRIGGERED_USAGE_ALERT", "until_datetime": "2022-07-01 06:30:00", "tz": "America/Los_Angeles", "bucket": "MIN", "since_datetime": "2022-07-01 06:15:00" }, "event_rule_name": "High Flow Alert" }, { "id": 5373614, "device_id": "6248148189204194987", "triggered_datetime": "2022-07-02T12:43:00.000Z", "flume_leak": false, "query": { "request_id": "SYSTEM_TRIGGERED_USAGE_ALERT", "until_datetime": "2022-07-02 05:44:00", "tz": "America/Los_Angeles", "bucket": "MIN", "since_datetime": "2022-07-02 05:29:00" }, "event_rule_name": "High Flow Alert" }, { "id": 5384498, "device_id": "6248148189204194987", "triggered_datetime": "2022-07-03T11:13:00.000Z", "flume_leak": false, "query": { "request_id": "SYSTEM_TRIGGERED_USAGE_ALERT", "until_datetime": "2022-07-03 04:14:00", "tz": "America/Los_Angeles", "bucket": "MIN", "since_datetime": "2022-07-03 03:59:00" }, "event_rule_name": "High Flow Alert" }, { "id": 5411226, "device_id": "6248148189204194987", "triggered_datetime": "2022-07-05T11:13:00.000Z", "flume_leak": false, "query": { "request_id": "SYSTEM_TRIGGERED_USAGE_ALERT", "until_datetime": "2022-07-05 04:14:00", "tz": "America/Los_Angeles", "bucket": "MIN", "since_datetime": "2022-07-05 03:59:00" }, "event_rule_name": "High Flow Alert" }, { "id": 5413585, "device_id": "6248148189204194987", "triggered_datetime": "2022-07-05T13:24:00.000Z", "flume_leak": false, "query": { "request_id": "SYSTEM_TRIGGERED_USAGE_ALERT", "until_datetime": "2022-07-05 06:25:00", "tz": "America/Los_Angeles", "bucket": "MIN", "since_datetime": "2022-07-05 06:10:00" }, "event_rule_name": "High Flow Alert" }, { "id": 5426430, "device_id": "6248148189204194987", "triggered_datetime": "2022-07-06T12:45:00.000Z", "flume_leak": false, "query": { "request_id": "SYSTEM_TRIGGERED_USAGE_ALERT", "until_datetime": "2022-07-06 05:46:00", "tz": "America/Los_Angeles", "bucket": "MIN", "since_datetime": "2022-07-06 05:31:00" }, "event_rule_name": "High Flow Alert" }, { "id": 5437976, "device_id": "6248148189204194987", "triggered_datetime": "2022-07-07T11:13:00.000Z", "flume_leak": false, "query": { "request_id": "SYSTEM_TRIGGERED_USAGE_ALERT", "until_datetime": "2022-07-07 04:14:00", "tz": "America/Los_Angeles", "bucket": "MIN", "since_datetime": "2022-07-07 03:59:00" }, "event_rule_name": "High Flow Alert" }, { "id": 5440080, "device_id": "6248148189204194987", "triggered_datetime": "2022-07-07T13:13:00.000Z", "flume_leak": false, "query": { "request_id": "SYSTEM_TRIGGERED_USAGE_ALERT", "until_datetime": "2022-07-07 06:14:00", "tz": "America/Los_Angeles", "bucket": "MIN", "since_datetime": "2022-07-07 05:59:00" }, "event_rule_name": "High Flow Alert" }, { "id": 5453334, "device_id": "6248148189204194987", "triggered_datetime": "2022-07-08T12:46:00.000Z", "flume_leak": false, "query": { "request_id": "SYSTEM_TRIGGERED_USAGE_ALERT", "until_datetime": "2022-07-08 05:47:00", "tz": "America/Los_Angeles", "bucket": "MIN", "since_datetime": "2022-07-08 05:32:00" }, "event_rule_name": "High Flow Alert" }, { "id": 5465242, "device_id": "6248148189204194987", "triggered_datetime": "2022-07-09T11:14:00.000Z", "flume_leak": false, "query": { "request_id": "SYSTEM_TRIGGERED_USAGE_ALERT", "until_datetime": "2022-07-09 04:15:00", "tz": "America/Los_Angeles", "bucket": "MIN", "since_datetime": "2022-07-09 04:00:00" }, "event_rule_name": "High Flow Alert" }, { "id": 5467031, "device_id": "6248148189204194987", "triggered_datetime": "2022-07-09T13:14:00.000Z", "flume_leak": false, "query": { "request_id": "SYSTEM_TRIGGERED_USAGE_ALERT", "until_datetime": "2022-07-09 06:15:00", "tz": "America/Los_Angeles", "bucket": "MIN", "since_datetime": "2022-07-09 06:00:00" }, "event_rule_name": "High Flow Alert" }, { "id": 5480078, "device_id": "6248148189204194987", "triggered_datetime": "2022-07-10T13:11:00.000Z", "flume_leak": false, "query": { "request_id": "SYSTEM_TRIGGERED_USAGE_ALERT", "until_datetime": "2022-07-10 06:12:00", "tz": "America/Los_Angeles", "bucket": "MIN", "since_datetime": "2022-07-10 05:57:00" }, "event_rule_name": "High Flow Alert" }, { "id": 5492257, "device_id": "6248148189204194987", "triggered_datetime": "2022-07-11T11:13:00.000Z", "flume_leak": false, "query": { "request_id": "SYSTEM_TRIGGERED_USAGE_ALERT", "until_datetime": "2022-07-11 04:14:00", "tz": "America/Los_Angeles", "bucket": "MIN", "since_datetime": "2022-07-11 03:59:00" }, "event_rule_name": "High Flow Alert" }, { "id": 5494981, "device_id": "6248148189204194987", "triggered_datetime": "2022-07-11T13:22:00.000Z", "flume_leak": false, "query": { "request_id": "SYSTEM_TRIGGERED_USAGE_ALERT", "until_datetime": "2022-07-11 06:23:00", "tz": "America/Los_Angeles", "bucket": "MIN", "since_datetime": "2022-07-11 06:08:00" }, "event_rule_name": "High Flow Alert" }, { "id": 5521358, "device_id": "6248148189204194987", "triggered_datetime": "2022-07-13T11:13:00.000Z", "flume_leak": false, "query": { "request_id": "SYSTEM_TRIGGERED_USAGE_ALERT", "until_datetime": "2022-07-13 04:14:00", "tz": "America/Los_Angeles", "bucket": "MIN", "since_datetime": "2022-07-13 03:59:00" }, "event_rule_name": "High Flow Alert" }, { "id": 5537687, "device_id": "6248148189204194987", "triggered_datetime": "2022-07-14T12:49:00.000Z", "flume_leak": false, "query": { "request_id": "SYSTEM_TRIGGERED_USAGE_ALERT", "until_datetime": "2022-07-14 05:50:00", "tz": "America/Los_Angeles", "bucket": "MIN", "since_datetime": "2022-07-14 05:35:00" }, "event_rule_name": "High Flow Alert" }, { "id": 5549658, "device_id": "6248148189204194987", "triggered_datetime": "2022-07-15T11:13:00.000Z", "flume_leak": false, "query": { "request_id": "SYSTEM_TRIGGERED_USAGE_ALERT", "until_datetime": "2022-07-15 04:14:00", "tz": "America/Los_Angeles", "bucket": "MIN", "since_datetime": "2022-07-15 03:59:00" }, "event_rule_name": "High Flow Alert" }, { "id": 5551885, "device_id": "6248148189204194987", "triggered_datetime": "2022-07-15T13:13:00.000Z", "flume_leak": false, "query": { "request_id": "SYSTEM_TRIGGERED_USAGE_ALERT", "until_datetime": "2022-07-15 06:14:00", "tz": "America/Los_Angeles", "bucket": "MIN", "since_datetime": "2022-07-15 05:59:00" }, "event_rule_name": "High Flow Alert" }, { "id": 5564244, "device_id": "6248148189204194987", "triggered_datetime": "2022-07-16T12:50:00.000Z", "flume_leak": false, "query": { "request_id": "SYSTEM_TRIGGERED_USAGE_ALERT", "until_datetime": "2022-07-16 05:51:00", "tz": "America/Los_Angeles", "bucket": "MIN", "since_datetime": "2022-07-16 05:36:00" }, "event_rule_name": "High Flow Alert" }, { "id": 5575597, "device_id": "6248148189204194987", "triggered_datetime": "2022-07-17T11:12:00.000Z", "flume_leak": false, "query": { "request_id": "SYSTEM_TRIGGERED_USAGE_ALERT", "until_datetime": "2022-07-17 04:13:00", "tz": "America/Los_Angeles", "bucket": "MIN", "since_datetime": "2022-07-17 03:58:00" }, "event_rule_name": "High Flow Alert" }, { "id": 5591234, "device_id": "6248148189204194987", "triggered_datetime": "2022-07-18T12:51:00.000Z", "flume_leak": false, "query": { "request_id": "SYSTEM_TRIGGERED_USAGE_ALERT", "until_datetime": "2022-07-18 05:52:00", "tz": "America/Los_Angeles", "bucket": "MIN", "since_datetime": "2022-07-18 05:37:00" }, "event_rule_name": "High Flow Alert" }, { "id": 5603583, "device_id": "6248148189204194987", "triggered_datetime": "2022-07-19T11:13:00.000Z", "flume_leak": false, "query": { "request_id": "SYSTEM_TRIGGERED_USAGE_ALERT", "until_datetime": "2022-07-19 04:14:00", "tz": "America/Los_Angeles", "bucket": "MIN", "since_datetime": "2022-07-19 03:59:00" }, "event_rule_name": "High Flow Alert" }, { "id": 5606381, "device_id": "6248148189204194987", "triggered_datetime": "2022-07-19T13:29:00.000Z", "flume_leak": false, "query": { "request_id": "SYSTEM_TRIGGERED_USAGE_ALERT", "until_datetime": "2022-07-19 06:30:00", "tz": "America/Los_Angeles", "bucket": "MIN", "since_datetime": "2022-07-19 06:15:00" }, "event_rule_name": "High Flow Alert" }, { "id": 5620785, "device_id": "6248148189204194987", "triggered_datetime": "2022-07-20T12:52:00.000Z", "flume_leak": false, "query": { "request_id": "SYSTEM_TRIGGERED_USAGE_ALERT", "until_datetime": "2022-07-20 05:53:00", "tz": "America/Los_Angeles", "bucket": "MIN", "since_datetime": "2022-07-20 05:38:00" }, "event_rule_name": "High Flow Alert" }, { "id": 5634037, "device_id": "6248148189204194987", "triggered_datetime": "2022-07-21T11:13:00.000Z", "flume_leak": false, "query": { "request_id": "SYSTEM_TRIGGERED_USAGE_ALERT", "until_datetime": "2022-07-21 04:14:00", "tz": "America/Los_Angeles", "bucket": "MIN", "since_datetime": "2022-07-21 03:59:00" }, "event_rule_name": "High Flow Alert" }, { "id": 5636547, "device_id": "6248148189204194987", "triggered_datetime": "2022-07-21T13:20:00.000Z", "flume_leak": false, "query": { "request_id": "SYSTEM_TRIGGERED_USAGE_ALERT", "until_datetime": "2022-07-21 06:21:00", "tz": "America/Los_Angeles", "bucket": "MIN", "since_datetime": "2022-07-21 06:06:00" }, "event_rule_name": "High Flow Alert" }, { "id": 5651243, "device_id": "6248148189204194987", "triggered_datetime": "2022-07-22T12:54:00.000Z", "flume_leak": false, "query": { "request_id": "SYSTEM_TRIGGERED_USAGE_ALERT", "until_datetime": "2022-07-22 05:55:00", "tz": "America/Los_Angeles", "bucket": "MIN", "since_datetime": "2022-07-22 05:40:00" }, "event_rule_name": "High Flow Alert" }, { "id": 5663989, "device_id": "6248148189204194987", "triggered_datetime": "2022-07-23T11:12:00.000Z", "flume_leak": false, "query": { "request_id": "SYSTEM_TRIGGERED_USAGE_ALERT", "until_datetime": "2022-07-23 04:13:00", "tz": "America/Los_Angeles", "bucket": "MIN", "since_datetime": "2022-07-23 03:58:00" }, "event_rule_name": "High Flow Alert" }, { "id": 5679244, "device_id": "6248148189204194987", "triggered_datetime": "2022-07-24T12:54:00.000Z", "flume_leak": false, "query": { "request_id": "SYSTEM_TRIGGERED_USAGE_ALERT", "until_datetime": "2022-07-24 05:55:00", "tz": "America/Los_Angeles", "bucket": "MIN", "since_datetime": "2022-07-24 05:40:00" }, "event_rule_name": "High Flow Alert" }, { "id": 5691434, "device_id": "6248148189204194987", "triggered_datetime": "2022-07-25T11:13:00.000Z", "flume_leak": false, "query": { "request_id": "SYSTEM_TRIGGERED_USAGE_ALERT", "until_datetime": "2022-07-25 04:14:00", "tz": "America/Los_Angeles", "bucket": "MIN", "since_datetime": "2022-07-25 03:59:00" }, "event_rule_name": "High Flow Alert" }, { "id": 5720925, "device_id": "6248148189204194987", "triggered_datetime": "2022-07-27T11:12:00.000Z", "flume_leak": false, "query": { "request_id": "SYSTEM_TRIGGERED_USAGE_ALERT", "until_datetime": "2022-07-27 04:13:00", "tz": "America/Los_Angeles", "bucket": "MIN", "since_datetime": "2022-07-27 03:58:00" }, "event_rule_name": "High Flow Alert" }, { "id": 5723700, "device_id": "6248148189204194987", "triggered_datetime": "2022-07-27T13:27:00.000Z", "flume_leak": false, "query": { "request_id": "SYSTEM_TRIGGERED_USAGE_ALERT", "until_datetime": "2022-07-27 06:28:00", "tz": "America/Los_Angeles", "bucket": "MIN", "since_datetime": "2022-07-27 06:13:00" }, "event_rule_name": "High Flow Alert" }, { "id": 5737526, "device_id": "6248148189204194987", "triggered_datetime": "2022-07-28T12:58:00.000Z", "flume_leak": false, "query": { "request_id": "SYSTEM_TRIGGERED_USAGE_ALERT", "until_datetime": "2022-07-28 05:59:00", "tz": "America/Los_Angeles", "bucket": "MIN", "since_datetime": "2022-07-28 05:44:00" }, "event_rule_name": "High Flow Alert" }, { "id": 5749779, "device_id": "6248148189204194987", "triggered_datetime": "2022-07-29T11:12:00.000Z", "flume_leak": false, "query": { "request_id": "SYSTEM_TRIGGERED_USAGE_ALERT", "until_datetime": "2022-07-29 04:13:00", "tz": "America/Los_Angeles", "bucket": "MIN", "since_datetime": "2022-07-29 03:58:00" }, "event_rule_name": "High Flow Alert" }, { "id": 5752512, "device_id": "6248148189204194987", "triggered_datetime": "2022-07-29T13:27:00.000Z", "flume_leak": false, "query": { "request_id": "SYSTEM_TRIGGERED_USAGE_ALERT", "until_datetime": "2022-07-29 06:28:00", "tz": "America/Los_Angeles", "bucket": "MIN", "since_datetime": "2022-07-29 06:13:00" }, "event_rule_name": "High Flow Alert" }, { "id": 5765668, "device_id": "6248148189204194987", "triggered_datetime": "2022-07-30T12:59:00.000Z", "flume_leak": false, "query": { "request_id": "SYSTEM_TRIGGERED_USAGE_ALERT", "until_datetime": "2022-07-30 06:00:00", "tz": "America/Los_Angeles", "bucket": "MIN", "since_datetime": "2022-07-30 05:45:00" }, "event_rule_name": "High Flow Alert" }, { "id": 5777345, "device_id": "6248148189204194987", "triggered_datetime": "2022-07-31T11:12:00.000Z", "flume_leak": false, "query": { "request_id": "SYSTEM_TRIGGERED_USAGE_ALERT", "until_datetime": "2022-07-31 04:13:00", "tz": "America/Los_Angeles", "bucket": "MIN", "since_datetime": "2022-07-31 03:58:00" }, "event_rule_name": "High Flow Alert" }, { "id": 5779249, "device_id": "6248148189204194987", "triggered_datetime": "2022-07-31T13:18:00.000Z", "flume_leak": false, "query": { "request_id": "SYSTEM_TRIGGERED_USAGE_ALERT", "until_datetime": "2022-07-31 06:19:00", "tz": "America/Los_Angeles", "bucket": "MIN", "since_datetime": "2022-07-31 06:04:00" }, "event_rule_name": "High Flow Alert" }, { "id": 5793493, "device_id": "6248148189204194987", "triggered_datetime": "2022-08-01T13:00:00.000Z", "flume_leak": false, "query": { "request_id": "SYSTEM_TRIGGERED_USAGE_ALERT", "until_datetime": "2022-08-01 06:01:00", "tz": "America/Los_Angeles", "bucket": "MIN", "since_datetime": "2022-08-01 05:46:00" }, "event_rule_name": "High Flow Alert" } ], "count": 122, "pagination": null }PyFlume-0.8.7/tests/test_auth.py000066400000000000000000000023351463621261200166310ustar00rootroot00000000000000"""Basic tests for flume Auth. This module contains unittest classes for testing different functionalities of flume.""" # Standard library imports import unittest # Third-party imports from requests import Session import requests_mock # Local application/library-specific imports import pyflume from .constants import ( CONST_CLIENT_ID, CONST_CLIENT_SECRET, CONST_FLUME_TOKEN, CONST_HTTP_METHOD_POST, CONST_PASSWORD, CONST_TOKEN_FILE, CONST_USER_ID, CONST_USERNAME, ) from .utils import load_fixture class TestFlumeAuth(unittest.TestCase): """Flume Auth Test Case.""" @requests_mock.Mocker() def test_auth(self, mock): """ Test initialization for Flume Auth. Args: mock: Requests mock. """ mock.register_uri( CONST_HTTP_METHOD_POST, pyflume.constants.URL_OAUTH_TOKEN, text=load_fixture(CONST_TOKEN_FILE), ) auth = pyflume.FlumeAuth( CONST_USERNAME, CONST_PASSWORD, CONST_CLIENT_ID, CONST_CLIENT_SECRET, CONST_FLUME_TOKEN, http_session=Session(), ) assert auth.user_id == CONST_USER_ID # noqa: S101 PyFlume-0.8.7/tests/test_data.py000066400000000000000000000040501463621261200165750ustar00rootroot00000000000000"""Basic tests for flume Data. This module contains unittest classes for testing different functionalities of flume.""" # Standard library imports import unittest # Third-party imports from requests import Session import requests_mock # Local application/library-specific imports import pyflume from .constants import ( CONST_CLIENT_ID, CONST_CLIENT_SECRET, CONST_FLUME_TOKEN, CONST_HTTP_METHOD_POST, CONST_PASSWORD, CONST_SCAN_INTERVAL, CONST_TOKEN_FILE, CONST_USER_ID, CONST_USERNAME, ) from .utils import load_fixture class TestFlumeData(unittest.TestCase): """Test Flume Data Test.""" @requests_mock.Mocker() def test_data(self, mock): """Test initialization for Flume Data. Args: mock: Requests mock. """ mock.register_uri( CONST_HTTP_METHOD_POST, pyflume.constants.URL_OAUTH_TOKEN, text=load_fixture(CONST_TOKEN_FILE), ) mock.register_uri( CONST_HTTP_METHOD_POST, pyflume.constants.API_QUERY_URL.format( user_id=CONST_USER_ID, device_id="device_id", ), text=load_fixture("query.json"), ) flume_auth = pyflume.FlumeAuth( CONST_USERNAME, CONST_PASSWORD, CONST_CLIENT_ID, CONST_CLIENT_SECRET, CONST_FLUME_TOKEN, ) flume = pyflume.FlumeData( flume_auth, "device_id", "America/Los_Angeles", CONST_SCAN_INTERVAL, http_session=Session(), update_on_init=False, ) assert flume.values == {} # noqa: S101,WPS520 flume.update() assert flume.values == { # noqa: S101 "current_interval": 14.38855184, "today": 56.6763912, "week_to_date": 1406.07065872, "month_to_date": 56.6763912, "last_60_min": 14.38855184, "last_24_hrs": 258.9557672, "last_30_days": 5433.56753264, } PyFlume-0.8.7/tests/test_devices.py000066400000000000000000000030101463621261200173010ustar00rootroot00000000000000"""Basic tests for flume Data. This module contains unittest classes for testing different functionalities of flume.""" # Standard library imports import unittest # Third-party imports import requests_mock # Local application/library-specific imports import pyflume from .constants import ( CONST_CLIENT_ID, CONST_CLIENT_SECRET, CONST_FLUME_TOKEN, CONST_HTTP_METHOD_POST, CONST_PASSWORD, CONST_TOKEN_FILE, CONST_USER_ID, CONST_USERNAME, ) from .utils import load_fixture class TestFlumeDeviceList(unittest.TestCase): """Flume Device List Test Case.""" @requests_mock.Mocker() def test_devices(self, mock): """Test initialization for Flume Device List. Args: mock: Requests mock. """ mock.register_uri( CONST_HTTP_METHOD_POST, pyflume.constants.URL_OAUTH_TOKEN, text=load_fixture(CONST_TOKEN_FILE), ) mock.register_uri( "get", pyflume.constants.API_DEVICES_URL.format(user_id=CONST_USER_ID), text=load_fixture("devices.json"), ) flume_auth = pyflume.FlumeAuth( CONST_USERNAME, CONST_PASSWORD, CONST_CLIENT_ID, CONST_CLIENT_SECRET, CONST_FLUME_TOKEN, ) flume_devices = pyflume.FlumeDeviceList(flume_auth) devices = flume_devices.get_devices() assert len(devices) == 1 # noqa: S101 assert devices[0][CONST_USER_ID] == 1111 # noqa: S101,WPS432 PyFlume-0.8.7/tests/test_leak.py000066400000000000000000000031221463621261200165770ustar00rootroot00000000000000"""Basic tests for flume leaks. This module contains unittest classes for testing different functionalities of flume.""" # Standard library imports import unittest # Third-party imports import requests_mock # Local application/library-specific imports import pyflume from .constants import ( CONST_CLIENT_ID, CONST_CLIENT_SECRET, CONST_FLUME_TOKEN, CONST_HTTP_METHOD_POST, CONST_PASSWORD, CONST_TOKEN_FILE, CONST_USER_ID, CONST_USERNAME, ) from .utils import load_fixture class TestFlumeLeakList(unittest.TestCase): """Test Flume Leak List Test.""" @requests_mock.Mocker() def test_leak(self, mock): """ Test initialization for Flume Usage Leak List. Args: mock: Requests mock. """ mock.register_uri( CONST_HTTP_METHOD_POST, pyflume.constants.URL_OAUTH_TOKEN, text=load_fixture(CONST_TOKEN_FILE), ) mock.register_uri( "get", pyflume.constants.API_LEAK_URL.format( user_id=CONST_USER_ID, device_id="6248148189204194987", ), text=load_fixture("leak.json"), ) flume_auth = pyflume.FlumeAuth( CONST_USERNAME, CONST_PASSWORD, CONST_CLIENT_ID, CONST_CLIENT_SECRET, CONST_FLUME_TOKEN, ) flume_leaks = pyflume.FlumeLeakList(flume_auth, "6248148189204194987") alerts = flume_leaks.get_leaks() assert len(alerts) == 1 # noqa: S101 assert alerts[0]["active"] # noqa: S101 PyFlume-0.8.7/tests/test_notifications.py000066400000000000000000000050701463621261200205400ustar00rootroot00000000000000"""Basic tests for flume notifications. This module contains unittest classes for testing different functionalities of flume.""" # Standard library imports import unittest # Third-party imports import requests_mock # Local application/library-specific imports import pyflume from .constants import ( CONST_CLIENT_ID, CONST_CLIENT_SECRET, CONST_FLUME_TOKEN, CONST_HTTP_METHOD_POST, CONST_PASSWORD, CONST_TOKEN_FILE, CONST_USER_ID, CONST_USERNAME, ) from .utils import load_fixture class TestFlumeNotificationList(unittest.TestCase): """Test Flume Notification List Test.""" @requests_mock.Mocker() def test_notification(self, mock): """ Test initialization for Flume Notification List. Args: mock: Requests mock. """ mock.register_uri( CONST_HTTP_METHOD_POST, pyflume.constants.URL_OAUTH_TOKEN, text=load_fixture(CONST_TOKEN_FILE), ) mock.register_uri( "get", pyflume.constants.API_NOTIFICATIONS_URL.format(user_id=CONST_USER_ID), text=load_fixture("notification.json"), ) flume_auth = pyflume.FlumeAuth( CONST_USERNAME, CONST_PASSWORD, CONST_CLIENT_ID, CONST_CLIENT_SECRET, CONST_FLUME_TOKEN, ) flume_notifications = pyflume.FlumeNotificationList(flume_auth) notifications = flume_notifications.get_notifications() assert len(notifications) == 1 # noqa: S101 assert notifications[0][CONST_USER_ID] == 1111 # noqa: S101,WPS432 assert flume_notifications.has_next # noqa: S101 mock.register_uri( "get", flume_notifications.next_page, text=load_fixture("notification_next.json"), ) notifications_next = flume_notifications.get_next_notifications() assert len(notifications_next) == 1 # noqa: S101 assert notifications_next[0][CONST_USER_ID] == 1111 # noqa: S101,WPS432 assert flume_notifications.has_next is False # noqa: S101 mock.register_uri( "get", pyflume.constants.API_NOTIFICATIONS_URL.format(user_id=CONST_USER_ID), text=load_fixture("notification_nopage.json"), ) notifications_nopage = flume_notifications.get_notifications() assert len(notifications_nopage) == 1 # noqa: S101 assert notifications_nopage[0][CONST_USER_ID] == 1111 # noqa: S101,WPS432 assert flume_notifications.has_next is False # noqa: S101 PyFlume-0.8.7/tests/test_usage.py000066400000000000000000000052611463621261200167750ustar00rootroot00000000000000"""Basic tests for flume usage alerts. This module contains unittest classes for testing different functionalities of flume.""" # Standard library imports import unittest # Third-party imports import requests_mock # Local application/library-specific imports import pyflume from .constants import ( CONST_CLIENT_ID, CONST_CLIENT_SECRET, CONST_FLUME_TOKEN, CONST_HTTP_METHOD_POST, CONST_PASSWORD, CONST_TOKEN_FILE, CONST_USER_ID, CONST_USERNAME, ) from .utils import load_fixture class TestFlumeUsageAlerts(unittest.TestCase): """Test Flume Usage Alerts Test.""" @requests_mock.Mocker() def test_usage(self, mock): """ Test initialization for Flume Usage Alerts List. Args: mock: Requests mock. """ mock.register_uri( CONST_HTTP_METHOD_POST, pyflume.constants.URL_OAUTH_TOKEN, text=load_fixture(CONST_TOKEN_FILE), ) mock.register_uri( "get", pyflume.constants.API_USAGE_URL.format(user_id=CONST_USER_ID), text=load_fixture("usage.json"), ) flume_auth = pyflume.FlumeAuth( CONST_USERNAME, CONST_PASSWORD, CONST_CLIENT_ID, CONST_CLIENT_SECRET, CONST_FLUME_TOKEN, ) flume_alerts = pyflume.FlumeUsageAlertList(flume_auth) alerts = flume_alerts.get_usage_alerts() assert len(alerts) == 50 # noqa: S101, WPS432 assert alerts[0]["device_id"] == "6248148189204194987" # noqa: S101 assert alerts[0]["event_rule_name"] == "High Flow Alert" # noqa: S101 assert flume_alerts.has_next # noqa: S101 mock.register_uri( "get", flume_alerts.next_page, text=load_fixture("usage_next.json"), ) alerts_next = flume_alerts.get_next_usage_alerts() assert len(alerts_next) == 50 # noqa: S101, WPS432 assert alerts_next[0]["device_id"] == "6248148189204194987" # noqa: S101 assert alerts_next[0]["event_rule_name"] == "High Flow Alert" # noqa: S101 assert flume_alerts.has_next is False # noqa: S101 mock.register_uri( "get", pyflume.constants.API_USAGE_URL.format(user_id=CONST_USER_ID), text=load_fixture("usage_nopage.json"), ) alerts_nopage = flume_alerts.get_usage_alerts() assert len(alerts_nopage) == 50 # noqa: S101, WPS432 assert alerts_nopage[0]["device_id"] == "6248148189204194987" # noqa: S101 assert alerts_nopage[0]["event_rule_name"] == "High Flow Alert" # noqa: S101 assert flume_alerts.has_next is False # noqa: S101 PyFlume-0.8.7/tests/utils.py000066400000000000000000000005161463621261200157700ustar00rootroot00000000000000"""Utils to support Flume tests.""" import os def load_fixture(filename): """Load a fixture. Args: filename: File to load fixture. Returns: File fixture contents. """ path = os.path.join(os.path.dirname(__file__), "fixtures", filename) with open(path) as fptr: return fptr.read() PyFlume-0.8.7/tox.ini000066400000000000000000000006501463621261200144260ustar00rootroot00000000000000# tox (https://tox.readthedocs.io/) is a tool for running tests # in multiple virtualenvs. This configuration file will run the # test suite on all supported python versions. To use it, "pip install tox" # and then run "tox" from this directory. [tox] envlist = py3 skip_missing_interpreters = True [testenv] deps = pyjwt pytest ratelimit requests requests_mock commands = pytest