예제 #1
0
    def test_regular(self):
        target = Target()
        target.collection = Mock()
        actual = target.insert(
            "entities_value",
            "locale_value",
            "new_context_id_value",
            "application_id_value",
            "session_id",
            "user_id",
            datetime(2000, 1, 1)
        )

        self.assertDictEqual(
            {'_rev': 'new_context_id_value', '_id': 'new_context_id_value'},
            actual
        )

        self.assertEqual(1, target.collection.insert.call_count)
        self.assertDictEqual(
            {
                '_id': 'new_context_id_value',
                'created': '2000-01-01T00:00:00',
                'entities': 'entities_value',
                'locale': 'locale_value',
                'session_id': 'session_id',
                'application_id': 'application_id_value',
                'user_id': 'user_id',
                '_rev': 'new_context_id_value',
                'version': "0.0.3"
            },
            target.collection.insert.call_args_list[0][0][0]
        )
예제 #2
0
    def test_none_user_id(self):
        target = Target()
        target.collection = Mock()
        actual = target.insert("entities_value", "locale_value",
                               "new_context_id_value", "application_id_value",
                               "session_id", None, datetime(2000, 1, 1))

        self.assertDictEqual(
            {
                '_rev': 'new_context_id_value',
                '_id': 'new_context_id_value'
            }, actual)

        self.assertEqual(1, target.collection.insert.call_count)
        self.assertDictEqual(
            {
                '_id': 'new_context_id_value',
                'created': '2000-01-01T00:00:00',
                'entities': 'entities_value',
                'locale': 'locale_value',
                'session_id': 'session_id',
                'application_id': 'application_id_value',
                '_rev': 'new_context_id_value',
                'version': '0.0.3'
            }, target.collection.insert.call_args_list[0][0][0])
예제 #3
0
    def test_entities_none(self):
        target = Target()
        target.collection = Mock()
        actual = target.update(
            "context_id_value",
            "new_ver_id_value",
            entities=None,
            now=datetime(2000, 1, 1)
        )

        self.assertEqual(
            "new_ver_id_value",
            actual
        )

        self.assertEqual(1, target.collection.update.call_count)
        self.assertDictEqual(
            {
                '_id': 'context_id_value'
            },
            target.collection.update.call_args_list[0][0][0]
        )
        self.assertDictEqual(
            {
                '$set': {
                    '_rev': 'new_ver_id_value',
                    'updated': '2000-01-01T00:00:00',
                    'unsupported_entities': {}
                }
            },
            target.collection.update.call_args_list[0][0][1]
        )
예제 #4
0
 def initialize(self, contextualizer: Contextualizer):
     self.contextualizer = contextualizer
     from context.data.context import Context
     self.context_data = Context()
     self.context_data.open_connection()
     self.param_extractor = ParamExtractor(self)
     self.path_extractor = PathExtractor(self)
예제 #5
0
    def test_regular(self):
        target = Target()
        target.collection = Mock()
        target.collection.find.return_value = ["first", "second"].__iter__()
        actual = target.get("_id_value", "_ver_value")

        self.assertEqual("first", actual)

        self.assertEqual(1, target.collection.find.call_count)
        self.assertDictEqual({'_id': '_id_value'},
                             target.collection.find.call_args_list[0][0][0])
예제 #6
0
    def test_regular(self):
        target = Target()
        target.collection = Mock()
        target.collection.find.return_value = ["first", "second"].__iter__()
        actual = target.get("_id_value", "_ver_value")

        self.assertEqual("first", actual)

        self.assertEqual(1, target.collection.find.call_count)
        self.assertDictEqual(
            {'_id': '_id_value'},
            target.collection.find.call_args_list[0][0][0]
        )
예제 #7
0
파일: context.py 프로젝트: rdefeo/context
class Context(RequestHandler):
    context_data = None
    contextualizer = None
    param_extractor = None
    path_extractor = None

    def initialize(self, contextualizer: Contextualizer):
        self.contextualizer = contextualizer
        from context.data.context import Context
        self.context_data = Context()
        self.context_data.open_connection()
        self.param_extractor = ParamExtractor(self)
        self.path_extractor = PathExtractor(self)

    def data_received(self, chunk):
        pass

    def on_finish(self):
        pass

    @asynchronous
    def get(self, context_id, *args, **kwargs):
        self.set_status(200)
        self.set_header('Content-Type', 'application/json')

        # hours = 600
        # self.set_header('Cache-Control', 'public,max-age=%d' % int(3600*hours))
        self.finish(
            dumps(
                self.context_data.get(self.path_extractor.context_id(context_id), self.param_extractor.rev())
            )
        )

    @asynchronous
    def post(self, *args, **kwargs):
        new_context_id = ObjectId()
        self.contextualizer.create(
            new_context_id,
            self.param_extractor.user_id(),
            self.param_extractor.application_id(),
            self.param_extractor.session_id(),
            self.param_extractor.locale()
        )

        self.set_header('Content-Type', 'application/json')
        self.add_header("Location", "/%s" % str(new_context_id))
        self.add_header("_id", str(new_context_id))
        self.add_header("_rev", str(new_context_id))
        self.set_status(201)
        self.finish()
예제 #8
0
class Context(RequestHandler):
    context_data = None
    contextualizer = None
    param_extractor = None
    path_extractor = None

    def initialize(self, contextualizer: Contextualizer):
        self.contextualizer = contextualizer
        from context.data.context import Context
        self.context_data = Context()
        self.context_data.open_connection()
        self.param_extractor = ParamExtractor(self)
        self.path_extractor = PathExtractor(self)

    def data_received(self, chunk):
        pass

    def on_finish(self):
        pass

    @asynchronous
    def get(self, context_id, *args, **kwargs):
        self.set_status(200)
        self.set_header('Content-Type', 'application/json')

        # hours = 600
        # self.set_header('Cache-Control', 'public,max-age=%d' % int(3600*hours))
        self.finish(
            dumps(
                self.context_data.get(
                    self.path_extractor.context_id(context_id),
                    self.param_extractor.rev())))

    @asynchronous
    def post(self, *args, **kwargs):
        new_context_id = ObjectId()
        self.contextualizer.create(new_context_id,
                                   self.param_extractor.user_id(),
                                   self.param_extractor.application_id(),
                                   self.param_extractor.session_id(),
                                   self.param_extractor.locale())

        self.set_header('Content-Type', 'application/json')
        self.add_header("Location", "/%s" % str(new_context_id))
        self.add_header("_id", str(new_context_id))
        self.add_header("_rev", str(new_context_id))
        self.set_status(201)
        self.finish()
예제 #9
0
파일: context.py 프로젝트: rdefeo/context
 def initialize(self, contextualizer: Contextualizer):
     self.contextualizer = contextualizer
     from context.data.context import Context
     self.context_data = Context()
     self.context_data.open_connection()
     self.param_extractor = ParamExtractor(self)
     self.path_extractor = PathExtractor(self)
예제 #10
0
    def test_entities_none(self):
        target = Target()
        target.collection = Mock()
        actual = target.update("context_id_value",
                               "new_ver_id_value",
                               entities=None,
                               now=datetime(2000, 1, 1))

        self.assertEqual("new_ver_id_value", actual)

        self.assertEqual(1, target.collection.update.call_count)
        self.assertDictEqual({'_id': 'context_id_value'},
                             target.collection.update.call_args_list[0][0][0])
        self.assertDictEqual(
            {
                '$set': {
                    '_rev': 'new_ver_id_value',
                    'updated': '2000-01-01T00:00:00',
                    'unsupported_entities': {}
                }
            }, target.collection.update.call_args_list[0][0][1])