Ejemplo n.º 1
0
class Network(Base):
    __tablename__ = 'networks'
    __table_args__ = (
        sa.UniqueConstraint('user_id', 'name'),
    )
    id = sa.Column(sa.Integer, primary_key=True)
    name = sa.Column(sa.String(255), nullable=False)
    nickname = sa.Column(sa.String(20), nullable=False)
    hostname = sa.Column(sa.String(100), nullable=False)
    port = sa.Column(sa.Integer, nullable=False)
    realname = sa.Column(sa.String(100), nullable=False, default='')
    username = sa.Column(sa.String(50), nullable=False, default='')
    password = sa.Column(sa.String(100), nullable=False, default='')
    usermode = sa.Column(sa.String(1), nullable=False, default='0')
    ssl = sa.Column(sa.Boolean(), default=False)
    ssl_verify = sa.Column(ChoiceType(SSL_VERIFY_CHOICES),
                           default=Choice(*SSL_VERIFY_CHOICES[0]))

    access_token = sa.Column(sa.String(100), nullable=False, unique=True,
                             default=lambda context: _create_access_token(
                             context.current_parameters['user_id'],
                             context.current_parameters['name']))
    user_id = sa.Column(
        sa.Integer(), sa.ForeignKey(User.id, ondelete='CASCADE'),
        nullable=False)

    # Runtime fields
    current_nickname = sa.Column(sa.String(20), nullable=True)
    status = sa.Column(ChoiceType(NETWORK_STATUS_TYPES),
                       default=Choice(*NETWORK_STATUS_TYPES[3]))

    # Remote socket info
    rhost = sa.Column(sa.String(100), nullable=True)
    rport = sa.Column(sa.Integer(), nullable=True)

    # Local socket info
    lhost = sa.Column(sa.String(100), nullable=True)
    lport = sa.Column(sa.Integer(), nullable=True)

    # timestamps
    created = sa.Column(sa.DateTime, default=datetime.datetime.utcnow)
    last_updated = sa.Column(sa.DateTime,
                             default=datetime.datetime.utcnow)

    def create_access_token(self):
        return _create_access_token(self.user.id, self.name)

    def to_dict(self, serializable=False):
        d = super().to_dict()
        ssl_verify = self.ssl_verify and self.ssl_verify if isinstance(
            self.ssl_verify, str) else self.ssl_verify.code
        status = self.status and (
            self.status if isinstance(self.status, str) else self.status.code)
        d['ssl_verify'] = ssl_verify
        d['status'] = status
        return d
Ejemplo n.º 2
0
 def test_non_equality_operator(self):
     assert Choice(1, 1) != 2
     assert not (Choice(1, 1) != 1)
Ejemplo n.º 3
0
    'role': 'driver',
    'name': 'Tony Khoo',
    'password': '******'
}, {
    'username': '******',
    'role': 'driver',
    'name': 'Roger Shum Cheng Sean',
    'password': '******'
}]

U_all = [U_manager, *U_drivers]

D_drivers = [{
    'task_id': None,
    'name_': 'John Smith',
    'status': Choice('off', 'Off Work')
}, {
    'task_id': None,
    'name_': 'Stan Mohan',
    'status': Choice('off', 'Off Work')
}, {
    'task_id': None,
    'name_': 'Ed Hong Weiming',
    'status': Choice('off', 'Off Work')
}, {
    'task_id': None,
    'name_': 'Tony Khoo',
    'status': Choice('off', 'Off Work')
}, {
    'task_id': None,
    'name_': 'Roger Shum Cheng Sean',
Ejemplo n.º 4
0
 def test_equality_operator(self):
     assert Choice(1, 1) == 1
     assert 1 == Choice(1, 1)
     assert Choice(1, 1) == Choice(1, 1)
Ejemplo n.º 5
0
 def test_hash(self):
     assert hash(Choice(1, 1)) == hash(1)