I've recently implemented two-factor auth in a django application. I used a third-party package for it, which is well-tested already. I want to write unit tests for my code, but it seems silly to test things which are really just their package. I feel really odd writing larger-scale selenium tests for the login process, especially e.g. scanning a QR code. Is the answer that if I'm not doing anything new with the code, just dropping in the existing library, that I can't effectively write tests for it? (because it's unnecessary?)
Related
I'm trying to integrate backend code into a Wix site. Im not too picky about how I want to do this, or what language to write in (ideally, I have a locally-hosted Java code that I'd love to simply call). I wouldn't mind re-writing it in JavaScript though, or another language. But before I decide that I'm confused about my options. I can code but I'm new to the concepts like modules, APIs, & servers.
According to my research, back-end code with Wix is supposed to be easy (or at least do-able and not THAT complicated)....
From this webpage https://support.wix.com/en/article/corvid-calling-server-side-code-from-the-front-end-with-web-modules,
"Web modules are exclusive to Corvid and enable you to write functions that run server-side in the backend, and easily call them in your client-side code. With web modules you can import functions from backend into files or scripts in public, knowing they will run server-side. Corvid handles all the client-server communication required to enable this access."
And from this: https://www.sitepoint.com/what-is-wix-code/
"It’s serverless: All this added functionality comes in a serverless environment that lets you get your work done without any of the normal full-stack development headaches.
Just code and go: Wix Code has a built-in, online IDE and backend so you can just add the code you need to your page or your site, publish, and you’re live."
So, I thought they have a backend IDE where I can write backend code directly, or I could call my Java program. But, as I tried doing this and finding tutorials, it seems I can really only do this by calling a public API from the backend...?
https://youtu.be/tuu0D1izrUU
But ive also read (and someone who supposedly has done it before told me this) that Wix integrates with node.js, which is a backend version of JavaScript.
Can I use a Wix domain for a NodeJS app?
But, when I go into my Wix site I cannot find any option for using Node JS, and doing research on that gives me no useful results.
So, I'm thoroughly confused on what the capabilities are here. Can someone help me make sense of this?
Why are there no tutorials showing explicit code in the Corvid backend module? What's stopping me from simply writing my Java program there in a module? Do I really need an API endpoint to call and pass to the front end?
Is Node JS supported or not - has anyone done this before?
Also, in one link above they said everything is "serverless". But if I have to set up my own API endpoint won't I need to set up my own server??
There are basically two ways to go about this, which you seem to have already discovered.
Write your backend code in your Wix site. Indeed, the backend is built on Node.js as you can see here. Using this approach you will have to use JavaScript. As you seem to have found, you write this code in the Backend section of your site in a Web Module. Pros: you don't need to worry about managing a server and all your code is in one place.
Expose your already existing Java code as an API that your Wix site can call using the wix-fetch API. Pros: you don't need to rewrite your code.
I'm a newbie, I'm afraid, and have newbie questions.
I have used python for simple scripts and automation for a while, but am challenging myself to go deeper by contributing to some open source projects on GitHub.
It's been fun, but also nerve-wracking to make dumb mistakes in such a public environment.
Sometimes one of my changes causes an error that is caught by one of the automated tests that the GitHub project runs when a PR is submitted. I'd like to catch those myself, if possible, before submitting the PR. Is there a way for me to run the same build tests locally on my own machine?
Any other best practice suggestions for doing open-source contributions without asking for too much time/help from maintainers is also appreciated.
Running the entire build locally doesn't really make sense. Especially not for just the tests.
Github and most open source repositories have a contribution guidelines. Github especially has CONTRIBUTING.md to allow repo owners demonstrate how to contribute.
For example:
CPython has a testing section on their readme.
Django has a contributing section and how to run the test suite in their readme.
Most proper open source projects would have explanations on how to run tests/builds locally.
Do not, however feel ashamed over something like broken tests. This is what version control systems are for. Make 10 mistakes, fix the bug/add the feature, make 20 mistakes afterwards. You can just make typos and fix them in the next commit. It doesn't matter. Just rebase your branch after you added what you needed to add and you are good to go. Making mistakes is nothing to be ashamed especially since we have tools to fix those mistakes easily.
Why not act?
Act is OK. It is a nice tool that I myself use. But you don't need to run entire workflow just for tests when you can run tests without it, and it is not really a small tool.
The problem with act is that it is only for github actions, which is only one of the many CI tools.
Travis, CircleCI, Jenkins, ...
It's better to just read the project you are contributing to and follow their guidelines.
Act works most of the time but is a bit limited on the types of images it can use.
I really feel you on this one, would be nice if there were tools for this :/
I'm theory crafting a Python service which will manipulate domain joined machines into running tests as part of a suite. Details of requirements
We must be logged in as a domain user, and we must not have the automatic login enabled
We need to reboot machines a few times, so it's a requirement for this to be sustainable
I'm wondering if it's possible to, from a Python service, somehow convince Windows to log us in? Presumably a Python service runs in Session0, as does Microsoft's Hardware Certification Kit? If that's capable of doing it, Python should also be (so far as I can see).
Any suggestions most welcome, I've got a suspicion there's a cheeky Windows API call that does this, but can't seem to find it anywhere.
So I've found a way to do it from a Windows service (written in C++) and presumably the ctypes library will permit me to use it.
Simple as using LogonUser from Win32API so far as I can see. Yet to actually set up and test it but it does seem to be exactly what I need. The difficulty being that session0 can only be accessed once logged in or via some remote debugging, so getting something like this working is no easy feat.
I'm working on a Python project, currently using Django, which does quite a bit of NLP work in a form post process. I'm using the NLTK package, and profiling my code and experimenting I've realised that the majority of the time the code takes is performing the import process of NLTK and various other packages. My question is, is there a way I can have this server start up, do these imports and then just wait for requests, passing them to a function that uses the already imported packages? This would be much faster and less wasteful than performing such imports on every request. If anybody has any ideas to avoid importing large packages on every request, it'd be great if you could help me out!
Thanks,
Callum
Django, under most deployment mechanism, does not import modules for every request. Even the development server only reloads code when it changes. I don't know how you're verifying that all the imports are re-run each time, but that certainly shouldn't be happening.
I'm investigating Google refine to speed up some of my data work -- never used it before this week, but I like a lot of what I see.
My biggest question so far is whether it's possible to call external python functions from Refine. I know you can call jython internally, but that doesn't provide access to C-based python libraries (e.g. lxml), and I have scripts elsewhere that I'd like to integrate, without lots of copy-paste or rewrite hassle.
What options are there for doing this in Refine? I'm willing to get creative -- I just want a stable, re-usable solution.
As Google Refine Wiki says:
lxml will NOT work in Jython, since lxml has C bindings for CPython (regular Python), hence will not work in Refine which is Jython / Java only, and has no CPython interpreter built-in
But you can try Google Refine Python Client Library to create projects and manipulate your data programmatically.
I'm going to mark reclosedev's answer as accepted, but there's still a litle more to the story.
The other answer to this question is that you can set up your own python-based API. For this project, I was able to set up a django app running on a local server. It only took an hour or so to build the API to my existing library.
More hassle than I'd have liked, but it fit the bill for this project without soaking up too much time.