Add a method to get participant usernames and its test.

communication
junos 2021-04-07 15:43:07 +02:00
parent b7b60294ba
commit e6d129c6ee
3 changed files with 37 additions and 0 deletions

View File

View File

@ -0,0 +1,27 @@
import datetime
from collections.abc import Collection
import pandas as pd
from sqlalchemy import and_
from config.models import Participant
from setup import db_engine, session
def get_usernames(
tester: bool = False,
active: bool = False,
collection_start: datetime.date = datetime.date.fromisoformat("2020-01-01"),
last_upload: datetime.date = datetime.date.today(),
) -> Collection:
query_participant_usernames = session.query(Participant.username).filter(
and_(
Participant.tester == tester,
Participant.active == active,
Participant.collection_start_utc >= collection_start,
Participant.last_upload_utc < last_upload,
)
)
with db_engine.connect() as connection:
df_participants = pd.read_sql(query_participant_usernames.statement, connection)
return df_participants

View File

@ -0,0 +1,10 @@
import unittest
from participants.query_db import get_usernames
class CallsFeatures(unittest.TestCase):
def test_get_usernames(self):
usernames_from_db = get_usernames()
print(usernames_from_db)
self.assertIsNotNone(usernames_from_db)