Testing REST API [closed] - python

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 8 years ago.
Improve this question
I am developing a REST API on Django. What do other uses to craft json msgs to test? Is there a browser plugin, python lib, curl, something else?

If you want to write Python try using the Requests library to do some basic testing from the client side. There is a CLI tool based on this called httpie that you might also want to check out. You can also use curl for testing if you prefer the command line but it is probably easier to use Requests in the long run from Python code if you are dealing with a more complex API or want to do anything repeatedly.

The Python 2.6+ standard library includes the json module which should help you create some JSON objects to do testing.
Here is a link to the documentation: http://docs.python.org/library/json.html

JSON is simple because you have a choice of JSON libraries to use in Python. Before you choose, read this article http://deron.meranda.us/python/comparing_json_modules/ because I suspect that you will find it very useful to use a strict parser for your testing. The benchmarks may be outdated, but the strict validating parsers are unlikely to have been superceded.
Write some Python code that acts as a web client, using a library like httplib2 to access your app. If your like a lot of people and all of your JSON is a single Javascript object, then you could keep your test data in any old database such as SQLite, read it into a Python dict, and encode it into a JSON object with one function call. Then for the actual test, after you receive a JSON reply, decode it into a dict and you have a normal Python object to use for comparisons.

Related

Is there a python binding to the Berkeley DB XML database? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 2 months ago.
Improve this question
I'm trying to migrate some perl code to python and it uses Sleeypcat::DbXml 'simple' to get read access to a .dbxml file, creates a XmlManager, calls createQueryContext, openContainer and query to get an XmlValue. I have found https://pypi.org/project/berkeleydb/ to support the Berkeley DB in general, but it has no mention of this XML layer. Is there an existing API I can use in python 3?
Berkeley dbxml does come with a Pyhon bindings. I ended up having to make modifications to the SWIG interface files to get it to run with Python3. If you are interested in building for a recent Python, you will need to make some modifications to the Python interface file. Specifically, you have to
redefine PYSTR_* macros to use unicode strings
make changes to the initialization code to return the module
update the Python 3 iterator code to use __next__ via a %rename pragma
potentially add code for missing objects an changed interfaces, e.g. I added an XmlResultsIterator, and added som code to XmlManager to let me reindex containers.
You then need to regenerate the swig interface and recompile the module. I don't know StackOverflow's policy on posting patches, but if it's allowed I'd be happy to post the patches that I created for dbxml 6.1.4 and Python 3.9 for you. Getting it all compiled is a little bit of work, but very doable.
Berkeley DB and Berkeley DB XML are two different products. My python bindings (legacy "bsddb3" and current "berkeleydb") only interface with Berkeley DB.
I am not aware of any Python bindings for Berkeley DB XML.
I am a freelance with commercial contracts, if that option would be useful to you.

Looking for example or documentation for wikidump python lib [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 8 years ago.
Improve this question
I stumbled upon the wikidump python library, which I think suits me just fine.
I could get by by looking at the source code, but I'm new at python and I don't want to write BS code as the project I need it for is kind of important to me.
I got the 'wiki-SPECIFICDATE-pages-articles.xml.bz2' file and I would need to use that as my source for single article fetching. Can anyone give me some pointers as to properly achieve this or, even better, point at some documentation? I couldn't find any!
(p.s. if you got any better and properly doc'd lib, please tell me)
Not sure if I understand the question, but if you have the Wikipedia dump and you need to parse the wikicode, I would suggest mwparserfromhell lib.
Another powerful framework is Pywikibot, that is the historic framework for bot users on Wikipedia (thus, it has many scripts dedicated to writing pages, instead of reading and parsing articles). It has a lot of documentation (though, sometimes obsolete) and it uses MediaWiki API.
You can use them both, of course: PWB for fetching articles and mwparserfromhell for parsing.

python twitter libraries - which one to use? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 8 years ago.
Improve this question
I want to extract information from Twitter using Python. There is a page with several twitter libraries:
https://dev.twitter.com/docs/twitter-libraries
Now I am not sure which one to use. Does anyone has experiences with them? I tried Twython and it is easy to handle but are the others worth a try too?
Tweepy is worth a go as it quite conveniently wraps the User, Tweet, Status etc... into easily accessible Python objects. The other one I've used is plain python-twitter, which does make interfacing easier, but is closer to raw bones JSON queries, and you have to remember the correct URLs to query. IIRC, both support standard interactions and the ability to use the tracking and searching engines.
Have a look on http://pypi.python.org/pypi?%3Aaction=search&term=twitter&submit=search for other options - but it really depends what you want to do and how. I've had success with the aforementioned but I can't recommend any ideal Python twitter library.
I have spent the past few weeks working with Twitter-Python -- the one hosted through Google. I really like the library, although I have not used tweepy or twython. I am pretty new to Python and I have find using Twitter-Python to be very intuitive and easy -- the library has tons of methods to return pretty much any data point you want. It can be a bit daunting since it's a lot of code, but once you get familiar with the library I think it's really simple to use. As the other users have noted though, Twitter-Python doesn't have a streaming API (as far as I know), so if you need that use tweepy.
Depends on what exactly you want to do. Twython is good and is regularly updated as well. Besides that,
Python Tweeter should take care of most of the stuff you would want to achieve. Plus, it's easy and fun to use.
If you need some sort of streaming API support, Tweepy is what you should go for.

Python test "framework" for testing input files and their outputs [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 6 years ago.
Improve this question
I'm writing end-to-end tests for my tool, which is written in Python. The tool reads a file as input. I want to test its exit code, and its output.
This is a fairly common idiom, and I've seen it done in several ways. In the PHP project, each test is a file, and has lines like: INPUT:, EXPECTED:, EXPECTED_REGEX:, etc. In my own phc project, each file is a normal source file, but with a comment added to the top, which includes keywords like EXPECTED. I think I had copied that off gcc which uses a much more complex tool written in tcl.
Are there frameworks, libraries, etc, that do this in Python? It should:
read the source file
parse special keywords (or similar) corresponding to expected output, exit code, words/regexes it expects to find or not find,
check that the output is correct.
While it doesn't seem hard in theory, I recall lots of edge-cases (esp involving escaping) when implementing this before, and would rather not reinvent the wheel.
The robot framework might be helpful. It is a keyword driven functional testing tool implemented in python and can be extended with pythion or java.
see: http://robotframework.googlecode.com/svn/tags/robotframework-2.5.4/doc/userguide/RobotFrameworkUserGuide.html
There are a number of built in libraries that you might be able to apply to solve your problem, including a OperatingSystem library for working with files etc. and a Strings library for working with strings:
http://robotframework.googlecode.com/svn/tags/robotframework-2.5.4/doc/userguide/RobotFrameworkUserGuide.html#standard-libraries
There is also a http://pythonpaste.org/scripttest/ library by Ian Bicking.
Since the implementation of file io is system dependent, why not mock out the file reading and writing using StringIO:
http://docs.python.org/library/stringio.html
and then test the bulk of the logic (reading from a file, doing some stuff, writing to a file) in python?
Then, perhaps you could have one end to end test for basic sanity by having a separate python file call out to the script using the commands module or something similar where you are calling out to it as another process:
http://docs.python.org/library/commands.html
Using that you could get both the output, and the status.

What is a good configuration file library for c thats not xml (preferably has python bindings)? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 5 years ago.
Improve this question
I am looking for a good config file library for c that is not xml. Optimally I would really like one that also has python bindings. The best option I have come up with is to use a JSON library in both c and python. What would you recommend, or what method of reading/writing configuration settings do you prefer?
YaML :)
If you're not married to Python, try Lua. It was originally designed for configuration.
You could use a pure python solution like ConfigObj and then simply use the CPython API to query for settings. This assumes that your application embeds Python. If it doesn't, and if you are shipping Python anyway, it might make sense to just embed it. Your C .exe won't get that much bigger if it's a dynamic link, and you will have all the flexibility of Python at your disposal.
Despite being hated by techies and disowned by Microsoft, INI files are actually quite popular with users, as they are easy to understand and edit. They are also very simple to write parsers for, should your libraries not already support them.

Categories