예제 #1
0
    def test_get_by_id(self):
        """Get key by ID."""
        application = Application(name=fake.word(),
                                  support_message=fake.sentence()).save()
        num_days = "15"
        key = Key(token=fake.word(),
                  remaining=randint(-1, 50),
                  app_id=application.id,
                  enabled=True,
                  memo=fake.sentence(),
                  hwid=fake.mac_address(),
                  expiry_date=("%s" % num_days)).save()

        retrieved = Key.get_by_id(key.id)
        assert retrieved == key
        retrieved = Key.get_by_uuid(key.uuid)
        assert retrieved == key
예제 #2
0
    def test_get_by_id(self):
        """Get application by ID."""
        application = Application(name=fake.word(),
                                  support_message=fake.sentence()).save()

        retrieved = Application.get_by_id(application.id)
        assert retrieved == application
        retrieved = Application.get_by_uuid(application.uuid)
        assert retrieved == application
예제 #3
0
 def test_application_through_key(self):
     """test the relationship of key.app"""
     application = Application(name=fake.word(),
                               support_message=fake.sentence()).save()
     num_days = "15"
     key1 = Key(token=fake.word(),
                remaining=randint(-1, 50),
                app_id=application.id,
                enabled=True,
                memo=fake.sentence(),
                hwid=fake.mac_address(),
                expiry_date="15").save()
     key2 = Key(token=fake.word(),
                remaining=randint(-1, 50),
                app_id=application.id,
                enabled=True,
                memo=fake.sentence(),
                hwid=fake.mac_address(),
                expiry_date="2020-12-25").save()
     assert key1.app == key2.app == application
예제 #4
0
    def test_key_expiry_date(self):
        """test that a key is only valid for a period of time"""
        application = Application(name=fake.word(),
                                  support_message=fake.sentence()).save()
        num_days = "15"
        key1 = Key(token=fake.word(),
                   remaining=randint(-1, 50),
                   app_id=application.id,
                   enabled=True,
                   memo=fake.sentence(),
                   hwid=fake.mac_address(),
                   expiry_date=("%s" % num_days)).save()
        key2 = Key(token=fake.word(),
                   remaining=randint(-1, 50),
                   app_id=application.id,
                   enabled=True,
                   memo=fake.sentence(),
                   hwid=fake.mac_address(),
                   expiry_date="2020-12-25").save()

        assert key1.valid_until <= dt.datetime.utcnow() + dt.timedelta(
            days=int(num_days))
        assert key2.valid_until == dt.datetime.combine(dt.date(2020, 12, 25),
                                                       dt.datetime.min.time())
예제 #5
0
def test_filename_extractor_with_invalid_system():
    filenames = [fake.linux_filename() for _ in range(3)]
    _paragraph = fake.paragraph_with_salt(filenames)
    with pytest.raises(ValueError):
        assert extractors.filename(_paragraph, system=fake.word())
예제 #6
0
def test_datetime_format_with_datetime_format_invalid_fmt():
    value = fake.iso8601()
    with pytest.raises(ValueError):
        assert extractors.datetime(value, fmt=fake.word())
예제 #7
0
def test_number_credit_card_with_host_invalid():
    value = fake.credit_card_number()
    with pytest.raises(ValueError):
        assert extractors.credit_card(value, host=fake.word())
예제 #8
0
def test_filename_validator_with_invalid_system():
    value = fake.linux_filename()
    with pytest.raises(ValueError):
        assert validators.filename(value, system=fake.word())