Пример #1
0
    def test_assign(self):
        """ PUT /groups/id/users assign users """

        mock = MockUtils.create_mock_response(status_code=204, data=None)

        employee1 = Employee(firstname=u"Steven", lastname=u"Gerrard")
        employee2 = Employee(firstname=u"Gerrard", lastname=u"Lampard")

        with patch('requests.request', mock):
            (objects, connection) = self.group.assign([employee1, employee2], Employee)

        method = MockUtils.get_mock_parameter(mock, 'method')
        url = MockUtils.get_mock_parameter(mock, 'url')
        headers = MockUtils.get_mock_parameter(mock, 'headers')

        self.assertEqual(connection.response.status_code, 204)
        self.assertEqual(url, 'https://vsd:8443/api/v3_2/groups/' + self.group.id + '/users')
        self.assertEqual(method, 'PUT')
        self.assertEqual(headers['Authorization'], 'XREST dXNlcjo1MWYzMTA0Mi1iMDQ3LTQ4Y2EtYTg4Yi02ODM2ODYwOGUzZGE=')
        self.assertEqual(headers['X-Nuage-Organization'], 'enterprise')
        self.assertEqual(headers['Content-Type'], 'application/json')

        self.assertEqual(objects, [employee1, employee2])
        self.assertEqual(self.group.employees, [employee1, employee2])
        self.group.employees.flush()
Пример #2
0
    def test_delete(self):
        """ DELETE /enterprises delete enterprise """

        mock = MockUtils.create_mock_response(status_code=204,
                                              data=self.enterprise)

        with patch('requests.Session.request', mock):
            (obj, connection) = self.enterprise.delete(response_choice=1)

        method = MockUtils.get_mock_parameter(mock, 'method')
        url = MockUtils.get_mock_parameter(mock, 'url')
        headers = MockUtils.get_mock_parameter(mock, 'headers')

        self.assertEqual(
            url, 'https://vsd:8443/api/v3_2/enterprises/%s?responseChoice=1' %
            self.enterprise.id)
        self.assertEqual(method, 'DELETE')
        self.assertEqual(
            headers['Authorization'],
            'XREST dXNlcjo1MWYzMTA0Mi1iMDQ3LTQ4Y2EtYTg4Yi02ODM2ODYwOGUzZGE=')
        self.assertEqual(headers['X-Nuage-Organization'], 'enterprise')
        self.assertEqual(headers['Content-Type'], 'application/json')

        self.assertEqual(obj.name, self.enterprise.name)
        self.assertEqual(obj.id, self.enterprise.id)
        self.assertEqual(connection.response.status_code, 204)
Пример #3
0
    def test_fetch_all(self):
        """ GET /enterprises fetch all enterprises """

        mock = MockUtils.create_mock_response(status_code=200,
                                              data=self.enterprises)

        with patch('requests.Session.request', mock):
            (fetcher, user, enterprises) = self.user.enterprises.fetch()
            connection = fetcher.current_connection

        method = MockUtils.get_mock_parameter(mock, 'method')
        url = MockUtils.get_mock_parameter(mock, 'url')
        headers = MockUtils.get_mock_parameter(mock, 'headers')

        self.assertEqual(url, 'https://vsd:8443/api/v3_2/enterprises')
        self.assertEqual(method, 'GET')
        self.assertEqual(
            headers['Authorization'],
            'XREST dXNlcjo1MWYzMTA0Mi1iMDQ3LTQ4Y2EtYTg4Yi02ODM2ODYwOGUzZGE=')
        self.assertEqual(headers['X-Nuage-Organization'], 'enterprise')
        self.assertEqual(headers['Content-Type'], 'application/json')

        self.assertEqual(fetcher, self.user.enterprises)
        self.assertEqual(user, self.user)
        self.assertEqual(len(enterprises), 4)
        self.assertEqual(connection.response.status_code, 200)
Пример #4
0
    def test_impersonate(self):
        """ GET /enterprises with impersonation

        """
        session = start_session()

        with patch.object(NURESTTestSession,
                          "_authenticate",
                          return_value=True):
            session.start()

        session.impersonate(username='******', enterprise='enterprise')

        mock = MockUtils.create_mock_response(status_code=200, data=[])

        user = User()

        with patch('requests.Session.request', mock):
            user.enterprises.fetch()

        headers = MockUtils.get_mock_parameter(mock=mock, name='headers')

        self.assertIn('X-Nuage-ProxyUser', headers)
        self.assertEquals(headers['X-Nuage-ProxyUser'], 'johndoe@enterprise')
        self.assertEquals(session.is_impersonating, True)

        session.stop_impersonate()
        self.assertEquals(session.is_impersonating, False)

        with patch('requests.Session.request', mock):
            user.enterprises.fetch()

        headers = MockUtils.get_mock_parameter(mock=mock, name='headers')
        self.assertNotIn('X-Nuage-ProxyUser', headers)
Пример #5
0
    def test_count_all(self):
        """ HEAD /enterprises count all enterprises """

        user = self.user
        headers = {'X-Nuage-Count': 4}

        mock = MockUtils.create_mock_response(status_code=200,
                                              data=None,
                                              headers=headers)

        with patch('requests.request', mock):
            (fetcher, user, count) = self.user.enterprises.count()

        method = MockUtils.get_mock_parameter(mock, 'method')
        url = MockUtils.get_mock_parameter(mock, 'url')
        headers = MockUtils.get_mock_parameter(mock, 'headers')

        self.assertEqual(url, 'https://vsd:8443/api/v3_2/enterprises')
        self.assertEqual(method, 'HEAD')
        self.assertEqual(
            headers['Authorization'],
            'XREST dXNlcjo1MWYzMTA0Mi1iMDQ3LTQ4Y2EtYTg4Yi02ODM2ODYwOGUzZGE=')
        self.assertEqual(headers['X-Nuage-Organization'], 'enterprise')
        self.assertEqual(headers['Content-Type'], 'application/json')

        self.assertEqual(fetcher, self.user.enterprises)
        self.assertEqual(user, self.user)
        self.assertEqual(count, 4)
Пример #6
0
    def test_assign(self):
        """ PUT /groups/id/users assign users """

        mock = MockUtils.create_mock_response(status_code=204, data=None)

        employee1 = Employee(firstname=u"Steven", lastname=u"Gerrard")
        employee2 = Employee(firstname=u"Gerrard", lastname=u"Lampard")

        with patch('requests.Session.request', mock):
            (objects, connection) = self.group.assign([employee1, employee2],
                                                      Employee)

        method = MockUtils.get_mock_parameter(mock, 'method')
        url = MockUtils.get_mock_parameter(mock, 'url')
        headers = MockUtils.get_mock_parameter(mock, 'headers')

        self.assertEqual(connection.response.status_code, 204)
        self.assertEqual(
            url,
            'https://vsd:8443/api/v3_2/groups/' + self.group.id + '/users')
        self.assertEqual(method, 'PUT')
        self.assertEqual(
            headers['Authorization'],
            'XREST dXNlcjo1MWYzMTA0Mi1iMDQ3LTQ4Y2EtYTg4Yi02ODM2ODYwOGUzZGE=')
        self.assertEqual(headers['X-Nuage-Organization'], 'enterprise')
        self.assertEqual(headers['Content-Type'], 'application/json')

        self.assertEqual(objects, [employee1, employee2])
        self.assertEqual(self.group.employees, [employee1, employee2])
        self.group.employees.flush()
Пример #7
0
    def test_update(self):
        """ PUT /enterprises update enterprise """

        enterprise = self.enterprise
        enterprise.name = "Another name"
        mock = MockUtils.create_mock_response(status_code=200, data=enterprise)

        with patch('requests.request', mock):
            (obj, connection) = enterprise.save()

        method = MockUtils.get_mock_parameter(mock, 'method')
        url = MockUtils.get_mock_parameter(mock, 'url')
        headers = MockUtils.get_mock_parameter(mock, 'headers')

        self.assertEqual(
            url, 'https://vsd:8443/api/v3_2/enterprises/%s' % enterprise.id)
        self.assertEqual(method, 'PUT')
        self.assertEqual(
            headers['Authorization'],
            'XREST dXNlcjo1MWYzMTA0Mi1iMDQ3LTQ4Y2EtYTg4Yi02ODM2ODYwOGUzZGE=')
        self.assertEqual(headers['X-Nuage-Organization'], 'enterprise')
        self.assertEqual(headers['Content-Type'], 'application/json')

        self.assertEqual(obj.name, "Another name")
        self.assertEqual(enterprise.name, "Another name")
        self.assertEqual(connection.response.status_code, 200)
Пример #8
0
    def test_create(self):
        """ POST /enterprises create enterprise """

        user = self.user
        enterprise = get_valid_enterprise(id=1, name=u"Enterprise")
        mock = MockUtils.create_mock_response(status_code=201, data=enterprise)

        with patch('requests.request', mock):
            (obj, connection) = user.create_child(enterprise)

        method = MockUtils.get_mock_parameter(mock, 'method')
        url = MockUtils.get_mock_parameter(mock, 'url')
        headers = MockUtils.get_mock_parameter(mock, 'headers')

        self.assertEqual(url, 'https://vsd:8443/api/v3_2/enterprises')
        self.assertEqual(method, 'POST')
        self.assertEqual(
            headers['Authorization'],
            'XREST dXNlcjo1MWYzMTA0Mi1iMDQ3LTQ4Y2EtYTg4Yi02ODM2ODYwOGUzZGE=')
        self.assertEqual(headers['X-Nuage-Organization'], 'enterprise')
        self.assertEqual(headers['Content-Type'], 'application/json')

        self.assertEqual(connection.response.status_code, 201)
        self.assertEqual(obj.id, 1)
        self.assertEqual(obj.name, enterprise.name)
        self.assertIn(obj, user.enterprises)
        self.assertIn(enterprise, user.enterprises)

        user.enterprises.flush()
Пример #9
0
    def test_impersonate(self):
        """ GET /enterprises with impersonation

        """
        session = start_session()

        session.impersonate(username='******', enterprise='enterprise')

        mock = MockUtils.create_mock_response(status_code=200, data=[])

        user = User()

        with patch('requests.request', mock):
            user.enterprises.fetch()

        headers = MockUtils.get_mock_parameter(mock=mock, name='headers')

        self.assertIn('X-Nuage-ProxyUser', headers)
        self.assertEquals(headers['X-Nuage-ProxyUser'], 'johndoe@enterprise')
        self.assertEquals(session.is_impersonating, True)

        session.stop_impersonate()
        self.assertEquals(session.is_impersonating, False)

        with patch('requests.request', mock):
            user.enterprises.fetch()

        headers = MockUtils.get_mock_parameter(mock=mock, name='headers')
        self.assertNotIn('X-Nuage-ProxyUser', headers)
Пример #10
0
    def test_create(self):
        """ POST /enterprises create enterprise """

        user = self.user
        enterprise = get_valid_enterprise(id=1, name=u"Enterprise")
        mock = MockUtils.create_mock_response(status_code=201, data=enterprise)

        with patch('requests.request', mock):
            (obj, connection) = user.create_child(enterprise)

        method = MockUtils.get_mock_parameter(mock, 'method')
        url = MockUtils.get_mock_parameter(mock, 'url')
        headers = MockUtils.get_mock_parameter(mock, 'headers')

        self.assertEqual(url, 'https://vsd:8443/api/v3_2/enterprises')
        self.assertEqual(method, 'POST')
        self.assertEqual(headers['Authorization'], 'XREST dXNlcjo1MWYzMTA0Mi1iMDQ3LTQ4Y2EtYTg4Yi02ODM2ODYwOGUzZGE=')
        self.assertEqual(headers['X-Nuage-Organization'], 'enterprise')
        self.assertEqual(headers['Content-Type'], 'application/json')

        self.assertEqual(connection.response.status_code, 201)
        self.assertEqual(obj.id, 1)
        self.assertEqual(obj.name, enterprise.name)
        self.assertIn(obj, user.enterprises)
        self.assertIn(enterprise, user.enterprises)

        user.enterprises.flush()
Пример #11
0
    def test_fetch_with_page(self):
        """ GET /enterprises retrieve enterprises with page """

        mock = MockUtils.create_mock_response(status_code=200, data=self.enterprises)

        with patch('requests.request', mock):
            (fetcher, user, enterprises) = self.user.enterprises.fetch(page=2)

        headers = MockUtils.get_mock_parameter(mock, 'headers')
        self.assertEqual(headers['X-Nuage-Page'], '2')
Пример #12
0
    def test_fetch_with_page(self):
        """ GET /enterprises retrieve enterprises with page """

        mock = MockUtils.create_mock_response(status_code=200, data=self.enterprises)

        with patch('requests.request', mock):
            (fetcher, user, enterprises) = self.user.enterprises.fetch(page=2)

        headers = MockUtils.get_mock_parameter(mock, 'headers')
        self.assertEqual(headers['X-Nuage-Page'], 2)
Пример #13
0
    def test_fetch_with_group_by(self):
        """ GET /enterprises retrieve enterprises with group_by """

        mock = MockUtils.create_mock_response(status_code=200, data=self.enterprises)

        with patch('requests.request', mock):
            (fetcher, user, enterprises) = self.user.enterprises.fetch(group_by=['field1', 'field2'])

        headers = MockUtils.get_mock_parameter(mock, 'headers')
        self.assertEqual(headers['X-Nuage-GroupBy'], 'true')
        self.assertEqual(headers['X-Nuage-Attributes'], 'field1, field2')
Пример #14
0
    def test_fetch_with_group_by(self):
        """ GET /enterprises retrieve enterprises with group_by """

        mock = MockUtils.create_mock_response(status_code=200, data=self.enterprises)

        with patch('requests.request', mock):
            (fetcher, user, enterprises) = self.user.enterprises.fetch(group_by=['field1', 'field2'])

        headers = MockUtils.get_mock_parameter(mock, 'headers')
        self.assertEqual(headers['X-Nuage-GroupBy'], 'true')
        self.assertEqual(headers['X-Nuage-Attributes'], 'field1, field2')
Пример #15
0
    def test_fetch_with_filter(self):
        """ GET /enterprises retrieve enterprises with filters """

        mock = MockUtils.create_mock_response(status_code=200, data=[self.enterprises[1]])

        with patch('requests.request', mock):
            (fetcher, user, enterprises) = self.user.enterprises.fetch(filter=u"name == 'Enterprise 2'")

        headers = MockUtils.get_mock_parameter(mock, 'headers')
        self.assertEqual(headers['X-Nuage-Filter'],"name == 'Enterprise 2'")
        self.assertEqual(len(enterprises), 1)
        self.assertEqual(enterprises[0].name,"Enterprise 2")
Пример #16
0
    def test_fetch_with_filter(self):
        """ GET /enterprises retrieve enterprises with filters """

        mock = MockUtils.create_mock_response(status_code=200, data=[self.enterprises[1]])

        with patch('requests.request', mock):
            (fetcher, user, enterprises) = self.user.enterprises.fetch(filter=u"name == 'Enterprise 2'")

        headers = MockUtils.get_mock_parameter(mock, 'headers')
        self.assertEqual(headers['X-Nuage-Filter'],"name == 'Enterprise 2'")
        self.assertEqual(len(enterprises), 1)
        self.assertEqual(enterprises[0].name,"Enterprise 2")
Пример #17
0
    def test_fetch_with_order_by(self):
        """ GET /enterprises retrieve enterprises with order_by """

        mock = MockUtils.create_mock_response(status_code=200,
                                              data=self.enterprises)

        with patch('requests.Session.request', mock):
            (fetcher, user,
             enterprises) = self.user.enterprises.fetch(order_by='name ASC')

        headers = MockUtils.get_mock_parameter(mock, 'headers')
        self.assertEqual(headers['X-Nuage-OrderBy'], 'name ASC')
Пример #18
0
    def test_count_with_page(self):
        """ HEAD /enterprises count enterprises with page """

        user = self.user
        headers = {'X-Nuage-Count': 2}

        mock = MockUtils.create_mock_response(status_code=200, data=None, headers=headers)

        with patch('requests.Session.request', mock):
            (fetcher, user, count) = self.user.enterprises.count(page=3)

        headers = MockUtils.get_mock_parameter(mock, 'headers')
        self.assertEqual(headers['X-Nuage-Page'], '3')
Пример #19
0
    def test_count_with_page(self):
        """ HEAD /enterprises count enterprises with page """

        user = self.user
        headers = {'X-Nuage-Count': 2}

        mock = MockUtils.create_mock_response(status_code=200, data=None, headers=headers)

        with patch('requests.request', mock):
            (fetcher, user, count) = self.user.enterprises.count(page=3)

        headers = MockUtils.get_mock_parameter(mock, 'headers')
        self.assertEqual(headers['X-Nuage-Page'], '3')
Пример #20
0
    def test_count_with_group_by(self):
        """ HEAD /enterprises count enterprises with group_by """

        user = self.user
        headers = {'X-Nuage-Count': 2}

        mock = MockUtils.create_mock_response(status_code=200, data=None, headers=headers)

        with patch('requests.Session.request', mock):
            (fetcher, user, count) = self.user.enterprises.count(group_by=['field1', 'field2'])

        headers = MockUtils.get_mock_parameter(mock, 'headers')
        self.assertEqual(headers['X-Nuage-GroupBy'], 'true')
        self.assertEqual(headers['X-Nuage-Attributes'], 'field1, field2')
Пример #21
0
    def test_count_with_filter(self):
        """ HEAD /enterprises count enterprises with filters """

        user = self.user
        headers = {'X-Nuage-Count': 2}

        mock = MockUtils.create_mock_response(status_code=200, data=None, headers=headers)

        with patch('requests.Session.request', mock):
            (fetcher, user, count) = self.user.enterprises.count(filter=u"name == 'Enterprise 2'")

        headers = MockUtils.get_mock_parameter(mock, 'headers')
        self.assertEqual(headers['X-Nuage-Filter'],"name == 'Enterprise 2'")
        self.assertEqual(count, 2)
Пример #22
0
    def test_count_with_filter(self):
        """ HEAD /enterprises count enterprises with filters """

        user = self.user
        headers = {'X-Nuage-Count': 2}

        mock = MockUtils.create_mock_response(status_code=200, data=None, headers=headers)

        with patch('requests.request', mock):
            (fetcher, user, count) = self.user.enterprises.count(filter=u"name == 'Enterprise 2'")

        headers = MockUtils.get_mock_parameter(mock, 'headers')
        self.assertEqual(headers['X-Nuage-Filter'],"name == 'Enterprise 2'")
        self.assertEqual(count, 2)
Пример #23
0
    def test_count_with_group_by(self):
        """ HEAD /enterprises count enterprises with group_by """

        user = self.user
        headers = {'X-Nuage-Count': 2}

        mock = MockUtils.create_mock_response(status_code=200, data=None, headers=headers)

        with patch('requests.request', mock):
            (fetcher, user, count) = self.user.enterprises.count(group_by=['field1', 'field2'])

        headers = MockUtils.get_mock_parameter(mock, 'headers')
        self.assertEqual(headers['X-Nuage-GroupBy'], 'true')
        self.assertEqual(headers['X-Nuage-Attributes'], 'field1, field2')
Пример #24
0
    def test_refetch_all_with_delete_object(self):
        """ GET /enterprises refetch all enterprises should remove local info when object is deleted """

        mock = MockUtils.create_mock_response(status_code=200, data=self.enterprises)

        with patch('requests.request', mock):
            (fetcher, user, enterprises) = self.user.enterprises.fetch()


        mock = MockUtils.create_mock_response(status_code=200, data=self.enterprises[1:])
        with patch('requests.request', mock):
            (fetcher, user, enterprises) = self.user.enterprises.fetch()
            connection = fetcher.current_connection

        self.assertEqual(connection.response.status_code, 200)
        self.assertEqual(len(enterprises), 3)
Пример #25
0
    def test_count_with_order_by(self):
        """ HEAD /enterprises count enterprises with order_by """

        user = self.user
        headers = {'X-Nuage-Count': 2}

        mock = MockUtils.create_mock_response(status_code=200,
                                              data=None,
                                              headers=headers)

        with patch('requests.request', mock):
            (fetcher, user,
             count) = self.user.enterprises.count(order_by='name ASC')

        headers = MockUtils.get_mock_parameter(mock, 'headers')
        self.assertEqual(headers['X-Nuage-OrderBy'], 'name ASC')
Пример #26
0
    def test_refetch_all_with_delete_object(self):
        """ GET /enterprises refetch all enterprises should remove local info when object is deleted """

        mock = MockUtils.create_mock_response(status_code=200, data=self.enterprises)

        with patch('requests.request', mock):
            (fetcher, user, enterprises) = self.user.enterprises.fetch()


        mock = MockUtils.create_mock_response(status_code=200, data=self.enterprises[1:])
        with patch('requests.request', mock):
            (fetcher, user, enterprises) = self.user.enterprises.fetch()
            connection = fetcher.current_connection

        self.assertEqual(connection.response.status_code, 200)
        self.assertEqual(len(enterprises), 3)
Пример #27
0
    def test_delete_raise_error(self):
        """ DELETE /enterprises delete enterprise raise error """

        mock = MockUtils.create_mock_response(status_code=400, data=self.enterprise, error=u"Internal error")

        with patch('requests.request', mock):
            with self.assertRaises(BambouHTTPError):
                (obj, connection) = self.enterprise.delete(response_choice=1)
Пример #28
0
    def test_fetch_all_should_not_raise_exception(self):
        """ GET /enterprises retrieve all enterprises should not raise exception """

        mock = MockUtils.create_mock_response(status_code=500, data=[], error=u"Internal error")

        with patch('requests.request', mock):
            with self.assertRaises(BambouHTTPError):
                (fetcher, user, enterprises) = self.user.enterprises.fetch()
                connection = fetcher.current_connection
Пример #29
0
    def test_count_all_should_raise_exception(self):
        """ HEAD /enterprises count all enterprises should raise exception """

        user = self.user
        mock = MockUtils.create_mock_response(status_code=500, data=[], error=u"Internal error")

        with patch('requests.request', mock):
            with self.assertRaises(BambouHTTPError):
                (fetcher, user, count) = self.user.enterprises.count()
Пример #30
0
    def test_fetch_all_should_not_raise_exception(self):
        """ GET /enterprises retrieve all enterprises should not raise exception """

        mock = MockUtils.create_mock_response(status_code=500, data=[], error=u"Internal error")

        with patch('requests.request', mock):
            with self.assertRaises(BambouHTTPError):
                (fetcher, user, enterprises) = self.user.enterprises.fetch()
                connection = fetcher.current_connection
Пример #31
0
    def test_count_all_should_raise_exception(self):
        """ HEAD /enterprises count all enterprises should raise exception """

        user = self.user
        mock = MockUtils.create_mock_response(status_code=500, data=[], error=u"Internal error")

        with patch('requests.Session.request', mock):
            with self.assertRaises(BambouHTTPError):
                (fetcher, user, count) = self.user.enterprises.count()
Пример #32
0
    def test_delete_raise_error(self):
        """ DELETE /enterprises delete enterprise raise error """

        mock = MockUtils.create_mock_response(status_code=400,
                                              data=self.enterprise,
                                              error=u"Internal error")

        with patch('requests.Session.request', mock):
            with self.assertRaises(BambouHTTPError):
                (obj, connection) = self.enterprise.delete(response_choice=1)
Пример #33
0
    def test_update_raise_error(self):
        """ PUT /enterprises update enterprise raise error """

        enterprise = self.enterprise
        enterprise.name ="Another name"
        mock = MockUtils.create_mock_response(status_code=404, data=enterprise, error=u"Enterprise not found")

        with patch('requests.request', mock):
            with self.assertRaises(BambouHTTPError):
                (obj, connection) = enterprise.save()
Пример #34
0
    def test_get_count_with_query_parameter(self):
        """ GET /enterprises with a query parameter using get_count() """

        mock = MockUtils.create_mock_response(status_code=200, data=self.enterprises)

        with patch('requests.request', mock):
            enterprises = self.user.enterprises.get_count(query_parameters={"query_param": "query_value"})
            connection = self.user.enterprises.current_connection

        self.assertEqual(connection.request.params, {"query_param": "query_value"})
Пример #35
0
    def test_create_raise_error(self):
        """ POST /enterprises create enterprise raises an error """

        user = self.user
        enterprise = get_valid_enterprise(id=1, name=u"Enterprise")
        mock = MockUtils.create_mock_response(status_code=409, data=enterprise, error=u"Name already exists")

        with patch('requests.request', mock):
            with self.assertRaises(BambouHTTPError):
                (obj, connection) = user.create_child(enterprise)
Пример #36
0
    def test_get_count_with_query_parameter(self):
        """ GET /enterprises with a query parameter using get_count() """

        mock = MockUtils.create_mock_response(status_code=200, data=self.enterprises)

        with patch('requests.request', mock):
            enterprises = self.user.enterprises.get_count(query_parameters={"query_param": "query_value"})
            connection = self.user.enterprises.current_connection

        self.assertEqual(connection.request.params, {"query_param": "query_value"})
Пример #37
0
    def test_fetch(self):
        """ GET /enterprises/id fetch enterprise """

        enterprise = Enterprise(id=1)
        mock = MockUtils.create_mock_response(status_code=200, data=self.enterprise)

        with patch('requests.request', mock):
            (obj, connection) = enterprise.fetch()

        method = MockUtils.get_mock_parameter(mock, 'method')
        url = MockUtils.get_mock_parameter(mock, 'url')
        headers = MockUtils.get_mock_parameter(mock, 'headers')

        self.assertEqual(url, 'https://vsd:8443/api/v3_2/enterprises/%s' % enterprise.id)
        self.assertEqual(method, 'GET')
        self.assertEqual(headers['Authorization'], 'XREST dXNlcjo1MWYzMTA0Mi1iMDQ3LTQ4Y2EtYTg4Yi02ODM2ODYwOGUzZGE=')
        self.assertEqual(headers['X-Nuage-Organization'], 'enterprise')
        self.assertEqual(headers['Content-Type'], 'application/json')

        self.assertEqual(connection.response.status_code, 200)
        self.assertEqual(enterprise.name, obj.name)
Пример #38
0
    def test_fetch_all_without_commit(self):
        """ GET /enterprises retrieve all enterprises without commit """

        mock = MockUtils.create_mock_response(status_code=200, data=self.enterprises)

        with patch('requests.request', mock):
            (fetcher, user, enterprises) = self.user.enterprises.fetch(commit=False)
            connection = fetcher.current_connection

        self.assertEqual(connection.response.status_code, 200)
        self.assertEqual(len(enterprises), 4)
        self.assertEqual(len(self.user.enterprises), 0)
Пример #39
0
    def test_create_without_commit(self):
        """ POST /enterprises create enterprise without commit """

        user = self.user
        enterprise = get_valid_enterprise(id=1, name=u"Enterprise")
        mock = MockUtils.create_mock_response(status_code=201, data=enterprise)

        with patch('requests.request', mock):
            (obj, connection) = user.create_child(enterprise, commit=False)

        self.assertNotIn(obj, user.enterprises)
        self.assertNotIn(enterprise, user.enterprises)
Пример #40
0
    def test_direct_count_all(self):
        """ HEAD /enterprises direct count all enterprises """

        user = self.user
        headers = {'X-Nuage-Count': 4}

        mock = MockUtils.create_mock_response(status_code=200, data=None, headers=headers)

        with patch('requests.Session.request', mock):
            count = self.user.enterprises.get_count()

        self.assertEqual(count, 4)
Пример #41
0
    def test_fetch_all_without_commit(self):
        """ GET /enterprises retrieve all enterprises without commit """

        mock = MockUtils.create_mock_response(status_code=200, data=self.enterprises)

        with patch('requests.request', mock):
            (fetcher, user, enterprises) = self.user.enterprises.fetch(commit=False)
            connection = fetcher.current_connection

        self.assertEqual(connection.response.status_code, 200)
        self.assertEqual(len(enterprises), 4)
        self.assertEqual(len(self.user.enterprises), 0)
Пример #42
0
    def test_delete(self):
        """ DELETE /enterprises delete enterprise """

        mock = MockUtils.create_mock_response(status_code=204, data=self.enterprise)

        with patch('requests.request', mock):
            (obj, connection) = self.enterprise.delete(response_choice=1)

        method = MockUtils.get_mock_parameter(mock, 'method')
        url = MockUtils.get_mock_parameter(mock, 'url')
        headers = MockUtils.get_mock_parameter(mock, 'headers')

        self.assertEqual(url, 'https://vsd:8443/api/v3_2/enterprises/%s?responseChoice=1' % self.enterprise.id)
        self.assertEqual(method, 'DELETE')
        self.assertEqual(headers['Authorization'], 'XREST dXNlcjo1MWYzMTA0Mi1iMDQ3LTQ4Y2EtYTg4Yi02ODM2ODYwOGUzZGE=')
        self.assertEqual(headers['X-Nuage-Organization'], 'enterprise')
        self.assertEqual(headers['Content-Type'], 'application/json')

        self.assertEqual(obj.name, self.enterprise.name)
        self.assertEqual(obj.id, self.enterprise.id)
        self.assertEqual(connection.response.status_code, 204)
Пример #43
0
    def test_direct_count_all(self):
        """ HEAD /enterprises direct count all enterprises """

        user = self.user
        headers = {'X-Nuage-Count': 4}

        mock = MockUtils.create_mock_response(status_code=200, data=None, headers=headers)

        with patch('requests.request', mock):
            count = self.user.enterprises.get_count()

        self.assertEqual(count, 4)
Пример #44
0
    def test_update_raise_error(self):
        """ PUT /enterprises update enterprise raise error """

        enterprise = self.enterprise
        enterprise.name = "Another name"
        mock = MockUtils.create_mock_response(status_code=404,
                                              data=enterprise,
                                              error=u"Enterprise not found")

        with patch('requests.request', mock):
            with self.assertRaises(BambouHTTPError):
                (obj, connection) = enterprise.save()
Пример #45
0
    def test_create_raise_error(self):
        """ POST /enterprises create enterprise raises an error """

        user = self.user
        enterprise = get_valid_enterprise(id=1, name=u"Enterprise")
        mock = MockUtils.create_mock_response(status_code=409,
                                              data=enterprise,
                                              error=u"Name already exists")

        with patch('requests.request', mock):
            with self.assertRaises(BambouHTTPError):
                (obj, connection) = user.create_child(enterprise)
Пример #46
0
    def test_create_without_commit(self):
        """ POST /enterprises create enterprise without commit """

        user = self.user
        enterprise = get_valid_enterprise(id=1, name=u"Enterprise")
        mock = MockUtils.create_mock_response(status_code=201, data=enterprise)

        with patch('requests.request', mock):
            (obj, connection) = user.create_child(enterprise, commit=False)

        self.assertNotIn(obj, user.enterprises)
        self.assertNotIn(enterprise, user.enterprises)
Пример #47
0
    def test_fetch_with_query_parameter(self):
        """ GET /enterprises with a query parameter using fetch() """

        mock = MockUtils.create_mock_response(status_code=200,
                                              data=self.enterprises)

        with patch('requests.Session.request', mock):
            (fetcher, user, enterprises) = self.user.enterprises.fetch(
                query_parameters={"query_param": "query_value"})
            connection = fetcher.current_connection

        self.assertEqual(connection.request.params,
                         {"query_param": "query_value"})
Пример #48
0
    def test_assign_with_commit(self):
        """ PUT /groups/id/users assign users without commit """

        mock = MockUtils.create_mock_response(status_code=204, data=None)

        employee1 = Employee(firstname=u"Steven", lastname=u"Gerrard")
        employee2 = Employee(firstname=u"Gerrard", lastname=u"Lampard")

        with patch('requests.request', mock):
            (objects, connection) = self.group.assign([employee1, employee2], Employee, commit=False)

        self.assertEqual(objects, [employee1, employee2])
        self.assertEqual(self.group.employees, [])
Пример #49
0
    def test_update(self):
        """ PUT /me update current user """

        self.user.prepare_change_password('test')

        mock = MockUtils.create_mock_response(status_code=204, data=None)

        with patch('requests.request', mock):
            (obj, connection) = self.user.save()

        method = MockUtils.get_mock_parameter(mock, 'method')
        url = MockUtils.get_mock_parameter(mock, 'url')
        headers = MockUtils.get_mock_parameter(mock, 'headers')

        self.assertEqual(connection.response.status_code, 204)
        self.assertEqual(url, 'https://vsd:8443/api/v3_2/me')
        self.assertEqual(method, 'PUT')
        self.assertEqual(headers['Authorization'], 'XREST dXNlcjp0ZXN0')
        self.assertEqual(headers['X-Nuage-Organization'], 'enterprise')
        self.assertEqual(headers['Content-Type'], 'application/json')

        self.assertEqual(self.user.password,"a94a8fe5ccb19ba61c4c0873d391e987982fbbd3")  # Encrypted password
Пример #50
0
    def test_fetch_all(self):
        """ GET /enterprises fetch all enterprises """

        mock = MockUtils.create_mock_response(status_code=200, data=self.enterprises)

        with patch('requests.request', mock):
            (fetcher, user, enterprises) = self.user.enterprises.fetch()
            connection = fetcher.current_connection

        method = MockUtils.get_mock_parameter(mock, 'method')
        url = MockUtils.get_mock_parameter(mock, 'url')
        headers = MockUtils.get_mock_parameter(mock, 'headers')

        self.assertEqual(url, 'https://vsd:8443/api/v3_2/enterprises')
        self.assertEqual(method, 'GET')
        self.assertEqual(headers['Authorization'], 'XREST dXNlcjo1MWYzMTA0Mi1iMDQ3LTQ4Y2EtYTg4Yi02ODM2ODYwOGUzZGE=')
        self.assertEqual(headers['X-Nuage-Organization'], 'enterprise')
        self.assertEqual(headers['Content-Type'], 'application/json')

        self.assertEqual(fetcher, self.user.enterprises)
        self.assertEqual(user, self.user)
        self.assertEqual(len(enterprises), 4)
        self.assertEqual(connection.response.status_code, 200)
Пример #51
0
    def test_count_all(self):
        """ HEAD /enterprises count all enterprises """

        user = self.user
        headers = {'X-Nuage-Count': 4}

        mock = MockUtils.create_mock_response(status_code=200, data=None, headers=headers)

        with patch('requests.request', mock):
            (fetcher, user, count) = self.user.enterprises.count()

        method = MockUtils.get_mock_parameter(mock, 'method')
        url = MockUtils.get_mock_parameter(mock, 'url')
        headers = MockUtils.get_mock_parameter(mock, 'headers')

        self.assertEqual(url, 'https://vsd:8443/api/v3_2/enterprises')
        self.assertEqual(method, 'HEAD')
        self.assertEqual(headers['Authorization'], 'XREST dXNlcjo1MWYzMTA0Mi1iMDQ3LTQ4Y2EtYTg4Yi02ODM2ODYwOGUzZGE=')
        self.assertEqual(headers['X-Nuage-Organization'], 'enterprise')
        self.assertEqual(headers['Content-Type'], 'application/json')

        self.assertEqual(fetcher, self.user.enterprises)
        self.assertEqual(user, self.user)
        self.assertEqual(count, 4)
Пример #52
0
    def test_update(self):
        """ PUT /me update current user """

        self.user.prepare_change_password('test')

        mock = MockUtils.create_mock_response(status_code=204, data=None)

        with patch('requests.Session.request', mock):
            (obj, connection) = self.user.save()

        method = MockUtils.get_mock_parameter(mock, 'method')
        url = MockUtils.get_mock_parameter(mock, 'url')
        headers = MockUtils.get_mock_parameter(mock, 'headers')

        self.assertEqual(connection.response.status_code, 204)
        self.assertEqual(url, 'https://vsd:8443/api/v3_2/me')
        self.assertEqual(method, 'PUT')
        self.assertEqual(headers['Authorization'], 'XREST dXNlcjp0ZXN0')
        self.assertEqual(headers['X-Nuage-Organization'], 'enterprise')
        self.assertEqual(headers['Content-Type'], 'application/json')

        self.assertEqual(
            self.user.password,
            "a94a8fe5ccb19ba61c4c0873d391e987982fbbd3")  # Encrypted password
Пример #53
0
    def test_assign_with_commit(self):
        """ PUT /groups/id/users assign users without commit """

        mock = MockUtils.create_mock_response(status_code=204, data=None)

        employee1 = Employee(firstname=u"Steven", lastname=u"Gerrard")
        employee2 = Employee(firstname=u"Gerrard", lastname=u"Lampard")

        with patch('requests.Session.request', mock):
            (objects, connection) = self.group.assign([employee1, employee2],
                                                      Employee,
                                                      commit=False)

        self.assertEqual(objects, [employee1, employee2])
        self.assertEqual(self.group.employees, [])
Пример #54
0
    def test_refetch_all(self):
        """ GET /enterprises refetch all enterprises should override local changes"""

        mock = MockUtils.create_mock_response(status_code=200, data=self.enterprises)

        with patch('requests.request', mock):

            (fetcher, user, enterprises) = self.user.enterprises.fetch()

            enterprise = self.user.enterprises[2]
            enterprise.name = 'This name should not appear because we will refetch everything!'

            (fetcher, user, enterprises) = self.user.enterprises.fetch()
            connection = fetcher.current_connection

        self.assertEqual(connection.response.status_code, 200)
        self.assertEqual(fetcher, self.user.enterprises)
        self.assertEqual(user, self.user)
        self.assertEqual(len(enterprises), 4)
        self.assertEqual(self.user.enterprises[2].name, "Enterprise 3")
Пример #55
0
    def test_refetch_all(self):
        """ GET /enterprises refetch all enterprises should override local changes"""

        mock = MockUtils.create_mock_response(status_code=200, data=self.enterprises)

        with patch('requests.request', mock):

            (fetcher, user, enterprises) = self.user.enterprises.fetch()

            enterprise = self.user.enterprises[2]
            enterprise.name = 'This name should not appear because we will refetch everything!'

            (fetcher, user, enterprises) = self.user.enterprises.fetch()
            connection = fetcher.current_connection

        self.assertEqual(connection.response.status_code, 200)
        self.assertEqual(fetcher, self.user.enterprises)
        self.assertEqual(user, self.user)
        self.assertEqual(len(enterprises), 4)
        self.assertEqual(self.user.enterprises[2].name, "Enterprise 3")