-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.py
67 lines (53 loc) · 1.64 KB
/
test.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
"""
Foo bar
"""
import inspect
from uuid import uuid4
from pprint import pprint
import models
import rethinkdb as rethink
from helpers import generate_packet, generate_error
ENDPOINTS = ["friend", "user", "message"]
PATH = "/api/v1/channel/paradigmshift3d/friend"
MODEL = "friend"
METHOD = "GET"
USER = "paradigmshift3d"
RDB_CONN = rethink.connect(host="localhost",
db="cactus")
DATA = list(rethink.table(MODEL + "s").run(RDB_CONN))
if DATA == []:
print("ERRORS AND DOOM!")
error_packet, errors = generate_error(
uid=uuid4(),
status="404",
code="405",
title="Table does not have any entries",
detail="Friends table does not have any entries",
source={"pointer": PATH})
if errors is not None:
print("Errors happened when making the error packet!")
print(errors)
else:
print({"errors": [error_packet]})
POST_IGNORE = []
# Remove the ignored keys
for name, obj in inspect.getmembers(models):
if name.lower() == MODEL:
for foo in DATA:
POST_IGNORE.append(
{key: foo[key] for key in foo if key not in obj.ignore})
relationships = [
relationship.lower() for relationship in obj.belongs_to]
relationships.extend([relate.lower() for relate in obj.has_one])
relationships.extend([relate.lower() for relate in obj.has_many])
relationships.extend([
relate.lower() for relate in obj.has_and_belongs_to_many])
# Generate the final packet
PACKET = [generate_packet(
MODEL,
uuid4(),
data,
PATH,
relationships
) for data in POST_IGNORE]
pprint(PACKET)