-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Start adding very basic tests, starting with packages API
- Loading branch information
David Moreau Simard
committed
Oct 2, 2015
1 parent
05a58b0
commit 01128c8
Showing
5 changed files
with
142 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,4 @@ | ||
sphinx | ||
sphinxcontrib-httpdomain | ||
unittest2py3k | ||
mock |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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' |