Exemplo n.º 1
0
    def test_method_get_instance(self):
        """User instance get single user by primary key"""

        user = User.get(TEST_USERNAME)

        # make sure one user is returned
        self.assertIsInstance(user, User)
Exemplo n.º 2
0
    def test_method_get_instance(self):
        """User instance get single user by primary key"""

        user = User.get(TEST_USERNAME)

        # make sure one user is returned
        self.assertIsInstance(user, User)
Exemplo n.º 3
0
    def validate(self):

        if not self._message:
            raise ActionError("Message can not be empty.")

        try:
            self._sender = User.current()
        except UserError:
            raise ActionError("Could not identify current user.")

        # get ooto notification recipients from the configs
        ptask_area = PTaskArea.current()
        ooto_config = ptask_area.config(
            OOTO_CONFIG_PATH,
            composite_ancestors=True,
            composite_method="append",
        )

        ooto_notify = ooto_config.get('notify', [])
        self._to.extend(ooto_notify)

        # for all usernames specified, make sure they're a valid user,
        # get their email addresses.
        recipients = set()
        for recipient in self._to:
            
            # assume already a valid email address
            if "@" in recipient:
                recipients.add(recipient)
            else:
                try:
                    recipient = User.get(recipient)
                except UserError:
                    raise ActionError(
                        "Could not identify user: "******"\n\nCurrent ptask: {p}".format(p=ptask_area.spec)
        self._message += "\n\n- {s}".format(s=self._sender.full_name)

        self._subject = "OOTO: {fn} ({un})".format(
            fn=self.sender.full_name,
            un=self.sender.username,
        )
Exemplo n.º 4
0
    def validate(self):

        if not self._message:
            raise ActionError("Message can not be empty.")

        try:
            self._sender = User.current()
        except UserError:
            raise ActionError("Could not identify current user.")

        # get ooto notification recipients from the configs
        ptask_area = PTaskArea.current()
        ooto_config = ptask_area.config(
            OOTO_CONFIG_PATH,
            composite_ancestors=True,
            composite_method="append",
        )

        ooto_notify = ooto_config.get('notify', [])
        self._to.extend(ooto_notify)

        # for all usernames specified, make sure they're a valid user,
        # get their email addresses.
        recipients = set()
        for recipient in self._to:
            
            # assume already a valid email address
            if "@" in recipient:
                recipients.add(recipient)
            else:
                try:
                    recipient = User.get(recipient)
                except UserError:
                    raise ActionError(
                        "Could not identify user: "******"\n\nCurrent ptask: {p}".format(p=ptask_area.spec)
        self._message += "\n\n- {s}".format(s=self._sender.full_name)

        self._subject = "OOTO: {fn} ({un})".format(
            fn=self.sender.full_name,
            un=self.sender.username,
        )
Exemplo n.º 5
0
def emails_from_unames(unames):

    emails = set()

    for uname in unames:
            
        # assume already a valid email address
        if "@" in uname:
            emails.add(uname)
        else:
            try:
                user = User.get(uname)
            except UserError:
                raise NotificationError("Could not identify user: " + str(uname))
            else:
                emails.add(user.email)

    return list(emails)
Exemplo n.º 6
0
def emails_from_unames(unames):

    emails = set()

    for uname in unames:

        # assume already a valid email address
        if "@" in uname:
            emails.add(uname)
        else:
            try:
                user = User.get(uname)
            except UserError:
                raise NotificationError("Could not identify user: " +
                                        str(uname))
            else:
                emails.add(user.email)

    return list(emails)
Exemplo n.º 7
0
    def execute(self):

        try:
            user = User.get(self.username)
        except UserError:
            self.logger.error(
                'Could not determine user from: "{u}"'.format(u=self.username)
            )
            raise

        # output headers. reused while defining the look of the output
        username = '******'
        last_name = 'Last'
        first_name = 'First'
        email = 'Email'
        active = 'Active'

        # define the look of the output
        output = Output()
        # defining the data headers
        output.header_names = [username, email]
        output.add_item(
            {
                username: user.username,
                email: user.email,
            },
            color_all=Style.bright,
        )
        
        # build the title
        title = " {u.first_name} {u.last_name}".format(u=user)
        if not user.is_active:
            title += " [INACTIVE]"
        title += " "
        output.title = title

        # dump the output as a list of key/value pairs
        output.dump()
Exemplo n.º 8
0
    def execute(self):

        try:
            user = User.get(self.username)
        except UserError:
            self.logger.error(
                'Could not determine user from: "{u}"'.format(u=self.username))
            raise

        # output headers. reused while defining the look of the output
        username = '******'
        last_name = 'Last'
        first_name = 'First'
        email = 'Email'
        active = 'Active'

        # define the look of the output
        output = Output()
        # defining the data headers
        output.header_names = [username, email]
        output.add_item(
            {
                username: user.username,
                email: user.email,
            },
            color_all=Style.bright,
        )

        # build the title
        title = " {u.first_name} {u.last_name}".format(u=user)
        if not user.is_active:
            title += " [INACTIVE]"
        title += " "
        output.title = title

        # dump the output as a list of key/value pairs
        output.dump()
Exemplo n.º 9
0
 def user(self):
     """:returns: a User object for the user assigned to the ptask."""
     return User.get(self.user_username)
Exemplo n.º 10
0
 def creator(self):
     """:returns: a User object for the creator of this ptask."""
     return User.get(self.creator_username)
Exemplo n.º 11
0
 def creator(self):
     """:returns: a User object for the creator of this ptask."""
     return User.get(self.creator_username)
Exemplo n.º 12
0
 def setUp(self):
     """Get a new user object for each test."""
     self.user = User.get(TEST_USERNAME)
Exemplo n.º 13
0
 def creator(self):
     return User.get(self.creator_username)
Exemplo n.º 14
0
 def creator(self):
     return User.get(self.creator_username)
Exemplo n.º 15
0
 def setUp(self):
     """Get a new user object for each test."""
     self.user = User.get(TEST_USERNAME)
Exemplo n.º 16
0
 def user(self):
     """:returns: a User object for the user assigned to the ptask."""
     return User.get(self.user_username)