Exemplo n.º 1
0
def get_all():
    """List all instance.

    Returns: instance collection

    """
    return Instance.get_all()
Exemplo n.º 2
0
def get_by_endpoint_starting_with(instance_endpoint):
    """Return instance object with the given get_by_endpoint.

    Args:
        instance_endpoint:

    Returns: instance object

    """
    return Instance.get_by_endpoint_starting_with(instance_endpoint)
Exemplo n.º 3
0
def get_by_name(instance_name):
    """Return instance object with the given name.

    Args:
        instance_name:

    Returns: instance object

    """
    return Instance.get_by_name(instance_name)
Exemplo n.º 4
0
def get_by_id(instance_id):
    """Return instance object with the given id.

    Args:
        instance_id:

    Returns: instance object

    """
    return Instance.get_by_id(instance_id)
    def generate_data_collection(self):
        """ Generate a Data collection.

        Returns:

        """
        self.data_1 = Instance(name="name_1",
                               endpoint='http://127.0.0.1:8000/',
                               access_token='token',
                               refresh_token='refresh',
                               expires=datetime.datetime.now()).save()
        self.data_collection = [self.data_1]
    def test_is_staff_returns_http_204(self, instance_get_by_id, instance_delete):
        instance_get_by_id.return_value = Instance(
            name="mock",
            endpoint="http://mock.com/",
            access_token="mock",
            refresh_token="mock",
            expires=datetime.datetime.now(),
        )

        response = RequestMock.do_request_delete(
            instance_views.InstanceDetail.as_view(),
            create_mock_user("1", is_staff=True),
            param={"pk": self.fake_id},
        )

        self.assertEqual(response.status_code, status.HTTP_204_NO_CONTENT)
    def test_get_blob_response_from_url_return_blob_if_is_known_instance(
        self,
        mock_get_by_endpoint_starting_with,
        mock_send_get_request_with_access_token,
    ):
        # Arrange
        mock_get_by_endpoint_starting_with.return_value = Instance(
            name="name",
            endpoint="http://my.url.test",
            access_token="access_token",
            refresh_token="refresh_token",
            expires="date",
        )

        mock_send_get_request_with_access_token.return_value = "remote"

        # Act
        return_value = api.get_blob_response_from_url(
            "http://my.url.test", "http://my.url.test/098765432")
        # assert
        self.assertEqual(return_value, "remote")
Exemplo n.º 8
0
def _create_instance_object_from_request_response(name, endpoint, content):
    """ Create an Instance object from a request.

    Args:
        name:
        endpoint:
        content:

    Returns:

    """
    # Calculate the expiration date
    now = datetime.now()
    delta = timedelta(seconds=int(json.loads(content)["expires_in"]))
    expires = now + delta
    # Create an instance with the response given by the remote server
    return Instance(name=name,
                    endpoint=endpoint,
                    access_token=json.loads(content)["access_token"],
                    refresh_token=json.loads(content)["refresh_token"],
                    expires=expires)