def test_set_vote(self): from pointing_poker.aws.repositories import sessions create_sessions_table(boto3.resource('dynamodb')) repo = sessions.SessionsDynamoDBRepo() session = session_factory() repo.create(session) participant = models.Participant(id=str(uuid4()), name='John', isModerator=True, vote=models.Vote(points=0, abstained=True)) repo.add_participant(session.id, participant) repo.set_vote(session.id, participant.id, models.Vote(points=5, abstained=False)) participant = repo.get_participant_in_session(session.id, participant.id) self.assertEqual(participant.vote.points, 5) self.assertEqual(participant.vote.abstained, False)
def create_session( self, description: models.SessionDescription, moderator: models.ParticipantDescription) -> models.Session: session = models.Session( id=str(uuid4()), name=description.name, pointingMax=description.pointingMax, pointingMin=description.pointingMin, votingStarted=False, expiration=86400, # 24 hours in seconds participants=[], createdAt=str(datetime.utcnow())) session.participants.append( models.Participant( id=str(uuid4()), name=moderator.name, isModerator=True, vote=models.Vote(0, True), )) self.repo.create(session) self.repo.add_participant(session.id, session.participants[0]) return session
def test_remove_participant(self): from pointing_poker.aws.repositories import sessions table = create_sessions_table(boto3.resource('dynamodb')) repo = sessions.SessionsDynamoDBRepo() participant = models.Participant(id=str(uuid4()), name='John', isModerator=True, vote=models.Vote(points=0, abstained=True)) session_id = str(uuid4()) table.put_item( Item={ 'sessionID': str(session_id), 'id': participant.id, 'name': participant.name, 'isModerator': participant.isModerator }) repo.remove_participant(session_id, participant.id) record = table.get_item(Key={ 'sessionID': session_id, 'id': participant.id }) self.assertNotIn('Item', record)
def test_add_participant_conflicts(self): from pointing_poker.aws.repositories import sessions create_sessions_table(boto3.resource('dynamodb')) repo = sessions.SessionsDynamoDBRepo() session = session_factory() repo.create(session) participant = models.Participant(id=str(uuid4()), name='John', isModerator=True, vote=models.Vote(points=0, abstained=True)) repo.add_participant(session.id, participant) try: repo.add_participant(session.id, participant) except Exception as err: self.assertEqual( err.args[0], f"participant with id {participant.id} already exists")
def test_add_participant(self): from pointing_poker.aws.repositories import sessions table = create_sessions_table(boto3.resource('dynamodb')) repo = sessions.SessionsDynamoDBRepo() session = session_factory() repo.create(session) participant = models.Participant(id=str(uuid4()), name='John', isModerator=True, vote=models.Vote(points=0, abstained=True)) repo.add_participant(session.id, participant) record = table.get_item(Key={ 'sessionID': session.id, 'id': participant.id }) self.assertEqual(record['Item']['id'], participant.id) self.assertEqual(record['Item']['name'], participant.name) self.assertEqual(record['Item']['isModerator'], participant.isModerator)
def get_participant(self, user_id: str): records = self.table.query( IndexName='id-index', KeyConditionExpression=Key('id').eq(user_id)) items = records['Items'] if not items: return None item = items[0] return models.Participant(id=item['id'], name=item['name'], isModerator=item['isModerator'], vote=models.Vote( points=item['points'], abstained=item['abstained']))
def get_participant_in_session( self, session_id: str, participant_id: str) -> Union[models.Participant, None]: record = self.table.get_item(Key={ 'sessionID': session_id, 'id': participant_id, }) if 'Item' not in record: return None item = record['Item'] return models.Participant(id=item['id'], name=item['name'], isModerator=item['isModerator'], vote=models.Vote( points=item['points'], abstained=item['abstained']))
def get(self, session_id: str) -> Union[models.Session, None]: records = self.table.query( KeyConditionExpression=Key('sessionID').eq(session_id)) items = records['Items'] if not items: return None participants = [ models.Participant(id=item['id'], name=item['name'], isModerator=item['isModerator'], vote=models.Vote(points=item['points'], abstained=item['abstained'])) for item in items if item['type'] == 'participant' ] session_item = [item for item in items if item['type'] == 'session'][0] session = models.Session(id=session_item['sessionID'], name=session_item['name'], createdAt=session_item['createdAt'], pointingMax=session_item['pointingMax'], pointingMin=session_item['pointingMin'], expiration=session_item['expiration'], votingStarted=session_item['votingStarted'], participants=participants) if any(key in session_item for key in [ 'reviewingIssueTitle', 'reviewingIssueDescription', 'reviewingIssueURL' ]): session.reviewingIssue = models.ReviewingIssue( title=session_item.get('reviewingIssueTitle'), description=session_item.get('reviewingIssueDescription'), url=session_item.get('reviewingIssueURL'), ) return session
def test_get_session_with_participants(self): from pointing_poker.aws.repositories import sessions create_sessions_table(boto3.resource('dynamodb')) repo = sessions.SessionsDynamoDBRepo() session = session_factory() repo.create(session) participant = models.Participant(id=str(uuid4()), name='John', isModerator=True, vote=models.Vote(points=0, abstained=True)) repo.add_participant(session.id, participant) session = repo.get(session.id) self.assertIn(participant, session.participants)
def join_session( self, session_id: str, participant_description: models.ParticipantDescription ) -> models.Session: participant_description.id = str( UUID(participant_description.id, version=4)) session: models.Session = self.repo.get(session_id) if session is None: raise Exception(f"session with id {session_id} not found") participant = models.Participant(id=participant_description.id, name=participant_description.name, isModerator=False, vote=models.Vote(points=0, abstained=True)) self.repo.add_participant(session_id, participant) session.participants.append(participant) return session