Пример #1
0
    def test_login(self):
        expected_capabilities1 = {
            u'GetMetadata': u'http://server.rets.com/rets/GetMetadata.ashx',
            u'GetObject': u'http://server.rets.com/rets/GetObject.ashx',
            u'Login': u'http://server.rets.com/rets/Login.ashx',
            u'Logout': u'http://server.rets.com/rets/Logout.ashx',
            u'PostObject': u'http://server.rets.com/rets/PostObject.ashx',
            u'Search': u'http://server.rets.com/rets/Search.ashx',
            u'Update': u'http://server.rets.com/rets/Update.ashx'
        }

        expected_capabilities2 = {
            u'GetMetadata': u'http://server.rets.com/rets/GetMetadata.ashx',
            u'GetObject': u'http://server.rets.com/rets/GetObject.ashx',
            u'Login': u'http://server.rets.com/rets/Login.ashx',
            u'Logout': u'http://server.rets.com/rets/Logout.ashx',
            u'Search': u'http://server.rets.com/rets/Search.ashx',
        }

        with open('tests/rets_responses/Login.xml') as f:
            contents = ''.join(f.readlines())

        with open('tests/rets_responses/Logout.html') as f:
            logout_contents = ''.join(f.readlines())

        with open('tests/rets_responses/Errors/Login_no_host.xml') as f:
            no_host_contents = ''.join(f.readlines())

        with responses.RequestsMock() as resps:
            resps.add(resps.POST, 'http://server.rets.com/rets/Login.ashx',
                      body=contents, status=200)
            s = Session(login_url='http://server.rets.com/rets/Login.ashx', username='******', version='1.5')
            s.login()

            self.assertEqual(s.capabilities, expected_capabilities1)
            self.assertEquals(s.version, '1.5')

            resps.add(resps.POST, 'http://server.rets.com/rets/Login.ashx',
                      body=contents, status=200)
            resps.add(resps.POST, 'http://server.rets.com/rets/Logout.ashx',
                      body=logout_contents, status=200)
            with Session(login_url='http://server.rets.com/rets/Login.ashx', username='******', version='1.7.2') as s:
                # I logged in here and will log out when leaving context
                pass

            resps.add(resps.POST, 'http://server.rets.com/rets/Login_no_host.ashx',
                      body=no_host_contents, status=200, headers={'RETS-Version': 'RETS/1.7.2'})
            s1 = Session(login_url='http://server.rets.com/rets/Login_no_host.ashx', username='******', version='1.5')
            s1.login()

            self.assertDictEqual(s1.capabilities, expected_capabilities2)
            self.assertEquals(s.version, '1.7.2')
Пример #2
0
    def test_session(self):
        c = Configuration('1.7.2')
        c.login_url = os.environ.get("RETS_LOGIN_URL")
        c.username = os.environ.get("RETS_USERNAME")
        c.password = os.environ.get("RETS_PASSWORD")

        s = Session(c)
        self.assertIsNotNone(s)

        s.login()

        system = s.get_system_metadata()

        self.assertIsNotNone(system)
        resources = s.get_resources_metadata()

        self.assertIsNotNone(resources)

        r_classes = {}
        for r, v in resources.items():
            r_classes[r] = s.get_classes_metadata(r)
        self.assertIsNotNone(r_classes)
        objects = s.get_object(resource='Property', r_type='Photo', content_ids='2228878', object_ids='*', location=0)
        self.assertIsNotNone(objects)
        fields = s.get_table_metadata(resource_id='Property', class_id='RES')
        self.assertIsNotNone(fields)
        search_res = s.search(resource_id='Property', class_id='RES', dqml_query='(ListPrice=150000+)', optional_parameters={'Limit': 3})
        self.assertIsNotNone(search_res)
Пример #3
0
    def test_login_with_action(self):
        with open("tests/rets_responses/Login_with_Action.xml") as f:
            action_login = "".join(f.readlines())

        with open("tests/rets_responses/Action.xml") as f:
            action_response = "".join(f.readlines())

        with responses.RequestsMock() as resps:
            resps.add(
                resps.POST,
                "http://server.rets.com/rets/Login_with_Action.ashx",
                body=action_login,
                status=200,
            )
            resps.add(
                resps.GET,
                "http://server.rets.com/rets/Action.ashx",
                body=action_response,
                status=200,
            )

            s2 = Session(
                login_url="http://server.rets.com/rets/Login_with_Action.ashx",
                username="******",
                version="1.5",
            )
            s2.login()
            self.assertIn(u"Action", list(s2.capabilities.keys()))
Пример #4
0
    def setUp(self):
        super(SessionTester, self).setUp()
        with open('tests/rets_responses/Login.xml') as f:
            contents = ''.join(f.readlines())

        with responses.RequestsMock() as resps:
            resps.add(resps.POST, 'http://server.rets.com/rets/Login.ashx',
                      body=contents, status=200)
            self.session = Session(login_url='http://server.rets.com/rets/Login.ashx', username='******',
                                   version='RETS/1.7.2')
            self.session.login()
Пример #5
0
    def setUp(self):
        super(SessionTester, self).setUp()
        with open('tests/rets_responses/Login.xml') as f:
            contents = ''.join(f.readlines())

        with responses.RequestsMock() as resps:
            resps.add(resps.POST, 'http://server.rets.com/rets/Login.ashx',
                      body=contents, status=200, headers={'Set-Cookie': 'ASP.NET_SessionId=zacqcc1gjhkmazjznjmyrinq;'})
            self.session = Session(login_url='http://server.rets.com/rets/Login.ashx', username='******',
                                   version='RETS/1.7.2', session_id_cookie_name='ASP.NET_SessionId')
            self.session.login()
Пример #6
0
    def test_port_added_to_actions(self):
        with open('tests/rets_responses/Login_relative_url.xml') as f:
            contents = ''.join(f.readlines())

        with responses.RequestsMock() as resps:
            resps.add(resps.POST, 'http://server.rets.com:9999/rets/Login.ashx',
                      body=contents, status=200)
            s = Session(login_url='http://server.rets.com:9999/rets/Login.ashx', username='******', version='1.5')
            s.login()

            for cap in s.capabilities.values():
                parts = urlparse(cap)
                self.assertEqual(parts.port, 9999)
Пример #7
0
    def test_login_with_action(self):
        with open('tests/rets_responses/Login_with_Action.xml') as f:
            action_login = ''.join(f.readlines())

        with open('tests/rets_responses/Action.xml') as f:
            action_response = ''.join(f.readlines())

        with responses.RequestsMock() as resps:
            resps.add(resps.POST, 'http://server.rets.com/rets/Login_with_Action.ashx',
                      body=action_login, status=200)
            resps.add(resps.GET, 'http://server.rets.com/rets/Action.ashx',
                      body=action_response, status=200)

            s2 = Session(login_url='http://server.rets.com/rets/Login_with_Action.ashx', username='******',
                         version='1.5')
            s2.login()
            self.assertIn(u'Action', s2.capabilities.keys())
Пример #8
0
    def setUp(self):
        super(Session15Tester, self).setUp()
        with open("tests/rets_responses/Login.xml") as f:
            contents = "".join(f.readlines())

        with responses.RequestsMock() as resps:
            resps.add(
                resps.POST,
                "http://server.rets.com/rets/Login.ashx",
                body=contents,
                status=200,
            )
            self.session = Session(
                login_url="http://server.rets.com/rets/Login.ashx",
                username="******",
                version="1.5",
            )
            self.session.metadata_format = "STANDARD-XML"
            self.session.login()
Пример #9
0
    def setUp(self):
        super(SessionTester, self).setUp()
        with open("tests/rets_responses/Login.xml") as f:
            contents = "".join(f.readlines())

        with responses.RequestsMock() as resps:
            resps.add(
                resps.POST,
                "http://server.rets.com/rets/Login.ashx",
                body=contents,
                status=200,
                headers={
                    "Set-Cookie": "ASP.NET_SessionId=zacqcc1gjhkmazjznjmyrinq;"
                },
            )
            self.session = Session(
                login_url="http://server.rets.com/rets/Login.ashx",
                username="******",
                version="RETS/1.7.2",
                session_id_cookie_name="ASP.NET_SessionId",
            )
            self.session.login()
Пример #10
0
    def test_login(self):
        expected_capabilities1 = {
            u"GetMetadata": u"http://server.rets.com/rets/GetMetadata.ashx",
            u"GetObject": u"http://server.rets.com/rets/GetObject.ashx",
            u"Login": u"http://server.rets.com/rets/Login.ashx",
            u"Logout": u"http://server.rets.com/rets/Logout.ashx",
            u"PostObject": u"http://server.rets.com/rets/PostObject.ashx",
            u"Search": u"http://server.rets.com/rets/Search.ashx",
            u"Update": u"http://server.rets.com/rets/Update.ashx",
        }

        expected_capabilities2 = {
            u"GetMetadata": u"http://server.rets.com/rets/GetMetadata.ashx",
            u"GetObject": u"http://server.rets.com/rets/GetObject.ashx",
            u"Login": u"http://server.rets.com/rets/Login.ashx",
            u"Logout": u"http://server.rets.com/rets/Logout.ashx",
            u"Search": u"http://server.rets.com/rets/Search.ashx",
        }

        with open("tests/rets_responses/Login.xml") as f:
            contents = "".join(f.readlines())

        with open("tests/rets_responses/Logout.html") as f:
            logout_contents = "".join(f.readlines())

        with open("tests/rets_responses/Errors/Login_no_host.xml") as f:
            no_host_contents = "".join(f.readlines())

        with responses.RequestsMock() as resps:
            resps.add(
                resps.POST,
                "http://server.rets.com/rets/Login.ashx",
                body=contents,
                status=200,
            )
            s = Session(
                login_url="http://server.rets.com/rets/Login.ashx",
                username="******",
                version="1.5",
            )
            s.login()

            self.assertEqual(s.capabilities, expected_capabilities1)
            self.assertEquals(s.version, "1.5")

            resps.add(
                resps.POST,
                "http://server.rets.com/rets/Login.ashx",
                body=contents,
                status=200,
            )
            resps.add(
                resps.POST,
                "http://server.rets.com/rets/Logout.ashx",
                body=logout_contents,
                status=200,
            )
            with Session(
                    login_url="http://server.rets.com/rets/Login.ashx",
                    username="******",
                    version="1.7.2",
            ) as s:
                # I logged in here and will log out when leaving context
                pass

            resps.add(
                resps.POST,
                "http://server.rets.com/rets/Login_no_host.ashx",
                body=no_host_contents,
                status=200,
                headers={"RETS-Version": "RETS/1.7.2"},
            )
            s1 = Session(
                login_url="http://server.rets.com/rets/Login_no_host.ashx",
                username="******",
                version="1.5",
            )
            s1.login()

            self.assertDictEqual(s1.capabilities, expected_capabilities2)
            self.assertEquals(s.version, "1.7.2")