Skip to content

Commit

Permalink
refactor(test): add faker for generating fake stuff and put all tests…
Browse files Browse the repository at this point in the history
… in a single file
  • Loading branch information
TudorAndrei-Pythia committed Oct 4, 2023
1 parent e8688a2 commit 4b98f1d
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 71 deletions.
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ dev = [
"pytest-dependency",
"commitizen",
"flit",
"Faker",
]
docs = [
"mkdocs",
Expand Down
75 changes: 51 additions & 24 deletions tests/test_insert.py → tests/test_all.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import asyncio

import pytest

from faker import Faker
from sirqle.query import Config, Query

fake = Faker()


config = Config(
url="127.0.0.1:9120",
namespace="test",
Expand All @@ -25,9 +28,9 @@ def event_loop():

class TestInsert:
data = {
"name": "SurrealDB",
"founded": "2021-09-10",
"founders": ["tobie", "jaime"],
"name": fake.company(),
"founded": fake.date(),
"founders": [fake.name(), fake.name()],
"tags": ["big data", "database"],
}

Expand All @@ -41,17 +44,16 @@ async def test_insert(self):
table_name = "company"
insert_query.insert(table_name, values=self.data)
res = await insert_query.execute()
res = res[0]["result"]
assert res[0]["id"].split(":")[0] == table_name.split(" ")[0]
assert res[0]["name"] == self.data["name"]
assert res[0]["founded"] == "2021-09-10T00:00:00Z"
assert res[0]["founded"] == self.data["founded"]
assert res[0]["name"] == self.data["name"]


class TestInsertSQL:
table_name = "person"
data = tuple(["John", "SurrealDB", "2021-09-10"])
SQL = "INSERT INTO company (name, founded) VALUES ('SurrealDB', '2021-09-10');"
data = tuple([fake.name(), fake.company(), fake.date()])
SQL = "INSERT INTO company (name, founded) VALUES ('Company 2', '2021-09-10');"

@pytest.mark.asyncio
async def test_insert_sql(self):
Expand All @@ -63,28 +65,27 @@ async def test_insert_sql(self):
table_name = f"{self.table_name} (name, company, founded)"
insert_query.insert(table_name, values=self.data)
res = await insert_query.execute()
res = res[0]["result"]
assert res[0]["company"] == "SurrealDB"
assert res[0]["founded"] == "2021-09-10T00:00:00Z"
assert res[0]["name"] == "John"
self.id = res[0]["id"]
assert res[0]["name"] == self.data[0]
assert res[0]["company"] == self.data[1]
assert res[0]["founded"] == self.data[2]

@pytest.mark.asyncio
@pytest.mark.dependency(on=["test_insert_sql"])
async def test_select(self):
"""Test the functionality of INSERT by looking in the database."""
query = Query(config=config)
query.select("*").from_(self.table_name)
query.select().from_(self.table_name)
res = await query.execute()
res = res[0]["result"]
assert res[0]["company"] == self.data[1]
assert res[0]["founded"] == "2021-09-10T00:00:00Z"
assert res[0]["name"] == self.data[0]
assert res[0]["company"] == self.data[1]
assert res[0]["founded"] == self.data[2]


class TestInsertValue:
table = "company"
table_name = f"{table} (name, founded)"
data = tuple(["SurrealDB", "2021-09-10"])
data = tuple([fake.company(), fake.date()])

@pytest.mark.asyncio
async def test_insert_value(self):
Expand All @@ -95,17 +96,43 @@ async def test_insert_value(self):
insert_query = Query(config=config)
insert_query.insert(self.table_name, values=self.data)
res = await insert_query.execute()
res = res[0]["result"]
assert res[0]["name"] == "SurrealDB"
assert res[0]["founded"] == "2021-09-10T00:00:00Z"
assert res[0]["name"] == self.data[0]
assert res[0]["founded"] == self.data[1]

@pytest.mark.asyncio
@pytest.mark.dependency(on=["test_insert_value"])
async def test_select2(self):
async def test_select(self):
"""Test the functionality of INSERT by looking in the database."""
query = Query(config=config)
query.select("*").from_(self.table)
res = await query.execute()
res = res[0]["result"]
assert res[0]["name"] == "SurrealDB"
assert res[0]["founded"] == "2021-09-10T00:00:00Z"
assert res[0]["name"] == self.data[0]
assert res[0]["founded"] == self.data[1]


class TestCreate:
data = {
"name": fake.name(),
"company": fake.company(),
"skills": ["Rust", "Go", "JavaScript"],
}
table_name = "person"

@pytest.mark.asyncio
async def test_create(self):
"""Test the functionality of CREATE.
Create an entry in the database.
"""
create_query = Query(config=config)
create_query.create(self.table_name).content(self.data)
await create_query.execute()

@pytest.mark.asyncio
@pytest.mark.dependency(on=["test_create"])
async def test_select(self):
"""Test the functionality of CREATE by looking in the database."""
query = Query(config=config)
query.select(list(self.data.keys())).from_(self.table_name)
res = await query.execute()
assert res[0] == self.data
47 changes: 0 additions & 47 deletions tests/test_create.py

This file was deleted.

0 comments on commit 4b98f1d

Please sign in to comment.