Beispiel #1
0
    def test_search_fields(self):
        """Test whether the search_fields is properly set"""

        setup_http_server()

        forge = PuppetForge(max_items=2)
        modules = [module for module in forge.fetch()]

        module = modules[0]
        self.assertEqual(forge.metadata_id(module['data']), module['search_fields']['item_id'])
        self.assertEqual(module['data']['module_group'], 'base')
        self.assertEqual(module['data']['module_group'], module['search_fields']['module_group'])
        self.assertEqual(module['data']['slug'], 'norisnetwork-ceph')
        self.assertEqual(module['data']['slug'], module['search_fields']['slug'])

        module = modules[1]
        self.assertEqual(forge.metadata_id(module['data']), module['search_fields']['item_id'])
        self.assertEqual(module['data']['module_group'], 'base')
        self.assertEqual(module['data']['module_group'], module['search_fields']['module_group'])
        self.assertEqual(module['data']['slug'], 'sshuyskiy-nomad')
        self.assertEqual(module['data']['slug'], module['search_fields']['slug'])

        module = modules[2]
        self.assertEqual(forge.metadata_id(module['data']), module['search_fields']['item_id'])
        self.assertEqual(module['data']['module_group'], 'base')
        self.assertEqual(module['data']['module_group'], module['search_fields']['module_group'])
        self.assertEqual(module['data']['slug'], 'sshuyskiy-consul')
        self.assertEqual(module['data']['slug'], module['search_fields']['slug'])
Beispiel #2
0
    def test_fetch(self):
        """Test whether it fetches a set of modules"""

        http_requests = setup_http_server()

        forge = PuppetForge(max_items=2)
        modules = [module for module in forge.fetch(from_date=None)]

        expected = [('ceph', 'a7709201e03bfec46e34e4d0065bb8bdc3f4e5b9',
                     1484906394.0, 2, 'noris network AG'),
                    ('nomad', '2fea1072d8ef4d107839c20b7d9926574c4df587',
                     1484896006.0, 1, 'sshuyskiy'),
                    ('consul', '234b9505bf47f2f48f8576a9a906732fe6c06e3c',
                     1484895908.0, 0, 'sshuyskiy')]

        self.assertEqual(len(modules), len(expected))

        for x in range(len(modules)):
            module = modules[x]
            expc = expected[x]
            self.assertEqual(module['data']['name'], expc[0])
            self.assertEqual(module['uuid'], expc[1])
            self.assertEqual(module['origin'], 'https://forge.puppet.com/')
            self.assertEqual(module['updated_on'], expc[2])
            self.assertEqual(module['category'], 'module')
            self.assertEqual(module['tag'], 'https://forge.puppet.com/')
            self.assertEqual(len(module['data']['releases']), expc[3])
            self.assertEqual(module['data']['owner_data']['display_name'],
                             expc[4])

        # Check requests
        expected = [{
            'limit': ['2'],
            'sort_by': ['latest_release']
        }, {
            'limit': ['2'],
            'module': ['norisnetwork-ceph'],
            'show_deleted': ['true'],
            'sort_by': ['release_date']
        }, {}, {
            'limit': ['2'],
            'module': ['sshuyskiy-nomad'],
            'show_deleted': ['true'],
            'sort_by': ['release_date']
        }, {}, {
            'limit': ['2'],
            'offset': ['2'],
            'sort_by': ['latest_release']
        }, {
            'limit': ['2'],
            'module': ['sshuyskiy-consul'],
            'show_deleted': ['true'],
            'sort_by': ['release_date']
        }]

        self.assertEqual(len(http_requests), len(expected))

        for i in range(len(expected)):
            self.assertDictEqual(http_requests[i].querystring, expected[i])
    def test_fetch_from_date(self):
        """Test whether if fetches a set of modules from the given date"""

        http_requests = setup_http_server()

        from_date = datetime.datetime(2017, 1, 20, 8, 0, 0)

        forge = PuppetForge(max_items=2)
        modules = [module for module in forge.fetch(from_date=from_date)]

        expected = [('ceph', 'a7709201e03bfec46e34e4d0065bb8bdc3f4e5b9', 1484906394.0, 2, 'noris network AG')]

        self.assertEqual(len(modules), len(expected))

        for x in range(len(modules)):
            module = modules[x]
            expc = expected[x]
            self.assertEqual(module['data']['name'], expc[0])
            self.assertEqual(module['uuid'], expc[1])
            self.assertEqual(module['origin'], 'https://forge.puppet.com/')
            self.assertEqual(module['updated_on'], expc[2])
            self.assertEqual(module['category'], 'module')
            self.assertEqual(module['tag'], 'https://forge.puppet.com/')
            self.assertEqual(len(module['data']['releases']), expc[3])
            self.assertEqual(module['data']['owner_data']['display_name'], expc[4])

        # Check requests
        expected = [
            {
                'limit': ['2'],
                'sort_by': ['latest_release']
            },
            {
                'limit': ['2'],
                'module': ['norisnetwork-ceph'],
                'show_deleted': ['true'],
                'sort_by': ['release_date']
            },
            {}
        ]

        self.assertEqual(len(http_requests), len(expected))

        for i in range(len(expected)):
            self.assertDictEqual(http_requests[i].querystring, expected[i])
Beispiel #4
0
    def test_fetch_empty(self):
        """Test if nothing is returned when there are no modules"""

        http_requests = setup_http_server()

        from_date = datetime.datetime(2017, 1, 21)

        forge = PuppetForge(max_items=2)
        modules = [module for module in forge.fetch(from_date=from_date)]

        self.assertEqual(len(modules), 0)

        # Check requests
        expected = [{'limit': ['2'], 'sort_by': ['latest_release']}]

        self.assertEqual(len(http_requests), len(expected))

        for i in range(len(expected)):
            self.assertDictEqual(http_requests[i].querystring, expected[i])