示例#1
0
    def test_remaining_connections(self):
        """A user has a count of its remaining available connections."""
        user = self.make_user()
        InviteFactory(from_user=user)
        InviteFactory(from_user=user, status=Invite.InviteStatus.ACCEPTED)

        assert user.remaining_connections == 499
示例#2
0
    def test_accept(self):
        """An invite can be accepted."""
        invite = InviteFactory()

        invite.accept()

        assert invite.status == Invite.InviteStatus.ACCEPTED
示例#3
0
    def test_reject(self):
        """An invite can be rejected."""
        invite = InviteFactory()

        invite.reject()

        assert invite.status == Invite.InviteStatus.REJECTED
示例#4
0
    def test_send(self):
        """A sent invite sends email, records the timestamp, and sets the status."""
        invite = InviteFactory()

        invite.send()

        # TODO: Assert that email is sent.
        assert invite.sent_at is not None
        assert invite.status == Invite.InviteStatus.SENT
示例#5
0
    def test_factory(self):
        invite = InviteFactory()

        assert invite.created_at is not None
        assert invite.sent_at is None
        assert invite.from_user is not None
        assert invite.to_user is not None
        assert invite.status == Invite.InviteStatus.PENDING
示例#6
0
    def test_max_connections_accepted_invite(self, mock_users_constants):
        """An accepted invite does not count against the max connections total."""
        mock_users_constants.MAX_USER_CONNECTIONS = 1
        from_user = UserFactory()
        to_user = UserFactory()
        InviteFactory(from_user=from_user, status=Invite.InviteStatus.ACCEPTED)
        data = {"from_user": str(from_user.id), "to_user": str(to_user.id)}
        form = SendInviteForm(data=data)

        is_valid = form.is_valid()

        assert is_valid
示例#7
0
    def test_invite_exists(self):
        """An existing invite is an error."""
        invite = InviteFactory()
        data = {
            "from_user": str(invite.from_user.id),
            "to_user": str(invite.to_user.id),
        }
        form = SendInviteForm(data=data)

        is_valid = form.is_valid()

        assert not is_valid
        assert "You have already sent an invitation." in form.non_field_errors()
示例#8
0
    def test_bulk_expire(self):
        """Old invites are expired."""
        now = timezone.now()
        the_past = now - datetime.timedelta(days=1)
        invite = InviteFactory(status=Invite.InviteStatus.SENT,
                               sent_at=the_past)
        accepted_invite = InviteFactory(status=Invite.InviteStatus.ACCEPTED,
                                        sent_at=the_past)

        Invite.bulk_expire(now)

        invite.refresh_from_db()
        assert invite.status == Invite.InviteStatus.EXPIRED
        accepted_invite.refresh_from_db()
        assert accepted_invite.status == Invite.InviteStatus.ACCEPTED
示例#9
0
    def test_in_flight_invites(self, mock_constants):
        """The user can't submit more than the max in flight."""
        mock_constants.MAX_IN_FLIGHT_INVITES = 1
        from_user = self.make_user()
        to_user = UserFactory()
        InviteFactory(from_user=from_user)
        data = {"from_user": str(from_user.id), "to_user": str(to_user.id)}
        form = SendInviteForm(data=data)

        is_valid = form.is_valid()

        assert not is_valid
        assert ("You have too many sent invitations out currently."
                in form.non_field_errors())
示例#10
0
    def test_max_connections(self, mock_users_constants):
        """A user may not send any invites when they are at their max connections."""
        mock_users_constants.MAX_USER_CONNECTIONS = 1
        from_user = UserFactory()
        to_user = UserFactory()
        InviteFactory(from_user=from_user)
        data = {"from_user": str(from_user.id), "to_user": str(to_user.id)}
        form = SendInviteForm(data=data)

        is_valid = form.is_valid()

        assert not is_valid
        assert ("You are at your maximum number of connections."
                in form.non_field_errors())