Ruby : How to make a HttpRequest - http

I'm still new in ruby, please help.
I'm trying to make a http request in my standalone ruby script.
#!/usr/bin/ruby
require 'rubygems'
require 'net/http'
...
class someClass
...
def get_ruby_doc
request = HttpRequest.new(:get, 'http://www.ruby-doc.org/')
response = request.perform!
puts response.succeeded?
puts "yeah"
end
...
when I run the script, I get this error:
Uncaught exception: uninitialized constant someClass::HttpRequest
Can you please let me know what did I miss? Thanks.
I also try to do the same in rails console, same error.

You could try using rest-client
gem install rest-client
http://rubydoc.info/gems/rest-client/1.6.7/frames

Related

How to test if url accepting query parameters using pytest-djnago

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)

How do you get Deno to use the DENO_AUTH_TOKENS environment variable?

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

Symfony phpunit undefined method Kernel::bootstrapEnv()

After installing PHPUnit following :
https://symfony.com/doc/current/testing.html
# In bin/phpunit
App\Kernel
To its path in my project. I get the error :
Call to undefined method My\Bundle\Path\Kernel::bootstrapEnv()
When I run bin/phpunit
Can anyone help me understand the reasons it's behaving this way? I'm starting to believe, the bin/phpunit script has not been updated for Symfony 4.
Thank you!
Try to comment this 3 lines in your bin/phpunit file :
// $classLoader = require dirname(__DIR__).'/vendor/autoload.php';
// App\Kernel::bootstrapEnv('test');
// $classLoader->unregister();

appengine python remote_api module object has no attribute GoogleCredentials

AttributeError: 'module' object has no attribute 'GoogleCredentials'
I have an appengine app which is running on localhost.
I have some tests which i run and i want to use the remote_api to check the db values.
When i try to access the remote_api by visiting:
'http://127.0.0.1:8080/_ah/remote_api'
i get a:
"This request did not contain a necessary header"
but its working in the browser.
When i now try to call the remote_api from my tests by calling
remote_api_stub.ConfigureRemoteApiForOAuth('localhost:35887','/_ah/remote_api')
i get the error:
Error
Traceback (most recent call last):
File "/home/dan/src/gtup/test/test_users.py", line 38, in test_crud
remote_api_stub.ConfigureRemoteApiForOAuth('localhost:35887','/_ah/remote_api')
File "/home/dan/Programs/google-cloud-sdk/platform/google_appengine/google/appengine/ext/remote_api/remote_api_stub.py", line 747, in ConfigureRemoteApiForOAuth
credentials = client.GoogleCredentials.get_application_default()
AttributeError: 'module' object has no attribute 'GoogleCredentials'
I did try to reinstall the whole google cloud but this didn't work.
When i open the client.py
google-cloud-sdk/platform/google_appengine/lib/google-api-python-client/oauth2client/client.py
which is used by remote_api_stub.py, i can see, that there is no GoogleCredentials class inside of it.
The GoogleCredentials class exists, but inside of other client.py files which lie at:
google-cloud-sdk/platform/google_appengine/lib/oauth2client/oauth2client/client.py
google-cloud-sdk/platform/gsutil/third_party/oauth2client/oauth2client/client.py
google-cloud-sdk/platform/bq/third_party/oauth2client/client.py
google-cloud-sdk/lib/third_party/oauth2client/client.py
my app.yaml looks like this:
application: myapp
version: 1
runtime: python27
api_version: 1
threadsafe: true
libraries:
- name: webapp2
version: latest
builtins:
- remote_api: on
handlers:
- url: /.*
script: main.app
Is this just a wrong import/bug inside of appengine.
Or am i doing something wrong to use the remote_api inside of my unittests?
I solved this problem by replacing the folder:
../google-cloud-sdk/platform/google_appengine/lib/google-api-python-client/oauth2client
with:
../google-cloud-sdk/platform/google_appengine/lib/oauth2client/oauth2client
the one which gets included in the google-api-python-client folder now has the needed Class: GoogleCredentials in the client file.
Then i had a second problem with the connection and now i have to call:
remote_api_stub.ConfigureRemoteApiForOAuth('localhost:51805','/_ah/remote_api', False)
note, the port changes every time, the server gets restarted.
Answering instead of commenting as I cannot post a comment with my reputation -
Similar things have happened to me, when running these types of scripts on mac. Sometimes, your PATH variable gets confused as to which files to actually check for functions, especially when you have gcloud installed alongside the app engine launcher. If on mac, I would suggest editing/opening your ~/.bash_profile file to fix this (or possible ~/.bashrc, if on linux). For example, on my Mac I have the following lines to fix my PATH variable:
export PATH="/usr/local/bin:$PATH"
export PYTHONPATH="/usr/local/google_appengine:$PYTHONPATH
These basically make sure the python / command line will look in /usr/local/bin (or /usr/local/google_appengine in the case of the PYTHONPATH line) BEFORE anything in the PATH (or PYTHONPATH).
The PATH variable is where the command line checks for python files when you type them into the prompt. The PYTHONPATH is where your python files find the modules to load at runtime.

Grunt : JASMINE is not supported anymore

i created an angular application with yeoman, when i executed grunt command i got the following error
Running "karma:unit" (karma) task
WARN [config]: JASMINE is not supported anymore.
Please use `frameworks = ["jasmine"];` instead.
WARN [config]: JASMINE_ADAPTER is not supported anymore.
Please use `frameworks = ["jasmine"];` instead.
WARN [config]: LOG_INFO is not supported anymore.
Please use `karma.LOG_INFO` instead.
ERROR [config]: Config file must export a function!
module.exports = function(config) {
config.set({
// your config
});
};
how do i solve this error ?
It's just those two predefined terms (JASMINE and JASMINE_ADAPTER)
that should not be used any more. All you have to do is open the
config file ./config/karma.conf.js and comment out those terms and add
frameworks = ["jasmine"];.
Via Yasuhiro Yoshida
apart from #sheplu's answer, there are additional changes that need to be done in karma.conf.js, you can see it in https://gist.github.com/sivakumar-kailasam/6421378
this gist solves your problem of 'Config file must be a export a function!'
The official docs has these changes as well http://karma-runner.github.io/0.10/config/configuration-file.html

Resources