예제 #1
0
    def test_gets_correct_collection(self, mock_get_collection):
        """
        make sure this operation uses the correct collection
        """
        utils.get([])

        mock_get_collection.assert_called_once_with()
예제 #2
0
    def test_gets_correct_collection(self, mock_get_collection):
        """
        make sure this operation uses the correct collection
        """
        utils.get([])

        mock_get_collection.assert_called_once_with()
예제 #3
0
    def _get(self, schedule_id, resource_href):
        """
        Gets and returns a schedule by ID, in dict form suitable for json serialization and
        end-user presentation.

        :param resource_href: href of the schedule
        :type  resource_href: str
        :param schedule_id: unique ID of a schedule
        :type  schedule_id: basestring

        :return:    dictionary representing the schedule
        :rtype:     dict

        :raise pulp.server.exceptions.MissingResource: if schedule is not found
        """

        # If schedule_id is not a valid bson ObjectId, this will raise InvalidValue. If the
        # schedule_id is a valid bson ObjectId but doesn't exist it will raise StopIteration.
        # Either should be a 404.
        try:
            schedule = next(iter(schedule_utils.get([schedule_id])))
        except (StopIteration, pulp_exceptions.InvalidValue):
            raise pulp_exceptions.MissingResource(schedule_id=schedule_id)

        ret = schedule.for_display()
        ret['_href'] = resource_href
        return generate_json_response(ret)
예제 #4
0
    def test_empty_result(self, mock_query):
        mock_query.return_value = []

        ret = list(utils.get([self.schedule_id1, self.schedule_id2]))

        self.assertEqual(mock_query.call_count, 1)

        self.assertEqual(len(ret), 0)
예제 #5
0
    def test_empty_result(self, mock_query):
        mock_query.return_value = []

        ret = list(utils.get([self.schedule_id1, self.schedule_id2]))

        self.assertEqual(mock_query.call_count, 1)

        self.assertEqual(len(ret), 0)
예제 #6
0
파일: test_utils.py 프로젝트: aweiteka/pulp
    def test_query(self, mock_query):
        mock_query.return_value = SCHEDULES

        ret = list(utils.get([self.schedule_id1, self.schedule_id2]))

        self.assertEqual(mock_query.call_count, 1)
        # there should only be 1 argument, a criteria
        self.assertEqual(len(mock_query.call_args[0]), 1)
        criteria = mock_query.call_args[0][0]
        self.assertTrue(isinstance(criteria, Criteria))
        self.assertEqual(criteria.filters, {'_id': {'$in': [ObjectId(self.schedule_id1), ObjectId(self.schedule_id2)]}})

        # three instances of ScheduledCall should be returned
        self.assertEqual(len(ret), 3)
        for schedule in ret:
            self.assertTrue(isinstance(schedule, ScheduledCall))
예제 #7
0
파일: schedule.py 프로젝트: omps/pulp
    def _get(self, schedule_id):
        """
        Gets and returns a schedule by ID, in dict form suitable for json
        serialization and end-user presentation. Raises MissingResource if the
        schedule is not found.

        :param schedule_id: unique ID of a schedule
        :type  schedule_id: basestring

        :return:    dictionary representing the schedule
        :rtype:     dict

        :raise: pulp.server.exceptions.MissingResource
        """
        try:
            schedule = next(iter(utils.get([schedule_id])))
        except StopIteration:
            raise exceptions.MissingResource(schedule_id=schedule_id)

        ret = schedule.for_display()
        ret.update(serialization.link.current_link_obj())
        return self.ok(ret)