示例#1
0
def device_with_invalid_member(faker, sample_device: Device):
    yield Device(
        id=sample_device.id,
        mac=sample_device.mac,
        adherent_id=faker.random_digit_not_null(),
        type=DeviceType.wired.value,
        ip=sample_device.ip,
        ipv6=sample_device.ipv6,
    )
示例#2
0
def unknown_device(faker, sample_member):
    yield Device(
        id=faker.random_digit_not_null(),
        mac=faker.mac_address(),
        adherent_id=sample_member.id,
        type=DeviceType.wired.value,
        ip=faker.ipv4_public(),
        ipv6=faker.ipv6(),
    )
示例#3
0
def custom_device(sample_member3):
    yield Device(
        id=42,
        mac='96-24-F6-D0-48-A7',
        adherent_id=sample_member3.id,
        type=DeviceType.wired.value,
        ip='157.159.1.1',
        ipv6='::1',
    )
示例#4
0
def wireless_device(faker, sample_member):
    yield Device(
        id=faker.random_digit_not_null(),
        mac=faker.mac_address(),
        adherent_id=sample_member.id,
        type=DeviceType.wireless.value,
        ip=faker.ipv4_private(),
        ipv6=faker.ipv6(),
    )
示例#5
0
def test_device_filter_hit_limit(client, sample_member: Adherent):
    s = db.session()
    LIMIT = 10

    # Create a lot of devices
    for _ in range(LIMIT * 2):
        suffix = "{0:04X}"
        dev = Device(
            adherent_id=sample_member.id,
            mac='00-00-00-00-' + suffix[:2] + "-" + suffix[2:],
            type=DeviceType.wired.value,
            ip="127.0.0.1",
            ipv6="::1",
        )
        s.add(dev)
    s.commit()

    r = client.get(
        f'{base_url}?limit={LIMIT}',
        headers=TEST_HEADERS,
    )
    assert r.status_code == 200
    response = json.loads(r.data.decode('utf-8'))
    assert len(response) == LIMIT
示例#6
0
文件: manage.py 项目: minet/adh6
def fake(login):
    """Add dummy data to the database."""
    fake = Faker()
    session: Session = db.session

    import datetime as dt

    now = datetime.now()
    adherent = Adherent(
        nom=fake.last_name_nonbinary(),
        prenom=fake.first_name_nonbinary(),
        mail=fake.email(),
        login=login,
        ldap_login=login,
        password="",
        chambre_id=1,
        datesignedminet=now,
        date_de_depart=now + dt.timedelta(days=365),
        subnet="10.0.42.0/28",
        ip="157.159.192.2"
    )

    session.add(adherent)
    session.flush()

    account = Account(
        type=2,
        name=adherent.nom + " " + adherent.prenom,
        actif=True,
        compte_courant=False,
        pinned=False,
        adherent_id=adherent.id
    )

    session.add(account)
    session.flush()

    membership = Membership(
        uuid=str(uuid.uuid4),
        account_id=account.id,
        adherent_id=adherent.id,
        payment_method_id=3,
        has_room=True,
        first_time=True,
        products="",
        update_at=datetime.now(),
        create_at=datetime.now(),
        status=MembershipStatus.COMPLETE.value,
        duration=MembershipDuration.ONE_YEAR.value
    )

    session.add(membership)
    session.flush()

    session.add(Transaction(
        value=9,
        timestamp=now,
        src=account.id,
        dst=2,
        name="Internet - 1 an",
        attachments="",
        type=3,
        author_id=1,
        pending_validation=False,
    ))
    session.add(Transaction(
        value=41,
        timestamp=now,
        src=account.id,
        dst=1,
        name="Internet - 1 an",
        attachments="",
        type=3,
        author_id=1,
        pending_validation=False,
    ))
    
    for _ in range(1, 4):
        session.add(Device(
            mac=fake.mac_address(),
            ip=None,
            adherent_id=adherent.id,
            ipv6=None,
            type=0
        ))
    for _ in range(1, 4):
        session.add(Device(
            mac=fake.mac_address(),
            ip=None,
            adherent_id=adherent.id,
            ipv6=None,
            type=1
        ))
    session.commit()