class TestMultiplayer(BaseTestCase):
    inviter_number = os.environ.get('TEST_FROM_NUMBER')
    secondary_number = os.environ.get('TEST_TO_NUMBER')

    def setUp(self):
        super().setUp()

        self.mitch = AppUser(phone_number=self.inviter_number,
                             username='******',
                             timezone=US_TIMEZONES['b'])
        self.db.session.add(self.mitch)

        self.billy = AppUser(phone_number=self.secondary_number,
                             username='******',
                             timezone=US_TIMEZONES['b'])
        self.db.session.add(self.billy)

        self.team = Team(founder=self.mitch, name='The Cherrys')
        self.db.session.add(self.team)

        self.mitch_member = TeamMember(user=self.mitch,
                                       team=self.team,
                                       inviter=self.mitch,
                                       status=Statuses.ACTIVE)
        self.db.session.add(self.mitch_member)

        self.billy_member = TeamMember(user=self.billy,
                                       team=self.team,
                                       inviter=self.mitch,
                                       status=Statuses.PENDING)
        self.db.session.add(self.billy_member)

        self.db.session.commit()

        self.mitch = self.mitch.to_dict()
        self.billy = self.billy.to_dict()
        self.team = self.team.to_dict()

    def test_leave_team(self):
        valid_inbound = self.team['id']
        invalid_inbound = '999'
        # test correct team id, and incorrect team id
        multiplayer.leave_team(self.mitch, valid_inbound)

        self.assertRaises(NoResultFound, multiplayer.leave_team, self.mitch,
                          invalid_inbound)

    def test_join_team_existing_user(self):
        '''Test the ability to join a team as an existing user'''
        member = multiplayer.respond_to_invite(self.billy, 'yes')

        assert member.status == Statuses.ACTIVE
Beispiel #2
0
def query_user_with_number(phone_number):
    '''
    use phone number to find user in db, else add to db
    returns the user object
    '''

    user = db.session.query(AppUser).filter(
        AppUser.phone_number == phone_number).first()

    if user is not None:
        return user.to_dict()
    else:
        new_user = AppUser(phone_number=phone_number)
        db.session.add(new_user)
        db.session.commit()

        new_user = new_user.to_dict()
        insert_notifications(new_user)

        return new_user
Beispiel #3
0
class TestSettings(BaseTestCase):
    inviter_number = os.environ.get('TEST_FROM_NUMBER')
    due_date = dt.datetime.now() + dt.timedelta(days=1)
    description = "Do my laundry"

    def setUp(self):
        super().setUp()

        self.mitch = AppUser(phone_number=self.inviter_number,
                             username='******',
                             timezone=US_TIMEZONES['a'])
        self.db.session.add(self.mitch)

        self.exchange = Exchange(router=RouterNames.DID_YOU_DO_IT,
                                 outbound='Did you do it?',
                                 user=self.mitch)
        self.db.session.add(self.exchange)

        self.task = Task(description=self.description,
                         due_date=self.due_date,
                         active=True,
                         user=self.mitch,
                         exchange=self.exchange)
        self.db.session.add(self.task)

        self.db.session.commit()

        self.mitch = self.mitch.to_dict()

    def test_update_timezone(self):
        '''test that when you update timezone, the due date on the task gets updated correctly'''
        valid_inbound = 'd'

        settings.update_timezone(valid_inbound, self.mitch)

        expected_due_date = self.due_date - dt.timedelta(hours=3)

        task = self.db.session.query(Task).filter(
            Task.description == self.description).one()

        assert task.due_date == expected_due_date
Beispiel #4
0
class TestSolo(BaseTestCase):
    inviter_number = os.environ.get('TEST_FROM_NUMBER')

    def setUp(self):
        super().setUp()

        now = dt.datetime.now()

        self.mitch = AppUser(phone_number=self.inviter_number,
                             username='******',
                             timezone=US_TIMEZONES['b'])
        self.db.session.add(self.mitch)

        self.exchange = Exchange(router=RouterNames.DID_YOU_DO_IT,
                                 user=self.mitch)
        self.db.session.add(self.exchange)

        self.task1 = Task(description='clean',
                          due_date=now - dt.timedelta(days=6),
                          active=True,
                          user=self.mitch,
                          exchange=self.exchange)
        self.db.session.add(self.task1)

        self.task2 = Task(description='cook',
                          due_date=now - dt.timedelta(days=8),
                          active=True,
                          user=self.mitch,
                          exchange=self.exchange)
        self.db.session.add(self.task2)

        self.db.session.commit()

        self.mitch = self.mitch.to_dict()

    def test_get_past_tasks(self):
        '''assert that tasks from the past week only get queried'''
        tasks = solo.get_past_tasks(self.mitch)

        assert len(tasks) == 1
class TestMultiplayer(BaseTestCase):
    inviter_number = os.environ.get('TEST_FROM_NUMBER')
    secondary_number = os.environ.get('TEST_TO_NUMBER')
    third_number = os.environ.get('EXTRA_NUMBER_1')
    fourth_number = os.environ.get('EXTRA_NUMBER_2')
    fifth_number = os.environ.get('EXTRA_NUMBER_3')
    sixth_number = os.environ.get('EXTRA_NUMBER_4')

    def setUp(self):
        super().setUp()

        self.mitch = AppUser(
            phone_number=self.inviter_number, 
            username='******',
            timezone=US_TIMEZONES['b'])
        self.db.session.add(self.mitch)

        self.billy = AppUser(
            phone_number=self.secondary_number, 
            username='******',
            timezone=US_TIMEZONES['b'])
        self.db.session.add(self.billy)

        self.jonah = AppUser(
            phone_number=self.third_number, 
            username='******',
            timezone=US_TIMEZONES['b'])
        self.db.session.add(self.jonah)

        self.allie = AppUser(
            phone_number=self.fourth_number, 
            username='******',
            timezone=US_TIMEZONES['b'])
        self.db.session.add(self.allie)

        self.winnie = AppUser(
            phone_number=self.fifth_number, 
            username='******',
            timezone=US_TIMEZONES['b'])
        self.db.session.add(self.winnie)

        self.full_team = Team(
            founder = self.mitch,
            name = 'The Fulls')
        self.db.session.add(self.full_team)

        self.open_team = Team(
            founder = self.mitch,
            name = 'The Opens')
        self.db.session.add(self.open_team)

        self.mitch_member = TeamMember(
            user = self.mitch,
            team = self.full_team,
            inviter = self.mitch,
            status = Statuses.ACTIVE)       
        self.db.session.add(self.mitch_member)

        self.mitch_member_2 = TeamMember(
            user = self.mitch,
            team = self.open_team,
            inviter = self.mitch,
            status = Statuses.ACTIVE)       
        self.db.session.add(self.mitch_member_2)

        self.billy_member = TeamMember(
            user = self.billy,
            team = self.full_team,
            inviter = self.mitch,
            status = Statuses.ACTIVE)       
        self.db.session.add(self.billy_member)

        self.jonah_member = TeamMember(
            user = self.jonah,
            team = self.full_team,
            inviter = self.mitch,
            status = Statuses.ACTIVE)       
        self.db.session.add(self.jonah_member)

        self.allie_member = TeamMember(
            user = self.allie,
            team = self.full_team,
            inviter = self.mitch,
            status = Statuses.ACTIVE)       
        self.db.session.add(self.allie_member)

        self.winnie_member = TeamMember(
            user = self.winnie,
            team = self.full_team,
            inviter = self.mitch,
            status = Statuses.ACTIVE)       
        self.db.session.add(self.winnie_member)

        self.db.session.commit()

        self.mitch = self.mitch.to_dict()
        self.billy = self.billy.to_dict()
    

    def test_team_full(self):
        '''raise error if user selects a team that is already full'''
        inbound = (self.full_team.id, self.sixth_number)

        self.assertRaises(
            AssertionError,
            multiplayer.insert_member,
            self.mitch, 
            inbound, 
            InitOnboardingInvited, 
            YouWereInvited)

    def test_team_open(self):
        '''allow invitee to be added to an open team'''
        inbound = (self.open_team.id, self.sixth_number)
        multiplayer.insert_member(
            self.mitch, 
            inbound, 
            InitOnboardingInvited, 
            YouWereInvited)
    
    def test_get_open_teams(self):
        '''assert that there is only one open team'''
        teams = multiplayer.get_open_teams(self.mitch)
        assert len(teams) == 1
    
    def test_str_open_teams(self):
        '''make sure the func runs'''
        result = multiplayer.str_open_teams(self.mitch)
        print(result)