Skip to content

Commit

Permalink
Start adding very basic tests, starting with packages API
Browse files Browse the repository at this point in the history
  • Loading branch information
David Moreau Simard committed Oct 2, 2015
1 parent 05a58b0 commit 01128c8
Show file tree
Hide file tree
Showing 5 changed files with 142 additions and 0 deletions.
2 changes: 2 additions & 0 deletions test-requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
sphinx
sphinxcontrib-httpdomain
unittest2py3k
mock
1 change: 1 addition & 0 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ usedevelop = True
install_command = pip install -U {opts} {packages}
setenv = VIRTUAL_ENV={envdir}
deps = -r{toxinidir}/test-requirements.txt
commands=unit2-3.4 discover []

[testenv:pep8]
commands = flake8 versiontracker
Expand Down
Empty file.
43 changes: 43 additions & 0 deletions versiontracker/tests/api/test-packages.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# Copyright Red Hat, Inc. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.

import io
import mock
import unittest

from versiontracker.tests import fakes
from versiontracker.api.packages import _fetch_base_urls


@mock.patch('versiontracker.api.packages._url_as_ini_file')
class TestFetchBaseUrls(unittest.TestCase):
def test_parse_repo_file_with_one_repo(self, _url_mock):
fake_inifile = io.StringIO(fakes.REPO_CONFIG_ONE)
fake_inifile.seek(0)
_url_mock.return_value = fake_inifile
expected_base_url = [('repo-one',
'http://example.org/one/x86_64/packages')]
base_url = _fetch_base_urls('repo-one')
self.assertEquals(expected_base_url, base_url)

def test_parse_repo_file_with_n_repo(self, _url_mock):
fake_inifile = io.StringIO(fakes.TWO_REPO_CONFIGS)
fake_inifile.seek(0)
_url_mock.return_value = fake_inifile
expected_base_url = [('repo-one',
'http://example.org/one/x86_64/packages'),
('repo-two',
'http://example.org/two/x86_64/packages')]
base_url = _fetch_base_urls('two-repo-configs')
self.assertEquals(expected_base_url, base_url)
96 changes: 96 additions & 0 deletions versiontracker/tests/fakes.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
# Copyright Red Hat, Inc. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.

import collections

REPO_CONFIG_ONE = """
[repo-one]
name=repo-one
baseurl=http://example.org/one/x86_64/packages
enabled=1
gpgcheck=0
priority=1
"""

REPO_CONFIG_TWO = """
[repo-two]
name=repo-two
baseurl=http://example.org/two/x86_64/packages
enabled=1
gpgcheck=0
priority=1
"""

TWO_REPO_CONFIGS = REPO_CONFIG_ONE + REPO_CONFIG_TWO

class FakeSettings(object):
def __init__(self):
self.REPOSITORIES = collections.OrderedDict({
'repo-one': {
'name': 'repo-one',
'friendly_name': 'Repo One',
'url': 'http://example.org/one/x86_64.repo'
},
'repo-two': {
'name': 'repo-two',
'friendly_name': 'Repo Two',
'url': 'http://example.org/two/x86_64.repo'
}
})
self.TAGS = collections.OrderedDict({
'repo': {
'name': 'repo',
'friendly_name': 'Repositories'
}
})
self.PACKAGE_PROPERTIES = ['arch', 'buildtime', 'name', 'release',
'version']

self.TMP_DIR = '/tmp/'


class FakePackageOne(object):
def __init__(self):
self.arch = 'x86_64'
self.buildtime = 946684800
self.name = 'fake-package-one'
self.release = 'foo'
self.version = '0.1'


class FakeDifferentPackageOne(object):
def __init__(self):
self.arch = 'x86_64'
self.buildtime = 946684800
self.name = 'fake-package-one'
self.release = 'foo'
self.version = '1.0'


class FakePackageTwo(object):
def __init__(self):
self.arch = 'x86_64'
self.buildtime = 946684800
self.name = 'fake-package-two'
self.release = 'foo'
self.version = '0.2'


class FakePackageThree(object):
def __init__(self):
self.arch = 'x86_64'
self.buildtime = 946684800
self.name = 'fake-package-three'
self.release = 'foo'
self.version = '3.0'

0 comments on commit 01128c8

Please sign in to comment.