def fetch_requests(self) -> List[SearchRequest]: supabase: Client = create_client(self.url, self.key) data = supabase.table('search_request').select(f"*").filter( 'datasource', 'eq', self.target_type).execute() data = data.get('data') ret = [SearchRequest.from_json(d) for d in data] return ret
def test_client_select(): """Ensure we can select data from a table.""" from supabase_py import create_client, Client url: str = os.environ.get("SUPABASE_TEST_URL") key: str = os.environ.get("SUPABASE_TEST_KEY") supabase: Client = create_client(url, key) data = supabase.table("countries").select("*")
def test_client_select(): """Ensure we can select data from a table.""" from supabase_py import create_client, Client url: str = os.environ.get("SUPABASE_TEST_URL") key: str = os.environ.get("SUPABASE_TEST_KEY") supabase: Client = create_client(url, key) # TODO(fedden): Add this set back in (and expand on it) when postgrest and # realtime libs are working. data = supabase.table("countries").select("*").execute() # Assert we pulled real data. assert len(data.get("data", [])) > 0
def create_db_conn() -> Client: ''' Creates a connection to Supabase Returns: A Supabase Client ''' try: logging.info('connecting to db...') supabase_url = config.SUPABASE_URL supabase_key = config.SUPABASE_KEY supabase: Client = create_client(supabase_url, supabase_key) logging.info('connected to db!') return supabase except Exception as e: logging.error('error creating connection to database:') logging.error(e) return None
def test_client_auth(): """Ensure we can create an auth user, and login with it.""" from supabase_py import create_client, Client url: str = os.environ.get("SUPABASE_TEST_URL") key: str = os.environ.get("SUPABASE_TEST_KEY") supabase: Client = create_client(url, key) # Create a random user login email and password. random_email: str = f"{_random_string(10)}@supamail.com" random_password: str = _random_string(20) # Sign up (and sign in). user = supabase.auth.sign_up(email=random_email, password=random_password) _assert_authenticated_user(user) # Sign out. user = supabase.auth.sign_out() _assert_unauthenticated_user(user) # Sign in (explicitly this time). user = supabase.auth.sign_in(email=random_email, password=random_password) _assert_authenticated_user(user)
def test_client_insert(): """Ensure we can select data from a table.""" from supabase_py import create_client, Client url: str = os.environ.get("SUPABASE_TEST_URL") key: str = os.environ.get("SUPABASE_TEST_KEY") supabase: Client = create_client(url, key) data = supabase.table("countries").select("*").execute() # Assert we pulled real data. previous_length: int = len(data.get("data", [])) new_row = { "name": "test name", "iso2": "test iso2", "iso3": "test iso3", "local_name": "test local name", "continent": None, } result = supabase.table("countries").insert(new_row).execute() data = supabase.table("countries").select("*").execute() current_length: int = len(data.get("data", [])) # Ensure we've added a row remotely. assert current_length == previous_length + 1 # Check returned result for insert was valid. assert result.get("status_code", 400) == 201
def __init__(self, url: str, key: str, session: Dict[str, Any]): self.session = session self.supabase: Client = create_client(url, key, session)
def test_incorrect_values_dont_instanciate_client(url: Any, key: Any): """Ensure we can't instanciate client with nonesense values.""" from supabase_py import create_client, Client _: Client = create_client(url, key)
def upload_result(self, search_results: List[SearchResult]): supabase: Client = create_client(self.url, self.key) for r in search_results: data = supabase.table("posts").insert(r.to_json()).execute() print(data) assert len(data.get("data", [])) > 0
import os import json from flask import Flask, request, render_template, redirect, send_from_directory from supabase_py import Client, create_client from pytezos import pytezos app = Flask(__name__) pyt = pytezos.using(key=os.environ["TEZOS_KEY"], shell="https://edonet.smartpy.io") contr = pyt.contract(os.environ["CONTRACT_ADDRESS"]) url: str = os.environ["SUPABASE_URL"] key: str = os.environ["SUPABASE_KEY"] supabase: Client = create_client(url, key) @app.route("/favicon.ico") def favicon(): return send_from_directory(os.path.join(app.root_path, 'static'), 'assets/favicon.png', mimetype='image/vnd.microsoft.icon') @app.route("/") def home(): if supabase.auth.current_user: authenticated = True else: authenticated = False