Ejemplo n.º 1
0
class TestRestyRootResource(TestCase):

    def setUp(self):
        # self.patcher = patch('resty.request.urllib2.urlopen')
        self.patcher = patch('urllib2.urlopen')
        self.mock_urlopen = self.patcher.start()
        self.content = """
        {
            "userprofiles": "http://localhost/api/userprofiles/",
            "users": "http://localhost/api/users/",
            "api-token": "http://localhost/api/token/",
            "comps": "http://localhost/api/components/",
            "reporttype": "http://localhost/api/reporttypes/",
            "groups": "http://localhost/api/groups/",
            "permissions": "http://localhost/api/permissions/",
            "reportsource": "http://localhost/api/reportsources/",
            "contenttype": "http://localhost/api/contenttype/",
            "reports": "http://localhost/api/reports/",
            "workspace": "http://localhost/api/workspaces/",
            "release": "http://localhost/api/releases/"
        }
        """
        self.mock_urlopen.return_value = mock_response(self.content)
        self.api = RestyAPI(REST_URL, REST_AUTH_TOKEN)
        self.expected_resources = [
            u"userprofiles",
            u"users",
            u"api-token",
            u"comps",
            u"reporttype",
            u"groups",
            u"permissions",
            u"reportsource",
            u"contenttype",
            u"reports",
            u"workspace",
            u"release"
        ]

    # def test_api_request(self):
    #     self.assertEqual(request(REST_URL).code, 200)
    #     self.assertEqual(request(REST_URL).msg, 'OK')
    #     data = json.loads(request(REST_URL).read())
    #     self.assertEqual(data, json.loads(self.content))

    def test_api_discover(self):
        self.api.discover()
        for item in self.api.list_resources():
            # self.assertIn(item, expected_resources)
            self.assertTrue(item in self.expected_resources)
Ejemplo n.º 2
0
class TestRestyResourceInstance(TestCase):

    def setUp(self):
        # self.patcher = patch('resty.request.urllib2.urlopen')
        self.patcher = patch('urllib2.urlopen')
        self.mock_urlopen = self.patcher.start()
        self.content = """
        {
            "id": 1,
            "url": "http://localhost/api/users/1/",
            "profile": "http://localhost/api/userprofiles/1/",
            "groups": [],
            "username": "******",
            "first_name": "Tom",
            "last_name": "Sawyer",
            "email": "*****@*****.**",
            "is_staff": true,
            "is_active": true,
            "is_superuser": false,
            "last_login": "******",
            "date_joined": "2012-05-08T21:23:50Z"
        }
        """
        self.mock_urlopen.return_value = mock_response(self.content)
        self.api = RestyAPI(REST_URL, REST_AUTH_TOKEN)
        self.expected_resources = [
            u"userprofiles",
            u"users",
            u"api-token",
            u"components",
            u"reporttype",
            u"groups",
            u"permissions",
            u"reportsource",
            u"contenttype",
            u"reports",
            u"workspace",
            u"release"
        ]

    # @skip("not implemented yet")
    def test_get_one(self):
        c = self.api.resource('users')
        user = c.one(1)
Ejemplo n.º 3
0
 def setUp(self):
     # self.patcher = patch('resty.request.urllib2.urlopen')
     self.patcher = patch('urllib2.urlopen')
     self.mock_urlopen = self.patcher.start()
     self.content = """
     {
         "userprofiles": "http://localhost/api/userprofiles/",
         "users": "http://localhost/api/users/",
         "api-token": "http://localhost/api/token/",
         "comps": "http://localhost/api/components/",
         "reporttype": "http://localhost/api/reporttypes/",
         "groups": "http://localhost/api/groups/",
         "permissions": "http://localhost/api/permissions/",
         "reportsource": "http://localhost/api/reportsources/",
         "contenttype": "http://localhost/api/contenttype/",
         "reports": "http://localhost/api/reports/",
         "workspace": "http://localhost/api/workspaces/",
         "release": "http://localhost/api/releases/"
     }
     """
     self.mock_urlopen.return_value = mock_response(self.content)
     self.api = RestyAPI(REST_URL, REST_AUTH_TOKEN)
     self.expected_resources = [
         u"userprofiles",
         u"users",
         u"api-token",
         u"comps",
         u"reporttype",
         u"groups",
         u"permissions",
         u"reportsource",
         u"contenttype",
         u"reports",
         u"workspace",
         u"release"
     ]
Ejemplo n.º 4
0
 def test_ok_authclass(self):
     api = RestyAPI()
     self.assertFalse(api.auth)
     auth = RestAuthBasic('username', 'secretpw')
     api.auth = auth
     self.assertTrue(api.auth)