예제 #1
0
def test_processPages(table_name):
    ip = randomIP()
    this_event = event(ip, table_name)
    visits = [
        itemToVisit(record['dynamodb']['NewImage'])
        for record in this_event['Records']
        if record['dynamodb']['NewImage']['Type']['S'] == 'visit'
    ]
    client = DynamoClient(table_name)
    client.addVisitor(Visitor(ip))
    client.addVisits(visits)
    client.addBrowsers([
        itemToBrowser(record['dynamodb']['NewImage'])
        for record in this_event['Records']
        if record['dynamodb']['NewImage']['Type']['S'] == 'browser'
    ])
    for session in [
            itemToSession(record['dynamodb']['NewImage'])
            for record in this_event['Records']
            if record['dynamodb']['NewImage']['Type']['S'] == 'session'
    ]:
        client.addSession(session)
    assert processPages( client, this_event ) == 'Successfully added ' + \
      f'{ len( { visit.slug for visit in visits } ) } pages and updated 0 ' + \
      f'from { len( visits ) } records.'
예제 #2
0
def test_duplicate_addSession(dynamo_client, table_init, table_name, session):
    client = DynamoClient(table_name)
    client.addSession(session)
    result = client.addSession(session)
    assert 'error' in result.keys()
    assert result['error'] == 'Visitor\'s session is already in table ' \
      + f'{ session }'
예제 #3
0
def test_duplicate_addBrowser(dynamo_client, table_init, table_name, browser):
    client = DynamoClient(table_name)
    client.addBrowser(browser)
    result = client.addBrowser(browser)
    assert 'error' in result.keys()
    assert result['error'] == 'Visitor\'s browser is already in table ' \
      + f'{ browser }'
예제 #4
0
 def test_duplicate_visitor_addNewVisitor(self, table_name, visitor,
                                          browsers, visits):
     client = DynamoClient(table_name)
     result = client.addVisitor(visitor)
     result = client.addNewVisitor(visitor, location(), browsers, visits)
     assert 'error' in result.keys()
     assert result['error'] == f'Visitor already in table { visitor }'
예제 #5
0
def test_duplicate_addLocation(table_name):
    client = DynamoClient(table_name)
    client.addLocation(location())
    result = client.addLocation(location())
    assert 'error' in result.keys()
    assert result['error'] == 'Visitor\'s location is already in table ' \
      + f'{ location() }'
예제 #6
0
def test_none_getSessionDetails(
  dynamo_client, table_init, table_name, session
):
  client = DynamoClient( table_name )
  result = client.getSessionDetails( session )
  assert 'error' in result.keys()
  assert result['error'] == 'Session not in table'
예제 #7
0
def test_duplicate_addVisit( dynamo_client, table_init, table_name, visit ):
  client = DynamoClient( table_name )
  client.addVisit( visit )
  result = client.addVisit( visit )
  assert 'error' in result.keys()
  assert result['error'] == 'Visitor\'s page visit is already in table ' \
    + f'{ visit }'
예제 #8
0
 def test_incrementVisitorSessions(self, table_name, visitor):
     client = DynamoClient(table_name)
     client.addVisitor(visitor)
     result = client.incrementVisitorSessions(visitor)
     visitor.numberSessions += 1
     assert 'visitor' in result.keys()
     assert result['visitor'] == visitor
예제 #9
0
def test_updatePage(table_name, year_visits, month_visits, week_visits,
                    day_visits):
    client = DynamoClient(table_name)
    result = client.updatePage(month_visits + year_visits + month_visits +
                               week_visits + day_visits)
    assert 'page' in result.keys() and 'days' in result.keys() and \
      'weeks' in result.keys() and 'months' in result.keys() and \
      'years' in result.keys()
예제 #10
0
 def test_duplicate_session_addNewVisitor(self, table_name, visitor,
                                          browsers, visits, session):
     client = DynamoClient(table_name)
     result = client.addSession(session)
     result = client.addNewVisitor(visitor, location(), browsers, visits)
     assert 'error' in result.keys()
     assert result['error'] == 'Visitor\'s session is already in table ' + \
       f'{ session }'
예제 #11
0
def test_visitor_addNewSession(
  dynamo_client, table_init, table_name, visitor, browsers, visits
):
  client = DynamoClient( table_name )
  result = client.addNewSession(
    visitor, browsers, visits
  )
  assert 'error' in result.keys()
  assert result['error'] == 'Visitor not in table'
예제 #12
0
 def test_addNewVisitor(self, table_name, visitor, browsers, visits,
                        session):
     client = DynamoClient(table_name)
     result = client.addNewVisitor(visitor, location(), browsers, visits)
     assert 'visitor' in result.keys()
     assert result['visitor'] == visitor
     assert 'browsers' in result.keys()
     assert result['browsers'] == browsers
     assert 'location' in result.keys()
     assert dict(result['location']) == dict(location())
     assert 'visits' in result.keys()
     assert result['visits'] == visits
     assert 'session' in result.keys()
     assert dict(result['session']) == dict(session)
예제 #13
0
def test_addNewSession(dynamo_client, table_init, table_name, visitor,
                       browsers, visits):
    client = DynamoClient(table_name)
    client.addVisitor(visitor)
    result = client.addNewSession(visitor, browsers, visits)
    assert 'visitor' in result.keys()
    assert result['visitor'] == visitor
    assert 'browsers' in result.keys()
    assert result['browsers'] == browsers
    assert 'visits' in result.keys()
    assert result['visits'] == visits
    assert 'session' in result.keys()
    assert result['session'].ip == visitor.ip
    assert result['session'].sessionStart == visits[0].date
예제 #14
0
def test_parameter_title_addPage(dynamo_client, table_init, table_name,
                                 year_visits):
    with pytest.raises(ValueError) as e:
        assert DynamoClient(table_name).addPage(year_visits + [
            Visit('2020-12-23T20:32:26.000Z', '0.0.0.0', '0', 'Resume', '/',
                  '2020-12-23T20:32:26.000Z')
        ])
    assert str(e.value) == 'List of visits must have the same title'
예제 #15
0
def test_parameter_year_addWeek(dynamo_client, table_init, table_name,
                                week_visits):
    with pytest.raises(ValueError) as e:
        assert DynamoClient(table_name).addWeek(week_visits + [
            Visit('2021-12-23T20:32:26.000Z', '0.0.0.0', '0', 'Tyler Norlund',
                  '/', '2020-12-23T20:32:26.000Z')
        ])
    assert str(e.value) == 'List of visits must be from the same year and week'
예제 #16
0
def test_parameter_addBrowsers(
    dynamo_client,
    table_init,
    table_name,
):
    with pytest.raises(ValueError) as e:
        assert DynamoClient(table_name).addBrowsers({})
    assert str(e.value) == 'Must pass a list'
예제 #17
0
def test_none_updateSession(dynamo_client, table_init, table_name, browsers,
                            visits, session):
    client = DynamoClient(table_name)
    client.addBrowsers(browsers)
    client.addVisits(visits)
    result = client.updateSession(session, visits)
    assert 'error' in result.keys()
    assert result['error'] == f'Session not in table { session }'
예제 #18
0
def test_parameter_year_addMonth(
  dynamo_client, table_init, table_name, month_visits
):
  with pytest.raises( ValueError ) as e:
    assert DynamoClient( table_name ).addMonth( month_visits + [
      Visit(
        visitor_id, '2021-12-23T20:32:26.000Z', '0', 'Tyler Norlund', '/',
        '2020-12-23T20:32:26.000Z', scroll_events
      )
    ] )
  assert str( e.value ) == 'List of visits must be from the same year and month'
예제 #19
0
def test_parameter_title_addDay(
  dynamo_client, table_init, table_name, day_visits
):
  with pytest.raises( ValueError ) as e:
    assert DynamoClient( table_name ).addDay( day_visits + [
      Visit(
        visitor_id, '2020-12-23T20:32:26.000Z',  '0', 'Resume', '/',
        '2020-12-23T20:32:26.000Z', scroll_events
      )
    ] )
  assert str( e.value ) == 'List of visits must have the same title'
예제 #20
0
 def test_getVisitorDetails(self, table_name, visitor, browsers, visits):
     print('location', location())
     client = DynamoClient(table_name)
     result = client.addNewVisitor(visitor, location(), browsers, visits)
     print('result', result)
     result = client.getVisitorDetails(visitor)
     print('result', result)
     assert 'visitor' in result.keys()
     assert dict(result['visitor']) == dict(visitor)
     assert 'browsers' in result.keys()
     assert all([
         dict(result['browsers'][index]) == dict(browsers[index])
         for index in range(len(browsers))
     ])
     assert 'location' in result.keys()
     assert dict(result['location']) == dict(location())
     assert 'visits' in result.keys()
     assert all([
         dict(result['visits'][index]) == dict(visits[index])
         for index in range(len(visits))
     ])
     assert 'sessions' in result.keys()
예제 #21
0
def test_getPageDetails(table_name, year_visits, month_visits, week_visits,
                        day_visits, page):
    client = DynamoClient(table_name)
    client.addVisits(month_visits + year_visits + month_visits + week_visits +
                     day_visits)
    client.updatePage(month_visits + year_visits + month_visits + week_visits +
                      day_visits)
    result = client.getPageDetails(page)
    assert 'page' in result.keys() and 'days' in result.keys() and \
      'weeks' in result.keys() and 'months' in result.keys() and \
      'years' in result.keys()
예제 #22
0
def test_visits_processPages(table_name):
    this_event = {
        'Records': [{
            'dynamodb': {
                'NewImage': {
                    'Type': {
                        'S': 'Something'
                    }
                }
            }
        }]
    }
    client = DynamoClient(table_name)
    assert processPages(client, this_event) == 'No pages to process'
예제 #23
0
def test_getSessionDetails(dynamo_client, table_init, table_name, visitor,
                           browsers, visits, session):
    client = DynamoClient(table_name)
    client.addVisitor(visitor)
    client.addNewSession(visitor, browsers, visits)
    result = client.getSessionDetails(session)
    assert 'visits' in result.keys()
    assert all([
        dict(result['visits'][index]) == dict(visits[index])
        for index in range(len(visits))
    ])
    assert 'session' in result.keys()
    assert result['session'].ip == visitor.ip
    assert result['session'].sessionStart == visits[0].date
예제 #24
0
def test_updateSession(
  dynamo_client, table_init, table_name, visitor, browsers, visits, session,
):
  client = DynamoClient( table_name )
  client.addNewSession( visitor, browsers, visits )
  client.addSession( session )
  result = client.updateSession( session, visits )
  assert 'visits' in result.keys()
  assert all( [
    dict( result['visits'][index] ) == dict(visits[index])
    for index in range( len( visits ) )
  ] )
  assert 'session' in result.keys()
  assert dict( result['session'] ) == dict( session )
예제 #25
0
def test_listLocations(table_name):
    client = DynamoClient(table_name)
    for loc in locations():
        client.addLocation(loc)
    result = client.listLocations()
    assert len(result) == len(locations())
예제 #26
0
def test_parameter_removeLocation(table_name):
    with pytest.raises(ValueError) as e:
        assert DynamoClient(table_name).removeLocation({})
    assert str(e.value) == 'Must pass a Location object'
예제 #27
0
def test_none_removeLocation(table_name):
    result = DynamoClient(table_name).removeLocation(location())
    assert 'error' in result.keys()
    assert result['error'] == f'Location not in table { location() }'
예제 #28
0
def test_removeLocation(table_name):
    client = DynamoClient(table_name)
    client.addLocation(location())
    result = client.removeLocation(location())
    assert 'location' in result.keys()
    assert dict(result['location']) == dict(location())
예제 #29
0
def test_element_addLocations(table_name):
    with pytest.raises(ValueError) as e:
        assert DynamoClient(table_name).addLocations([None])
    assert str(e.value) == 'Must pass Location objects'
예제 #30
0
def test_addLocation(table_name):
    result = DynamoClient(table_name).addLocation(location())
    assert 'location' in result.keys()
    assert dict(result['location']) == dict(location())