Is there good information on how to use the Python fixture module with Google App Engines New DB?
It seems there are a few problems, such as:
obj.delete() on teardown (in ndb it's obj.key.delete())
It is not intuitive how to set up nested StructuredProperty elements.
Are there workarounds to permit the Fixture module to work with ndb, or an alternative fixture system that would work with ndb?
Thank you.
I'm guessing that fixture's GoogleDatastoreFixture class intercepts the Datastore operations at the ext.db module level. Since NDB has a different API it needs changing. Perhaps you can contribute a GoogleNdbFixture class. Or perhaps the right thing to do would be to intercept things at a lower level -- again, something you might take up with fixture's author and see if there's a way you can help.
Did you consider using Testbed? It setups GAE service stubs appropriately, so you can test against datastore (and other services) and it will tear down all your datastore writes after each test.
To create fixtures for your tests, you just directly put some entities into datastore in setUp() method. And you can use NDB API to put fixtures and in tests if you like.
Related
I'm an experienced SWE but sort of new to modern web development. I'd like to build a demo/prototype website for a startup idea with minimal time. I'd like to have the frontend tied to a backend DB store up front so it's fully functional. I'd like advice on the best stack to use. I'd like a python backend, and I'm planning on React for the frontend, with GraphQL (unless this is a dumb idea for a prototype... I'd like to learn about it though.)
I feel like there is a ton of redundancy in terms of data object models. I can make a GraphQL schema (I was thinking of using ariadne + FastAPI) but then I still need to build DB tables, or create an object model e.g. in Django. And then of course there is all the React code to make forms to edit stuff. My app will require a significant amount of data entry on the website to set up users and lots of metadata. I built a ton of forms etc in React, backed by Apollo client.
Any suggestions -- am I on the right track or is there a quicker way to a prototype?
Are there any tools that autogenerate some of this code? E.g., I expected I could start with a GraphQL schema and there would be a way to auto-extract a reasonable object model like that used in Django. Or conversely, maybe I could build DB tables and auto-gen a basic GraphQL service. If these don't exist it seems like an opportunity, since I'm seeing so much redundancy... and in prototype phase I don't care about keeping the DB and the API totally independent; I'm okay to trash the DB over and over and re-generate until I get to a beta state, etc.
Hey guys kind of a n00b in App engine and I have been strugling with this is there a way that I can add/bulk default data to Data Store.
I would like to create catalogs or example data, as well user or permission. I am not using the default App engine user instead I am using webapp2 User auth session base model.
Thanks
You can use the bulkloader: https://developers.google.com/appengine/docs/python/tools/uploadingdata
Or upload data to the blobstore and move it to the datastore.
This is a large topic but, I am using Java code running in task queues to do this.
Much easier to create random test and demo data through code.
Much more friendly to unit testing.
This requires no dependencies. It is just code running and accessing the datastore.
Sometimes easier to manipulate the datastore through code instead of scripts when logic is involved in the changes.
Allows us to upload new task definitions (a Java classes) embedded in a new app version. Then, we trigger the tasks executions by calling a servlet URL. These task classes are then removed from the next app version.
And using tasks, you get around the request execution timeout. If a task is long running, we split it as sequential tasks. When a task completes, it queues the next one automatically.
Of course, this requires a fair amount of coding but is really simple and flexible at the same time.
I have a model called "Category" in my app in GAE.
This model simply contains a name and it's parent category, and this won't be changed frequently after the website go online.
I'd like to know what is a better way to put these model instances in the beginning?
I now only know to execute (category.put()) in a webapp.RequestHandler by issuing a http request. But I suspect there is a proper way to do this.
Thanks!
You can use the remote API to connect to your datastore in a shell and add data as required.
Or, if it's a huge amount, you could think about using the bulk loader - but I suspect that the remote API will be more suitable.
I am trying to transfer data in the form of objects between a gwt client and the app engine server. The objects i transfer need to be persistable (a blog comment for example). as it turns out AppEngine is uncomfortable to include those persistable objects (annotated as #PersistenceCapable) in the gwt module, because the gwt client cant store such date. Also the gwt client cant call a remote procedure with objects which are not concrete. So there is not the option to define interfaces for accessing those classes.
In short:
GWT Client cant work with interfaces, but also not with persistable annotated classes.
My Question is: how can i design an application which transfers stored data between the gwt client and the appengine. This is currently a real problem for me. it seems to me as if the only option is a DataTransferObejct which is just pure sensless code doing the exact thing the data-objects do: storing data.
I used the appengine.datastore Key for the id's of the classes.
Any suggestions ? Or am i getting something wrong ?
What version of GWT are you using? I regularly share data between GWT and GAE using serializable POJOs annotated PersistenceCapable. If you are using Key key, use Long id instead to get it working.
I try to get an application running which should interact with a server via RPC (JDO in Google DataStore). So I defined a persistent POJO on the server-side to get it put in the datastore via the PersistenceManager (as shown in the gwt rpc tuts). Everything works fine. But I am not able to receive the callback POJO on the client side because the POJO is only defined on server-side. How can I realize it, that the client knows that kind of object??
(sry for my bad english)
Lars
Put your POJOs in a separate package/directory (e.g. com.example.common) and then add source declaration to your GWT module descriptor (xyz.gwt.xml):
<source path="common"/> //relative to your xyz.gwt.xml location
GWT compiler will then also compile POJOs and they will be seen by your other GWT code.
Edited:
#Lars - now I understand your problem. As I see it you have several options:
If possible use Objectify instead of JDO. Objectify uses pure POJOs and they play nicely with GWT. I use this in my projects. One nice thing that Objectify gives you is #PostLoad & # PrePersist on methods to run some code before/after POJOs are loaded/saved to datastore. I use this to handle serialization of GeoPoint for instance.
Use JDO and make copies of your domain classes. This is a pain but it would work. Use 'transient' java keyword in your server JDO classes to exclude fields you do not want to RPC.
Edit #2: There is a third option that you might prefer:
Create "fake" JDO annotation classes using super-sourcing. This is a common technique to replace classes with a GWT version. Described here: http://fredsa.allen-sauer.com/2009/04/1st-look-at-app-engine-using-jdo.html
You can use DTO(stackoverflow, moar) for transferring data to client.
Basic sample here (method getTenLatestEntries() in your case).
Or you can use some third-party libraries like objectify and stop worry about making DTO`s.