コード例 #1
0
ファイル: test_bills.py プロジェクト: mkrump/chicagoledger
def test_exists(bills_table):
    item = BillMapper().to_db(EXAMPLE_INTRODUCTIONS[0])
    bills_table.put_item(Item=item)

    bills = Bills(boto3.Session())
    assert bills.exists(EXAMPLE_INTRODUCTIONS[0]) is True
    assert bills.exists(EXAMPLE_INTRODUCTIONS[1]) is False
コード例 #2
0
ファイル: test_bills.py プロジェクト: mkrump/chicagoledger
def test_get(bills_table):
    bill = EXAMPLE_INTRODUCTIONS[0]
    item = BillMapper().to_db(bill)
    bills_table.put_item(Item=item)

    bills = Bills(boto3.Session())
    bill = bills.get(bill)
    assert bill == EXAMPLE_INTRODUCTIONS[0]
コード例 #3
0
ファイル: test_bills.py プロジェクト: mkrump/chicagoledger
def test_insert(bills_table):
    bills = Bills(boto3.Session())
    for introduction in EXAMPLE_INTRODUCTIONS:
        bills.insert(introduction)

    intro1 = bills.get(EXAMPLE_INTRODUCTIONS[0])
    intro2 = bills.get(EXAMPLE_INTRODUCTIONS[1])
    assert intro1 == EXAMPLE_INTRODUCTIONS[0]
    assert intro2 == EXAMPLE_INTRODUCTIONS[1]
コード例 #4
0
ファイル: test_bills.py プロジェクト: mkrump/chicagoledger
def test_no_tweet(bills_table):
    no_tweet_id_bills = [
        Bill(str(i), None, None, None, '10/25/18') for i in range(4)
    ]
    have_tweet_id_bills = [
        Bill(str(len(no_tweet_id_bills) + i), None, None, None, '10/25/18',
             str(i)) for i in range(4)
    ]
    bills = Bills(boto3.Session())
    combined_bills = no_tweet_id_bills + have_tweet_id_bills
    for bill in combined_bills:
        bills.insert(bill)
    assert sorted(bills.missing_tweet_id(),
                  key=lambda x: x.identifier) == no_tweet_id_bills
コード例 #5
0
def setup(app_config):
    boto3_session = generate_boto3_session(app_config.aws_profile)
    bills = Bills(boto3_session)

    twitter_client = twitter_client_from_aws(boto3_session, app_config.aws_secret_name)
    twitter_bot = TwitterBot(twitter_client)
    return App(bills, twitter_bot)
コード例 #6
0
def setup(app_config):
    requests_session = requests.Session()
    ocd_bills_api = BillsAPI(requests_session)

    boto3_session = generate_boto3_session(app_config.aws_profile)
    bills = Bills(boto3_session)

    return App(ocd_bills_api, app_config.query, bills)
コード例 #7
0
ファイル: test_bills.py プロジェクト: mkrump/chicagoledger
def test_get_prev_tweet_id():
    session = boto3.Session()
    client = session.client('dynamodb')
    test_table_name = 'bills_test'
    client.create_table(
        TableName=test_table_name,
        AttributeDefinitions=AttributeDefinitions,
        KeySchema=KeySchema,
        ProvisionedThroughput=ProvisionedThroughput,
        GlobalSecondaryIndexes=GlobalSecondaryIndexes,
    )
    print('Waiting for', test_table_name, '...')
    waiter = client.get_waiter('table_exists')
    waiter.wait(TableName=test_table_name)

    introductions = [
        Bill('1', 'text', ['tag'], 'ocd-id', '10/28/18', '789'),
        Bill('2', 'text', ['tag'], 'ocd-id', '10/28/18', '123'),
        Bill('3', 'text', ['tag'], 'ocd-id', '10/28/18', '10000'),
        Bill('4', 'text', ['tag'], 'ocd-id', '10/28/18', '1'),
        Bill('5', 'text', ['tag'], 'ocd-id', '10/29/18', '10000000')
    ]
    bills = Bills(boto3.Session(), test_table_name)
    for introduction in introductions:
        bills.insert(introduction)

    prev_tweet_id = bills.get_prev_tweet_id('10/29/18')
    assert prev_tweet_id == '10000000'
    prev_tweet_id = bills.get_prev_tweet_id('10/28/18')
    assert prev_tweet_id == '10000'
    client.delete_table(TableName=test_table_name)
    waiter = client.get_waiter('table_not_exists')
    waiter.wait(TableName=test_table_name)