My django webserver url accept query-parameters. For ex. "mydomain.com?emp_name=abc&dept=admin".
I want to automate this write a test using pytest-djnago to see if the url accepts the query parameters or not. Please suggest.
There are two ways to achive this.
My setup :
Django 3.2.12
django-test-curl 0.2.0
gunicorn 20.1.0
pytest 7.0.1
pytest-django 4.5.2
1) By using pytest-curl-report plugin (https://pypi.org/project/pytest-curl-report/)
I was getting below error after installing the "pytest-curl-report 0.5.4" plugin.
Error:
`pluggy._manager.PluginValidationError: Plugin 'curl-report' for hook
'pytest_runtest_makereport'
hookimpl definition: pytest_runtest_makereport(multicall, item, call)
Argument(s) {'multicall'} are declared in the hookimpl but can not be found in the hookspec`
I tired multiple install/unistall but it didnt helped.
Also I didnt found any fix this issue on google, so I skipped this one and decided to use django-test-curl plugin. See point no. 2)
2) By using django-test-curl plugin ("https://github.com/crccheck/django-test-curl")
$ pip3 install django-test-curl
Usage
from django_test_curl import CurlClient
class SimpleTest(TestCase):
def setUp(self):
self.client = CurlClient()
def test_details(self):
response = self.client.curl("""
curl http://localhost:8000/customer/details/
""")
self.assertEqual(response.status_code, 200)
self.assertEqual(len(response.context['customers']), 5)
Related
I am sending mail using airflow emailOperator. Is there any way to send "reply-to" parameter also. i tried default_param={'key':'value'} but throwing exception as invalid parameter.
I read this https://github.com/apache/airflow/blob/main/airflow/operators/email.py
https://github.com/apache/airflow/blob/main/tests/operators/test_email.py
But I don't know where i am doing mistake.
version : 2.0.2
email_op = EmailOperator(
task_id='send_email',
to=destination['emails'],
subject=destination['subject'],
html_content=destination['message'],
files=[file.name],
default_param={'Reply-To': 'reply_to#example.com'},
)
email_op.execute(context)
It would be passed via dictionary custom_headers, as per the Official Source Code and Official Docs
I actually took the Reply-To directly from the official Airflow unit test.
There was a bug patched in release 2.3.0 with the send_email function to correctly pass the custom_headers. This might be your root cause...
Here is the link to the issue
Here is the pull request to resolve it
For new comers here is how you would send the custom_headers when using 2.3.0 and above.
from airflow.operators.email_operator import EmailOperator
t1 = EmailOperator(
task_id='send_email',
to="email#example.com",
subject="Airflow Example",
html_content=""" <h3>Email Test</h3> """,
cc="email#example",
custom_headers = {
'Reply-To': 'reply_to#example.com'
}
)
Using the DENO_AUTH_TOKENS environment variable doesn't appear to work for me. I've created a personal access token from GitHub and added it to my environment as described in the private modules page of the Deno manual. However, I still just get a 404 error:
error: Import 'https://raw.githubusercontent.com/MYCOMPANY/MYREPO/main/MYFILE.ts' failed: 404 Not Found
I've verified that the token is in the environment variable, and it succeeds in curl by executing the following:
curl -s https://$DENO_AUTH_TOKENS/MYCOMPANY/MYREPO/main/MYFILE.ts
Am I doing the import differently than the Deno runtime expects it?
import { foo } from 'https://raw.githubusercontent.com/MYCOMPANY/MYREPO/main/MYFILE.ts';
Running the script with -L debug gives a lot of verbose logging, but nothing about tokens at all.
What does it want me to do?
$ deno --version
deno 1.14.2 (release, x86_64-apple-darwin)
v8 9.4.146.16
typescript 4.4.2
This was a dumb mistake. When I added the variable to my .profile file, I forgot to add export before. It works after adding that:
export DENO_AUTH_TOKENS=aaaaaaaaaaaaaaaaaa#raw.githubusercontent.com
I've finally managed to make my proxy settings work for GitHub cloning, using the following code :
options(rsconnect.http = "internal")
Sys.setenv(http_proxy = "http://proxy.lala.blabla:8080")
Sys.setenv(https_proxy = "https://proxy.lala.blabla:8080")
I can now clone github projects using File > New Project > Version control.
But I can't install from github :'(
require(devtools)
install_github("this/that")
--> Installation failed: Could not resolve host: raw.githubusercontent.com
People seem to use the following command :
http::set_config(use_proxy(...))
But that would force me to explicitely write my login / pass, which I don't want to do. I'd rather use the default ones that are associated to
options(rsconnect.http = "internal")
How can I configure the proxy here, without writing my login/pass please ?
devtools uses httr under the hoods, see e.g. devtools:::remote_package_name.github_remote or devtools:::remote_download.github_remote.
That is why it requires you to set the proxy in the httr::set_config(httr::use_proxy(...)) way.
I would suggest that you just pick up the information from the environment variables and pass the elements to httr::set_config(httr::use_proxy(...)). Then you don't need to type your settings in the code.
Is there a way to delete GAVs through a REST API in Nexus 3? From various
google searches it appears that this capability existed in Nexus 2, but not in
Nexus 3 yet. Is that true?
I tried the following with my current Nexus installation, which is OSS 3.2.1-01:
I was trying to delete GAV:
groupId = org.mycompany.myproject
artifactId = myartifact
version = 1.0.0
$ curl --request DELETE --user "USERNAME:PASSWORD" --write-out '%{http_code}\n' http://my-server:8081/service/local/repositories/my-repo/content/org.mycompany.myproject/myartifact/1.0.0
This gave me a 405.
I also looked at the release notes for 3.3 through 3.5 and nothing jumped out
that REST API support was added.
I also looked into
https://help.sonatype.com/display/NXRM3/REST+and+Integration+API. I downloaded
the nexus-book-examples and downloaded several of the Javadocs (nexus-core,
nexus-repository, nexus-common, nexus-script, nexus-commands, nexus-selector)
for version 3.2.1-01 and started to look through the code. It was not clear
where to start with a simple program to delete GAVs.
Am I correct that you cannot delete GAVs through the REST API in Nexus 3? Is
there a plan to support this in a future Nexus 3 release? Is there a way to do
what I want to do by creating a Groovy script using the code referenced by the
REST+and+Integration+API link above? Is there some sample code which will help
bootstrap me to using the above code (either 3.2.1-01, or a newer version of
Nexus).
Thanks.
You might take a look at our Beta REST API in Nexus Repository 3. Upgrade to a version greater than 3.3, preferably to 3.5 (just so you are using latest and greatest) and navigate to:
http://nexushostname:nexusport/swagger-ui/
Since the REST API is currently Beta we have yet to publish documentation or fanfare around it while we let people experiment with it and give us feedback.
You should see endpoints for deleting components and assets. You will likely want to use the component delete, so that it will clean up all associated assets.
Let me know your mileage!
According to the documentation, you can delete an ASSET (individual file) or a COMPONENT (a set of files, like jar+md5+sha1+pom.xml representing an artifact) only if you know the assetId or the componentId
https://help.sonatype.com/repomanager3/rest-and-integration-api/components-api
https://help.sonatype.com/repomanager3/rest-and-integration-api/assets-api
So you should issue a separate search call passing the GAV and finding out the componentId, then use the componentId to delete in a second call.
However I see here https://issues.sonatype.org/browse/NEXUS-11266 and here
https://issues.sonatype.org/browse/NEXUS-11881 that people can delete an asset just by specifying the entire path... I have tried with
curl -u admin:admin123 -X "DELETE" -w "%{http_code}" http://localhost:8081/repository/deployments/org/apache/commons/commons-compress/1.18/commons-compress-1.18.jar
and it gives me a HTTP 204 (no content). In my case "deployments" is a hosted repository. I have tried the same command on "central" (aproxy repo) and I get a 405.
But if I try to download the whole component (including pom, sha1 etc) with
curl -u admin:admin123 -X "DELETE" -w "%{http_code}" http://localhost:8081/repository/deployments/org/apache/commons/commons-compress/1.18/
I get a HTTP 404.
I know, it's painful and in Nexus2 it was much easier.
I have developed a desktop application in OCaml under Ubuntu.
Now, I would like to deploy it to a DigitalOcean Ubuntu server (512 MB Memory / 20 GB Disk) that I own. I will use JavaScript programs on the client side to call the executable stored on the server side, then deal with the returned results.
However, I have no idea how to get started.
Someone pointed me to FastCGI, I did see some FastCGI settings in Nginx server. It seems that there are some OCaml libraries to handle FastCGI or CGI: ocamlnet, cgi, CamlGI, etc.
Could anyone tell me which library is stable and suits my need?
Besides, are there some samples of the library and the settings in Nginx server to let me get started?
I don't think the solution I will propose is the less heavy, but it has several advantages :
It allows you to generate the website in Ocaml, so that the interface with your code won't be to hard to do
If needed you will be able to export your whole application directly in Javascript : you won't let your serveur do useless computes that the user could do, and moreover you don't need to rewrite your code in Javascript, Ocsigen can convert your code for you
If some operations need to be performed by the serveur, you can really easily call server side functions from the client side code, and all your code will be written in Ocaml.
It's pretty easy
What is this amazing tool ? Ocsigen ! You can find a complete tutorial here.
Now let's see how you can use it
Install Ocsigen
First if you don't have it, install opam (it will allow you to install ocaml packages). Just follow the instructions on the website (I cannot paste link since I don't have enough reputation points), but basically for ubuntu run :
sudo add-apt-repository ppa:avsm/ppa
sudo apt-get update
sudo apt-get install ocaml ocaml-native-compilers camlp4-extra m4 opam
Then, you need to install Ocsigen. All instructions are here : https://ocsigen.org/install but basically just do :
sudo aptitude install libev-dev libgdbm-dev libncurses5-dev libpcre3-dev libssl-dev libsqlite3-dev libcairo-ocaml-dev m4 opam camlp4-extra
opam install eliom
(Note : you can also install it with apt-get if you don't want to install/use opam, but I prefer using opam to deal with ocaml depends, you can choose a precise version...)
Well it's done, you now have installed ocsigen !
Create the web page
Then to create a basic scaffold site just run
eliom-distillery -name mysite -template basic -target-directory mysite
and to run it :
cd mysite/
make test.byte
You should see a basic page at localhost:8080/.
Now, let's insert your code. Let's imagine it is named myscript and return a string :
let myscript () = "Here is my amazing result"
Add this code before the let () = in the file mysite.eliom, and add just after h2 [pcdata "Welcome from Eliom's distillery!"]; the line :
p [pcdata (Printf.sprintf "My script gives the return function : \"%s\"" (myscript ()))]
This will create a paragraphe (p) whose content (pcdata) contains the result of myscritpt.
For me the whole mysite.eliom gives :
{shared{
open Eliom_lib
open Eliom_content
open Html5.D
}}
module Mysite_app =
Eliom_registration.App (
struct
let application_name = "mysite"
end)
let main_service =
Eliom_service.App.service ~path:[] ~get_params:Eliom_parameter.unit ()
let myscript () = "Here is my amazing result"
let () =
Mysite_app.register
~service:main_service
(fun () () ->
Lwt.return
(Eliom_tools.F.html
~title:"mysite"
~css:[["css";"mysite.css"]]
Html5.F.(body [
h2 [pcdata "Welcome from Eliom's distillery!"];
p [pcdata (Printf.sprintf "My script gives the return function : \"%s\"" (myscript ()))]
])))
(Please note that let application_name = "mysite" must follow the name that you gave to eliom-distillery. If it's not the case your javascript won't be linked)
Let's compile again :
make test.byte
Now at localhost:8080 you can read :
My script gives the return function : "Here is my amazing result"
The result of the script has been included !
Going further
You can also define myscript to be run in client side, take some Post/Get param, or communicate with the page in real time in only a few lines, but if you want to learn more about that just read the ocsigen tutorial !
Interface with Nginx
I'm not sure you really need to interface it with Nginx, since ocsigenserver is supposed to run as an (http) serveur, but if needed you can always put ocsigenserver behing a Nginx serveur by using reverse-proxy (or the reverse thing, you can serve Nginx from ocsigenserver, read the ocsigenserver manual for more details).