Browse Source

Merge branch 'simple-database-test' into 'master'

Add some simple database tests against SQLite

See merge request ftp-team/dak!93
devuan-devel
Joerg Jaspert 2 years ago
parent
commit
269dd15da9
5 changed files with 134 additions and 2 deletions
  1. +44
    -0
      daklib/conftest.py
  2. +2
    -1
      daklib/database/architecture.py
  3. +44
    -0
      daklib/database/test_architecture.py
  4. +43
    -0
      daklib/database/test_section.py
  5. +1
    -1
      debian/rules

+ 44
- 0
daklib/conftest.py View File

@@ -0,0 +1,44 @@
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.

# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.

# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA

################################################################################

import pytest
from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker

from daklib.database.all import Base


Session = sessionmaker()


@pytest.fixture(scope='session')
def engine():
engine = create_engine('sqlite://', echo=True)
Base.metadata.create_all(engine)
return engine


@pytest.yield_fixture
def session(engine):
connection = engine.connect()
trans = connection.begin()
session = Session(bind=connection)

yield session

session.close()
trans.rollback()
connection.close()

+ 2
- 1
daklib/database/architecture.py View File

@@ -30,8 +30,9 @@ class Architecture(BaseTimestamp):
# indexes where not created as constraints, need to do as well
__table_args__ = (Index('architecture_arch_string_key', 'arch_string', unique=True), )

def __init__(self, arch_string=None):
def __init__(self, arch_string=None, description=None):
self.arch_string = arch_string
self.description = description

def __str__(self):
return self.arch_string


+ 44
- 0
daklib/database/test_architecture.py View File

@@ -0,0 +1,44 @@
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.

# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.

# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA

################################################################################

import pytest

from .architecture import Architecture


def test_Architecture(session):
obj = Architecture('arch', 'description')
session.add(obj)
session.flush()

get = Architecture.get(1, session)
assert get
assert get.arch_string == 'arch'
assert get.description == 'description'


def test_Architecture___eq__():
obj = Architecture('arch')

assert obj == 'arch'
assert 'arch' == obj


def test_Architecture___ne__():
obj = Architecture('arch')

assert obj != 'zzzz'
assert 'zzzz' != obj

+ 43
- 0
daklib/database/test_section.py View File

@@ -0,0 +1,43 @@
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.

# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.

# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA

################################################################################

import pytest

from .section import Section


def test_Section(session):
obj = Section('section')
session.add(obj)
session.flush()

get = Section.get(1, session)
assert get
assert get.section == 'section'


def test_Section___eq__():
obj = Section('section')

assert obj == 'section'
assert 'section' == obj


def test_Section___ne__():
obj = Section('section')

assert obj != 'zzzz'
assert 'zzzz' != obj

+ 1
- 1
debian/rules View File

@@ -14,7 +14,7 @@ ifneq ($(JENKINS_EXPORTS_DIR),)
endif
mkdir -p debian/test-gnupghome
make -C tests/fixtures/packages
GNUPGHOME=$$(pwd)/debian/test-gnupghome py.test -v tests $(PYBUILD_EXTRA_ARGS)
GNUPGHOME=$$(pwd)/debian/test-gnupghome py.test -v daklib tests $(PYBUILD_EXTRA_ARGS)
./integration-tests/run-tests
endif



Loading…
Cancel
Save