import static org.assertj.core.api.Assertions.assertThat not suggested by IntelliJ - unit-testing

Newbie, big project, copy/paste unit testing task.
Using IntelliJ Ultimate, when trying to import assertThat(), I get to choose only between:
import static com.mysema.commons.lang.Assert.assertThat;
or
import static org.hamcrest.MatcherAssert.assertThat;
But what i need as an option =>
import static org.assertj.core.api.Assertions.assertThat;
Co-workers have no problem with imports on the same project on their machines.
No error, when i just copy/paste import from another class. But IntelliJ doesn't suggest imports I need!
Any ideas?
Tried to:
invalidate caches
restore default settings
reload all gradle projects
delete .gradle and .idea folders
clean/build project directory
restart pc...
No result

File -> Project Structure -> Global Libraries
Add - New Global Library from Maven -> assertj.core.
Choose version. Apply.

Related

ModuleNotFoundError: No module named 'config.wsgi'

I'm trying to run a .py file and in the file I have this import
from config.wsgi import *
import os
from django.template.loader import get_template
from weasyprint import HTML, CSS
from config import settings
The whole project works, if I set runserver, the project starts without any problem, but this file does not work. The structure of the project is as follows
NombreDelProyecto
--app
---config
----__init__.py
----asgi.py
----settings.py
----wsgy.py
----db.py
---core
----general
----login
----user
----archivodetest.py
the case as I say the project works, but in the views of the applications that I have been doing to put imports I get in red underlined but as I say it works for example:
from core.general.forms import ActividadForm
That comes out in red, if I put in front of the core, app.core as follows
from app.core.general.forms import ActividadForm
it does not show red but the project does not work and I get the following error
from app.core.general.forms import ActividadForm
ModuleNotFoundError: No module named 'app'
I understand that it is the routes or something I did wrong from the beginning, please could someone help me.
Thank you very much.
I tried adding the route, changing the app's route in settings, but to no avail.
You've named the file wsgy.py but it needs to be wsgi.py.
Rename your file in config and retry.
To your question, I think its because you're missing the __init__.py file in the general app.
If you haven't already go one, you'll likely need to have add the same again in your core app too.
You probably manually created all of these files and structures I suspect, and if that's the case, please take a look at the documentation regarding creating new apps inside a django project.
If you go a bit further up the page, it will also tell you how to create the initial django project structure with a command.
Thank you very much for the answer, I managed to solve it after a lot of testing.
There are two ways, open the project again from the app folder (I had it open in the ProjectName folder).
Or as a second option in pyCharm on the left where the project folders are, I went to the app folder (which is the root) and right clicked and in the menu, Mark Directorie as - Sources root. Then my problem is fixed.
I had all the arcvhiso init.py, and where I put the wrong name wsgi.py is that I wrote it wrong here but in the project it was right.
Thank you very much for the help.

Autocomplete import paths WebStorm

I have a create-react-app and I have NODE_PATH = src/ in my .env file to make import paths of common components simpler. But WebStorm isn't recognizing it and wont autocomplete any of them like it does if I were to import ../../Common/foo or how it autocompletes node modules import Button from 'material-ui/Button always gives me a long list of material-ui components and helps make sure I don't have any typos.
Is there a way I can configure this in WebStorm?
You can try setting NODE_PATH in default Node.js run configuration to get it respected - see https://youtrack.jetbrains.com/issue/WEB-19476#comment=27-1255547:
in Run | Edit configurations, expand Defaults node, select Node.js
in default Node.js run configuration, press ellipsis button next to Environment variables: field
add NODE_PATH variable there, specify a full path to src folder as a value
in Project tool window, mark src folder as Resource root
reopen the project

Absolute Paths with Gulp Mocha and Browserify

I have a project which is using Browserify and ES6 to handle importing and defining packages. The project is using absolute paths using the 'paths' option when building with Gulp-Browserify.
This works fine for the source code, but now I am attempting to write tests with Mocha and run them using gulp-mocha and this is causing problems. Mocha is expecting relative paths, but if I give it a relative path to a file that has other imports using absolute paths, testing will fail with a MODULE_NOT_FOUND
error.
for example
Mocha Import at test/actions/user.js:
import createUser from '../../src/actions/user';
...
Source Import at src/actions/user.js:
import CREATE_USER from 'constants/use
...
will cause a MODULE_NOT_FOUND_ERROR
What I'm wondering is if there is any way to set an absolute path list in mocha similar to how you can for browserify?
You can use app-require-path. Just install it as a dev dep and add the following two files:
test/mocha.opts
--require test/_bootstrap.js
test/_bootstrap.js
require('app-require-path')(__dirname + '/..');
And that's it. You can change the path in _bootstrap.js to whatever you want. You can also add multiple paths. It's up to you.

django dev on mac having to explicitly name full path

After a long time away from an app i wrote in Django and didn't complete, I've come back to it on a new Mac.
I'm struggling to get the code to refer to the apps and the files within them without the explicit path. For instance:
from myproject.app.file import object
Whereas I remember not having to use myproject every time.
Is this something that has changed? I seem to remember being about to add to the path in manage.py which is called every time you run the dev server, but this hasn't worked this time.
sys.path.append /path/to/myproject
Should that fix the issue I'm having?
I started with a simple answer and it grew into more details on how to add subdirectories of your project to python path. Maybe a bit off-topic, but it could be useful to you so I'm pushing the post button anyway.
I usually have a bunch of small re-usable apps of mine I keep inside my project tree, because I don't want them to grow into independent modules. My projet tree will look like this:
manage.py
myproject/apps
myproject/libs
myproject/settings
...
Still, by default, Django only adds the project root to python path. Yet it makes no sense in my opinion to have apps load modules with full path:
from myproject.apps.author.models import Author
from myproject.libs.rest_filters import filters
That's both way too verbose, and it breaks reusability as I only use absolute imports. Not to mention if I someday build an actual python package out of some of the libs, it will break.
So, I took the following steps. I added the relevant folders to the path:
# in manage.py
root = os.path.dirname(__file__)
sys.path.append(os.path.realpath(os.path.join(root, 'myproject', 'apps')))
sys.path.append(os.path.realpath(os.path.join(root, 'myproject', 'libs')))
But you must ensure those packages cannot be loaded from the root of the project, or you will have odd issues as python would load another copy of the module. For instance, isinstance(libs.foo.bar(), myproject.libs.foo.bar) == False
It's not hard though : just remove __init__.py from the folders you add to the path. That will make sure they cannot be descended into from the project.
Also, Django's discover runner will not descend into those paths unless you specify them manually. That may be fine with you (if every module has its own test suite). Or you can extend the runner, so it knows about this: sample code.

The right way to add unique libraries to heroku (django app)

I'm trying to deploy a django app to heroku.
I have several python libraries which are not on PyPi and so I can't just declare them in requirements.txt file
In local development I've used:
import sys
sys.path += [os.path.dirname(os.path.dirname(__file__))+"\\project-name\\lib"]
inside manage.py and it works fine there.
Obviously it doesn't work on heroku and I get import errors.
What is the recommended way to add libraries like that on heroku?
Thanks.
One way to do it is include the libraries in the repository itself, from which you can import them. That means simply moving the actual folder for each library into your main Django project folder.
- DjangoProject
- AppFolder1
- AppFolder2 ...
- python-library1
- python-library2
When the repository is pushed to Heroku your libraries will be pushed as part of the project.
From here, your imports of these libraries within a view/model etc within any app's folder would
import python-library1
from python-library2 import a_function, a_class
The reason why I suggest the directory structure above is that, most likely, you would not have go back and change any import codes.
If you have a large number of libraries and would like to keep the direcory structure simpler, simply create a folder with a name such as "importables" in the main DjangoProject folder and change the import statements to something such as...
from importables import python-library1
from importables.python-library2 import a_function, a_class
It's not exactly beautiful, but a quick way to get the job done. If you aren't sure where the libraries you'd like to include are located, there's a few ways to quickly see their location using Python (How do I find the location of Python module sources?).