16ccbf82e9b0b313485ab957c37e4167f351b817
[archive/20170607/tools/tic-core.git] / test / test_repodata.py
1 #!/usr/bin/python
2 # Copyright (c) 2000 - 2016 Samsung Electronics Co., Ltd. All rights reserved.
3 #
4 # Contact: 
5 # @author Chulwoo Shin <cw1.shin@samsung.com>
6
7 # Licensed under the Apache License, Version 2.0 (the "License");
8 # you may not use this file except in compliance with the License.
9 # You may obtain a copy of the License at
10 #
11 # http://www.apache.org/licenses/LICENSE-2.0
12 #
13 # Unless required by applicable law or agreed to in writing, software
14 # distributed under the License is distributed on an "AS IS" BASIS,
15 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 # See the License for the specific language governing permissions and
17 # limitations under the License.
18 #
19 # Contributors:
20 # - S-Core Co., Ltd
21
22 import os
23 import base64
24 import unittest
25
26 from tic.repo import Repo
27 from tic.repo import get_repodata_from_repos
28
29 CWD = os.path.dirname(__file__) or '.'
30 TEST_REPODATA_LOC=os.path.join(CWD, 'dependency_fixtures')
31 DEFAULT_CACHEDIR='/var/tmp/tic-core/cached'
32
33 def suite():
34     return unittest.makeSuite(RepodataTest)
35
36 class RepodataTest(unittest.TestCase):
37     def setUp(self):
38         # test environment setup
39         self.local_repo = ['file:/' + TEST_REPODATA_LOC + '/base',
40                            'file:/' + TEST_REPODATA_LOC + '/mobile']
41         
42         self.remote_repo = ['http://download.tizen.org/snapshots/tizen/base/latest/repos/arm64/packages', 
43                             'http://download.tizen.org/snapshots/tizen/mobile/latest/repos/arm64-wayland/packages']
44
45     def tearDown(self):
46         # clear environment after test 
47         del self.local_repo
48         del self.remote_repo
49
50     def test_local_repodata(self):
51         repos = []
52         for repo_url in self.local_repo:
53             repos.append(Repo(base64.urlsafe_b64encode(repo_url), repo_url))
54         repodata_list = get_repodata_from_repos(repos, DEFAULT_CACHEDIR)
55         
56         for repo_info in repodata_list: 
57             self.assertNotEqual(repo_info, None)
58             self.assertNotEqual(repo_info.get('repomd'), None)
59             self.assertNotEqual(repo_info.get('primary'), None)
60             if not os.path.exists(repo_info.get('repomd')):
61                 raise self.failureException
62             if not os.path.exists(repo_info.get('primary')):
63                 raise self.failureException
64     
65     def test_remote_repodata(self):
66         repos = []
67         for repo_url in self.remote_repo:
68             repos.append(Repo(base64.urlsafe_b64encode(repo_url), repo_url))
69         repodata_list = get_repodata_from_repos(repos, DEFAULT_CACHEDIR)
70         
71         for repo_info in repodata_list: 
72             self.assertNotEqual(repo_info, None)
73             self.assertNotEqual(repo_info.get('repomd'), None)
74             self.assertNotEqual(repo_info.get('primary'), None)
75             if not os.path.exists(repo_info.get('repomd')):
76                 raise self.failureException
77             if not os.path.exists(repo_info.get('primary')):
78                 raise self.failureException
79     
80 if __name__ == "__main__":
81     #import sys;sys.argv = ['', 'Test.testName']
82     unittest.main()