Esempio n. 1
0
    def test_get_repositories(self, mock_rcu_query, mock_repository_query):
        c1 = model.RepositoryContentUnit(repo_id='repo1')
        c2 = model.RepositoryContentUnit(repo_id='repo2')

        mock_rcu_query.return_value = [c1, c2]
        mock_repository_query.return_value = ['apples']

        unit = ContentUnitHelper(id='foo_id')

        self.assertEquals(unit.get_repositories(), ['apples'])

        mock_rcu_query.assert_called_once_with(unit_id='foo_id')
        mock_repository_query.assert_called_once_with(repo_id__in=['repo1', 'repo2'])
    def test_migration_duplicate_unit(self, mock_modules, mock_dist,
                                      mock_association, mock_controller,
                                      mock_repo, mock_open):
        module_foo = Module(name='kung-foo', version='0.1.2', author='kung')
        module_bar = Module(name='foo', version='0.1.2', author='kung')
        module_bar.first = Mock()
        mock_modules.filter.side_effect = ([module_foo], module_bar)
        module_foo.save = Mock()
        module_foo.save.side_effect = NotUniqueError()
        repo_association = model.RepositoryContentUnit(
            repo_id='test_repo', unit_type_id='puppet_module', unit_id='bar')
        test_repo = model.Repository(repo_id='test_repo')
        mock_repo.get_repo_or_missing_resource.return_value = test_repo
        mock_association.filter.return_value = [repo_association]

        migration.migrate()

        module_foo.save.assert_called_once_with()
        mock_association.filter.assert_called_once_with(unit_id=module_foo.id)
        mock_modules.filter.assert_called_with(name='foo')
        mock_controller.disassociate_units.assert_called_once_with(
            repo_association, [module_foo])
        mock_repo.get_repo_or_missing_resource.assert_called_once_with(
            'test_repo')
        mock_controller.rebuild_content_unit_counts.assert_called_once_with(
            test_repo)
Esempio n. 3
0
    def test_limit(self, mock_get_model, mock_demo_objects, mock_rcu_objects):
        """
        Test that limits are applied properly to the results
        """
        repo = MagicMock(repo_id='foo')
        rcu_list = []
        unit_list = []
        for i in range(10):
            unit_id = 'bar_%i' % i
            unit_key = 'key_%i' % i
            rcu = model.RepositoryContentUnit(repo_id='foo',
                                              unit_type_id='demo_model',
                                              unit_id=unit_id)
            rcu_list.append(rcu)
            unit_list.append(DemoModel(id=unit_id, key_field=unit_key))

        mock_rcu_objects.return_value = rcu_list

        mock_get_model.return_value = DemoModel
        mock_demo_objects.return_value = unit_list
        result = list(repo_controller.find_repo_content_units(repo, limit=5))

        self.assertEquals(5, len(result))
        self.assertEquals(result[0].unit_id, 'bar_0')
        self.assertEquals(result[4].unit_id, 'bar_4')
Esempio n. 4
0
    def test_content_units_query_test(self, mock_get_model, mock_demo_objects, mock_rcu_objects):
        """
        Test the query parameters for the ContentUnit
        """
        repo = MagicMock(repo_id='foo')
        test_unit = DemoModel(id='bar', key_field='baz')
        test_rcu = model.RepositoryContentUnit(repo_id='foo',
                                               unit_type_id='demo_model',
                                               unit_id='bar')
        mock_rcu_objects.return_value = [test_rcu]

        u_filter = mongoengine.Q(key_field='baz')
        u_fields = ['key_field']
        mock_get_model.return_value = DemoModel
        mock_demo_objects.return_value.only.return_value = [test_unit]
        result = list(repo_controller.find_repo_content_units(repo, units_q=u_filter,
                                                              unit_fields=u_fields))

        mock_demo_objects.return_value.only.assert_called_once_with(['key_field'])

        # validate that the repo content unit was returned and that the unit is attached
        self.assertEquals(result, [test_rcu])
        self.assertEquals(result[0].unit, test_unit)
Esempio n. 5
0
 def test_model_superclass(self):
     sample_model = model.RepositoryContentUnit()
     self.assertTrue(isinstance(sample_model, Document))