test_official_provider.py 2.21 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
import pytest

from sqlalchemy.exc import IntegrityError

from aurweb.db import create
from aurweb.models.official_provider import OfficialProvider
from aurweb.testing import setup_test_db


@pytest.fixture(autouse=True)
def setup():
    setup_test_db("OfficialProviders")


def test_official_provider_creation():
    oprovider = create(OfficialProvider,
                       Name="some-name",
                       Repo="some-repo",
                       Provides="some-provides")
    assert bool(oprovider.ID)
    assert oprovider.Name == "some-name"
    assert oprovider.Repo == "some-repo"
    assert oprovider.Provides == "some-provides"


def test_official_provider_cs():
    """ Test case sensitivity of the database table. """
    oprovider = create(OfficialProvider,
                       Name="some-name",
                       Repo="some-repo",
                       Provides="some-provides")
    assert bool(oprovider.ID)

    oprovider_cs = create(OfficialProvider,
                          Name="SOME-NAME",
                          Repo="SOME-REPO",
                          Provides="SOME-PROVIDES")
    assert bool(oprovider_cs.ID)

    assert oprovider.ID != oprovider_cs.ID

    assert oprovider.Name == "some-name"
    assert oprovider.Repo == "some-repo"
    assert oprovider.Provides == "some-provides"

    assert oprovider_cs.Name == "SOME-NAME"
    assert oprovider_cs.Repo == "SOME-REPO"
    assert oprovider_cs.Provides == "SOME-PROVIDES"


def test_official_provider_null_name_raises_exception():
    from aurweb.db import session
    with pytest.raises(IntegrityError):
        create(OfficialProvider,
               Repo="some-repo",
               Provides="some-provides")
    session.rollback()


def test_official_provider_null_repo_raises_exception():
    from aurweb.db import session
    with pytest.raises(IntegrityError):
        create(OfficialProvider,
               Name="some-name",
               Provides="some-provides")
    session.rollback()


def test_official_provider_null_provides_raises_exception():
    from aurweb.db import session
    with pytest.raises(IntegrityError):
        create(OfficialProvider,
               Name="some-name",
               Repo="some-repo")
    session.rollback()