File: test_validation.py

package info (click to toggle)
devpi-common 3.2.2-1.1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 248 kB
  • sloc: python: 1,552; makefile: 4
file content (23 lines) | stat: -rw-r--r-- 732 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
from devpi_common.validation import normalize_name, validate_metadata
import pytest


def names(*args):
    return pytest.mark.parametrize("name", args)


@names("hello-xyz", "hello_xyz", "hello.xyz", "Hello.XYZ", "Hello___XYZ")
def test_safe_name(name):
    assert normalize_name(name) == "hello-xyz"


class TestValidateMetadata:
    @names("hello", "hello-xyz", "hello1-xyz", "hello_xyz")
    def test_valid_names(self, name):
        validate_metadata(data=dict(name=name, version="1.0"))

    @names("hello_", "hello-", "-hello", "_hello1", "hel%lo",
           "hello#", "hello<",)
    def test_invalid(self, name):
        pytest.raises(ValueError, lambda:
            validate_metadata(data=dict(name=name, version="1.0")))