-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_aggregate_user.py
60 lines (47 loc) · 1.56 KB
/
test_aggregate_user.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
##File query_test.py
import unittest
from unittest import TestCase
import numpy as np
from numpy.testing._private.utils import assert_equal
from sqlalchemy.sql.sqltypes import BIGINT, JSON, Integer
import process
from sqlalchemy import create_engine, text
from sqlalchemy.sql import *
import os
import os.path
import sys
from numpy.core.defchararray import count
import pandas as pd
import time
# import db configs
from config import *
class TestQuery(unittest.TestCase):
def test_query(self):
CAPTURE_FILE_NAME = 'data'
if len(CAPTURES_DIR) <= 0:
print("No captures directory declared in config.py. Exiting.")
sys.exit(1)
if not os.path.exists(CAPTURES_DIR):
os.mkdir(CAPTURES_DIR)
# create db connection
try:
# dialect+driver://username:password@host:port/database
connection_string = f'mysql+pymysql://{DB_USER}:{DB_PASS}@{DB_HOST}:{DB_PORT}/{DB_NAME}'
engine = create_engine(connection_string)
except Exception as e:
print(e)
sys.exit(1)
# aggregate_user testing
user_flag = process.aggregate_user(126,5,2)
with engine.connect() as conn:
with conn.begin():
query = text("""
SELECT *
FROM aggregate_user;
"""
)
result = conn.execute(query)
count = [r[1:] for r in result]
sum = np.sum(count)
# aggregate_user
self.assertEqual(sum, 16797)