예제 #1
0
    def setUp(self):
        self.processor = processor(requestsGenerator)

        self.manager = Mock()
        self.manager.name = "account"
        self.processor.manager = self.manager

        self.response = Response("", Request({}, {}, ""))
    def setUp(self):
        self.processor = processor(requestsGenerator)

        self.manager = Mock()
        self.manager.name = "list"
        self.manager.manage.return_value = []
        self.processor.manager = self.manager

        self.new_response = Response("", Request({"id": 1, "login": "******", "password": "******"}, {}, ""))
예제 #3
0
    def setUp(self):
        self.processor = processor(requestsGenerator)

        self.manager = Mock()
        self.manager.name = "session"
        self.processor.manager = self.manager

        self.response = Response(
            "", Request({}, {
                "type": "session",
                "user_id": 1
            }, ""))
예제 #4
0
 def get_account(self, request):
     if request.account["type"] == "account" or request.account[
             "type"] == "admin":
         taken_response = self.processors["account"].process(
             Response(
                 "new",
                 Request({"type": "internal"}, {
                     "type": "account",
                     "login": request.account["login"],
                     "password": request.account["password"]
                 }, "get")))
         request.account = taken_response.result["objects"][0]
     elif request.account["type"] == "session":
         taken_response = self.processors["account"].process(
             Response(
                 "new",
                 Request({"type": "internal"}, {
                     "type": "account",
                     "id": request.account["user_id"]
                 }, "get")))
         request.account = taken_response.result["objects"][0]
     return request
예제 #5
0
    def verify_account(self, response_account):
        if response_account["type"] == "anonymous":
            return True

        elif response_account["type"] == "account" or response_account[
                "type"] == "admin":
            account_response = Response(
                "new",
                Request({"type": "internal"}, {
                    "type": "account",
                    "login": response_account["login"],
                    "password": response_account["password"]
                }, "get"))
            accounts = self.processors["account"].process(
                account_response).result["objects"]
            if len(accounts) == 1:
                if response_account["type"] == "account":
                    return True

                elif response_account["type"] == "admin":
                    if accounts[0]["account_type"] == "admin":
                        return True

        elif response_account["type"] == "session":
            session_response = Response(
                "new",
                Request({"type": "internal"}, {
                    "type": "session",
                    "user_id": response_account["user_id"]
                }, "get"))
            sessions = self.processors["session"].process(
                session_response).result["objects"]
            keys = [session["key"] for session in sessions]
            if response_account["key"] in keys:
                return True

        return False
예제 #6
0
    def setUp(self):
        self.guard = guard()

        self.response = Response("new", Request({}, {}, ""))
    def setUp(self):
        self.processor = processor()

        self.response = Response("", Request({}, {}, ""))
    def test_response(self):
        response = Response("new", self.request)

        self.assertEqual("new", response.status)
        self.assertEqual(self.request, response.request)
        self.assertEqual({}, response.result)