Skip to content

Commit

Permalink
fix bug that was causing user_domain_id to not be unique for each user
Browse files Browse the repository at this point in the history
  • Loading branch information
andresionek91 committed Jul 22, 2020
1 parent a0be814 commit 6f45776
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 5 deletions.
2 changes: 1 addition & 1 deletion fake_web_events/event.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class Event(WeightedRandom):
def __init__(self, current_timestamp: datetime, user: User, batch_size: int):
self.previous_page = None
self.current_page = self.select('landing_pages')
self.user = user.asdict()
self.user = user
self.batch_size = batch_size
self.current_timestamp = self.randomize_timestamp(current_timestamp)
self.is_new_page = True
Expand Down
4 changes: 2 additions & 2 deletions fake_web_events/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,10 +155,10 @@ def __init__(self, size: int):

def populate_pool(self):
logging.info('Creating UserPool. This might take a while depending on your pool size.')
for idx in range(self.size):
for idx in range(1, self.size + 1):
if idx % 100 == 0:
logging.info(f'{idx} users created.')
self.pool.append(User())
self.pool.append(User().asdict())

def __repr__(self) -> str:
return repr(self.pool)
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

setup(
name='fake_web_events',
version='0.2.2',
version='0.2.3',
description='Generator of semi-random fake web events. ',
long_description=long_description,
long_description_content_type='text/markdown',
Expand Down
6 changes: 6 additions & 0 deletions tests/test_simulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,9 @@ def test_get_rate_per_step(self, mock_simulation):

def test_update(self, mock_simulation, mock_update):
assert mock_simulation.get_len_sessions() == 4

def test_max_unique_user_ids(self, mock_simulation):
# after running the simulation for some time, the max unique user ids must be equal to the pool size
events = list(mock_simulation.run(2))
user_domain_ids = set(event['user_domain_id'] for event in events)
assert len(user_domain_ids) == 10
2 changes: 1 addition & 1 deletion tests/test_user.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ def test_pool_size(self, mock_user_pool):
assert len(mock_user_pool.pool) == 10

def test_get_user(self, mock_user_pool):
assert isinstance(mock_user_pool.get_user(), User)
assert isinstance(mock_user_pool.get_user(), dict)

def test_pool_size_after_getting_user(self, mock_user_pool):
mock_user_pool.get_user()
Expand Down

0 comments on commit 6f45776

Please sign in to comment.