Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 months ago.
Improve this question
I am exploring ways on bash as well as on Python to print out values onto an ASCII art for improving the readability.
The one difficulty is to update values without changing the format of the art.
The ascii art looks something like this:
========================================================
| | | | | |
| | | | | |
| CPU | | GPU | | HDD |
| | | | | |
| | | | | |
| ${CPU_W}W | | | | |
| ${CPU_Freq}MHz| | | |Avail Mem${size}G|
| | |${GPU_W}W | | Used Mem${size}G|
| | |${GPU}Mhz | | |
| | | | | |
| | | | | |
| | | | | |
| | | | | |
========================================================
So far, I was able to prevent the format from changing on Bash. But doing this, is not allowing me to change the values.
cat << "EOF"
========================================================
| | | | | |
| | | | | |
| CPU | | GPU | | HDD |
| | | | | |
| | | | | |
| ${CPU_W}W | | | | |
| ${CPU_Freq}MHz| | | |Avail Mem${size}G|
| | |${GPU_W}W | | Used Mem${size}G|
| | |${GPU}Mhz | | |
| | | | | |
| | | | | |
| | | | | |
| | | | | |
========================================================
EOF
Without cat << "EOF" ...ascii art.... EOF, I can update the values but the format keeps changing .
Is there anyway to keep the same format even with the values changing? Thanks in advance.
I'm not exactly sure what you're trying to achieve... so?
f = """
========================================================
| | | | | |
| | | | | |
| CPU | | GPU | | HDD |
| | | | | |
| | | | | |
|{cpuW:>15}| | | | |
|{cpuF:>15}| | | |Avail Mem{ramA:>8}|
| | |{gpuW:>10}| | Used Mem{ramU:>8}|
| | |{gpuF:>10}| | |
| | | | | |
| | | | | |
| | | | | |
| | | | | |
========================================================
"""
def main():
cpuW = 12.2
cpuF = 2354
gpuW = 15.2
gpuF = 789
ramA = 16.1
ramU = 12.2
d = {
'cpuW': f'{cpuW:.1f} W ',
'cpuF': f'{cpuF:d} MHz ',
'gpuW': f'{gpuW:.1f} W ',
'gpuF': f'{gpuF:d} MHz ',
'ramA': f' {ramA:.1f} GB',
'ramU': f' {ramU:.1f} GB',
}
out = f.format_map(d)
print(out)
if __name__ == '__main__':
main()
Output is:
========================================================
| | | | | |
| | | | | |
| CPU | | GPU | | HDD |
| | | | | |
| | | | | |
| 12.2 W | | | | |
| 2354 MHz | | | |Avail Mem 16.1 GB|
| | | 15.2 W | | Used Mem 12.2 GB|
| | | 789 MHz | | |
| | | | | |
| | | | | |
| | | | | |
| | | | | |
========================================================
In python, you can use the format and str.ljust method.
format(value[, format_spec])
Convert a value to a “formatted” representation, as controlled by format_spec. The interpretation of format_spec will depend on the type of the value argument; however, there is a standard formatting syntax that is used by most built-in types: Format Specification Mini-Language.
It depends on what you want the notation to be (e.g how many zeros, ecc...).
here is an example:
>>> characters = 10
>>> format(32,".2E").zfill(characters)
'003.20E+01'
>>> #first number is the minimum number of characters
>>> format(32,"{0}.2E".format(characters))
' 3.20E+01'
or, with fstrings:
>>> f"{32:.2E}"
'3.20E+01'
Example on how to use it in ascii art:
>>> def create_ascii_art(CPU_W,CPU_freq,GPU_W,
... GPU,Free_Mem,Used_Mem):
... CPU_W,CPU_freq,GPU_W,GPU,Free_Mem,Used_Mem = map(float,(CPU_W,CPU_freq,GPU_W,GPU,Free_Mem,Used_Mem))
... return f'''
...========================================================
...| | | | | |
...| | | | | |
...| CPU | | GPU | | HDD |
...| | | | | |
...| | | | | |
...|{CPU_W:12.2E}W | | | | |
...|{CPU_freq:12.2E}MHz| | | |Avail Mem{Free_Mem:7.3}G|
...| | |{GPU_W:8.2E}W | | Used Mem{Used_Mem:7.3}G|
...| | |{GPU:6.0E}Mhz | | |
...| | | | | |
...| | | | | |
...| | | | | |
...| | | | | |
...========================================================'''
>>> print(create_ascii_art(1,1,1,1,1,1))
output:
========================================================
| | | | | |
| | | | | |
| CPU | | GPU | | HDD |
| | | | | |
| | | | | |
| 1.00E+00W | | | | |
| 1.00E+00MHz| | | |Avail Mem 1.0G|
| | |1.00E+00W | | Used Mem 1.0G|
| | | 1E+00Mhz | | |
| | | | | |
| | | | | |
| | | | | |
| | | | | |
========================================================
The "format" does not change; the display width of the strings in the here document depends on the values of the variables. You'll want to make sure the values are padded to the expected width (or truncated, if necessary).
A slightly tortured way to accomplish this is to pad the actual values:
#!/bin/bash
:
printf -v CPU_W '%8s' "$CPU_W"
printf -v CPU_Freq '%11s' "$CPU_Freq"
printf -v GPU_W '%8s' "$GPU_W"
printf -v GPU '%6s' "$GPU"
printf -v size '%7s' "$size"
cat <<EOF
========================================================
| | | | | |
| | | | | |
| CPU | | GPU | | HDD |
| | | | | |
| | | | | |
| ${CPU_W}W | | | | |
| ${CPU_Freq}MHz| | | |Avail Mem${size}G|
| | |${GPU_W}W | | Used Mem${size}G|
| | |${GPU}Mhz | | |
| | | | | |
| | | | | |
| | | | | |
| | | | | |
========================================================
EOF
Probably a better solution altogether is to use printf directly to format the output. (Personally, I would perceive a notable reduction in my blood pressure if you removed at least half of the repetitive "ASCII art", which would somewhat tidy up the necessary code, too.)
We can't know what values these variables contain; if they are integers, maybe experiment with i instead of s for the printf format code, or correspondingly f or perhaps g for floating-point values.
If you need truncation, try %8.8 instead of %8, etc.
An altogether nicer approach is to use a library for producing this format. I can't recommend any particular one for Bash; for Python, look at tabulate.
I am trying to write Python code to request my vpn software to connect / disconnect upon certain conditions. I use HMA VPN and am running on Windows 10. Python 3.9.5.
The PyWinAuto module would appear to have the required functionality, but I cannot get it to work correctly. I'm sure it's my coding, not the module itself... ;)
I'm fairly sure I'm referring to the control incorrectly when I call it with the click() method, but can anyone suggest the correct approach, given the dump_tree that I have included? (I have tried tens of variations based based on the code snippets in the Getting Started guide, but no joy).
I'm looking to be able to toggle Button4 in GroupBox2, which is named either "Connect" or "Disconnect", depending on the current state of the VPN. I also want to be able to click Button5, "Change IP Address", but once I figure out one button, the other should be easy.
Any thoughts where I am going wrong?
My code snippet is as follows:
from pywinauto import Desktop, Application
Desktop(backend='uia').HMAVPN.dump_tree()
app = Application().start('C:\Program Files\Privax\HMA VPN\Vpn.exe', timeout=5)
dlg_spec = app.window(title='HMA VPN')
dlg_spec.AvastChromiumWindow.Pane2.Document.GroupBox2.Button4.click()
The resulting output is as follows:
Control Identifiers:
Dialog - 'HMA VPN' (L-149, T68, R551, B638)
['HMA VPNDialog', 'HMA VPN', 'Dialog']
child_window(title="HMA VPN", control_type="Window")
|
| Pane - 'AvastChromiumWindow' (L-149, T68, R551, B638)
| ['Pane', 'AvastChromiumWindowPane', 'AvastChromiumWindow', 'Pane0', 'Pane1']
| child_window(title="AvastChromiumWindow", control_type="Pane")
| |
| | Pane - '' (L-149, T68, R551, B638)
| | ['Pane2', '\ue01bPane', '\ue01bPane0', '\ue01bPane1']
| | |
| | | Document - ' Original IP 91.90.253.244 New IP 80.255.5.198 Original IP 91.90.253.244 Location Germany, Berlin ' (L-149, T68, R551, B638)
| | | ['\ue01b \ue014 \ue007 Original IP \xa0 91.90.253.244 New IP \xa0 80.255.5.198 \ue019 Original IP \xa0 91.90.253.244 \xa0 Location Germany, Berlin \ue005 Document', 'Document', '\ue01b \ue014 \ue007 Original IP \xa0 91.90.253.244 New IP \xa0 80.255.5.198 \ue019 Original IP \xa0 91.90.253.244 \xa0 Location Germany, Berlin \ue005 ']
| | | child_window(title=" Original IP 91.90.253.244 New IP 80.255.5.198 Original IP 91.90.253.244 Location Germany, Berlin ", auto_id="7211296", control_type="Document")
| | | |
| | | | GroupBox - '' (L-149, T68, R551, B104)
| | | | ['\ue01bGroupBox', 'GroupBox', '\ue01bGroupBox0', '\ue01bGroupBox1', 'GroupBox0', 'GroupBox1']
| | | | |
| | | | | Button - 'Preferences' (L-134, T76, R-114, B96)
| | | | | ['PreferencesButton', 'Preferences', 'Button', 'Button0', 'Button1']
| | | | | child_window(title="Preferences", auto_id="hma_title__preferences", control_type="Button")
| | | | | |
| | | | | | Static - '' (L-134, T76, R-114, B96)
| | | | | | ['Static', '\ue01b', '\ue01bStatic', 'Static0', 'Static1']
| | | | | | child_window(title="", control_type="Text")
| | | | |
| | | | | Button - 'Minimize' (L486, T76, R506, B96)
| | | | | ['Minimize', 'Button2', 'MinimizeButton']
| | | | | child_window(title="Minimize", control_type="Button")
| | | | | |
| | | | | | Static - '' (L486, T76, R506, B96)
| | | | | | ['\ue014Static', 'Static2', '\ue014']
| | | | | | child_window(title="", control_type="Text")
| | | | |
| | | | | Button - 'Close' (L516, T76, R536, B96)
| | | | | ['Close', 'Button3', 'CloseButton']
| | | | | child_window(title="Close", control_type="Button")
| | | | | |
| | | | | | Static - '' (L516, T76, R536, B96)
| | | | | | ['Static3', '\ue007', '\ue007Static']
| | | | | | child_window(title="", control_type="Text")
| | | |
| | | | GroupBox - '' (L-149, T68, R551, B638)
| | | | ['\ue01bGroupBox2', 'GroupBox2']
| | | | |
| | | | | Image - '' (L111, T120, R291, B300)
| | | | | ['\ue01bImage', 'Image']
| | | | |
| | | | | Button - 'Disconnect' (L126, T323, R276, B383)
| | | | | ['Button4', 'DisconnectButton', 'Disconnect']
| | | | | child_window(title="Disconnect", auto_id="dashboard_switch", control_type="Button")
| | | | |
| | | | | Static - 'Original IP' (L68, T414, R135, B430)
| | | | | ['Original IPStatic', 'Static4', 'Original IP', 'Original IPStatic0', 'Original IPStatic1', 'Original IP0', 'Original IP1']
| | | | | child_window(title="Original IP", control_type="Text")
| | | | |
| | | | | Static - ' ' (L164, T412, R168, B427)
| | | | | ['Static5', '\xa0Static', '\xa0', '\xa0Static0', '\xa0Static1', '\xa00', '\xa01']
| | | | | child_window(title=" ", control_type="Text")
| | | | |
| | | | | Static - '91.90.253.244' (L184, T414, R266, B429)
| | | | | ['Static6', '91.90.253.244Static', '91.90.253.244', '91.90.253.244Static0', '91.90.253.244Static1', '91.90.253.2440', '91.90.253.2441']
| | | | | child_window(title="91.90.253.244", control_type="Text")
| | | | |
| | | | | Static - 'New IP' (L68, T442, R113, B458)
| | | | | ['New IP', 'Static7', 'New IPStatic']
| | | | | child_window(title="New IP", control_type="Text")
| | | | |
| | | | | Static - ' ' (L164, T440, R168, B455)
| | | | | ['Static8', '\xa0Static2', '\xa02']
| | | | | child_window(title=" ", control_type="Text")
| | | | |
| | | | | Static - '80.255.5.198' (L184, T442, R258, B457)
| | | | | ['Static9', '80.255.5.198', '80.255.5.198Static']
| | | | | child_window(title="80.255.5.198", control_type="Text")
| | | | |
| | | | | Button - 'Change IP Address' (L294, T416, R334, B456)
| | | | | ['Change IP AddressButton', 'Button5', 'Change IP Address']
| | | | | child_window(title="Change IP Address", auto_id="ip_change", control_type="Button")
| | | | |
| | | | | Static - 'Original IP' (L95, T428, R162, B444)
| | | | | ['Original IPStatic2', 'Static10', 'Original IP2']
| | | | | child_window(title="Original IP", control_type="Text")
| | | | |
| | | | | Static - ' ' (L191, T426, R196, B441)
| | | | | ['Static11', '\xa0Static3', '\xa03']
| | | | | child_window(title=" ", control_type="Text")
| | | | |
| | | | | Static - '91.90.253.244' (L211, T428, R293, B443)
| | | | | ['Static12', '91.90.253.244Static2', '91.90.253.2442']
| | | | | child_window(title="91.90.253.244", control_type="Text")
| | | | |
| | | | | Button - 'Location Germany, Berlin' (L31, T489, R371, B569)
| | | | | ['Button6', 'Location Germany, BerlinButton', 'Location Germany, Berlin']
| | | | | child_window(title="Location Germany, Berlin", auto_id="dashboard_chooseLocation", control_type="Button")
| | | | | |
| | | | | | Static - ' ' (L51, T507, R55, B522)
| | | | | | ['Static13', '\xa0Static4', '\xa04']
| | | | | | child_window(title=" ", control_type="Text")
| | | | | |
| | | | | | Static - 'Location' (L111, T511, R164, B526)
| | | | | | ['Static14', 'Location', 'LocationStatic']
| | | | | | child_window(title="Location", control_type="Text")
| | | | | |
| | | | | | Static - 'Germany, Berlin' (L111, T529, R219, B546)
| | | | | | ['Static15', 'Germany, Berlin', 'Germany, BerlinStatic']
| | | | | | child_window(title="Germany, Berlin", control_type="Text")
| | | | | |
| | | | | | Static - '' (L331, T519, R351, B539)
| | | | | | ['Static16', '\ue005', '\ue005Static']
| | | | | | child_window(title="", control_type="Text")
| | | | |
| | | | | Button - 'More' (L420, T107, R528, B137)
| | | | | ['More', 'Button7', 'MoreButton']
| | | | | child_window(title="More", control_type="Button")
| | |
| | | Pane - '' (L-149, T68, R551, B638)
| | | ['Pane3', '\ue01bPane2']
Traceback (most recent call last):
File "C:\Users\db533\VirtualBox VMs\pycharm-gunabot\venv\lib\site-packages\pywinauto\application.py", line 250, in __resolve_control
ctrl = wait_until_passes(
File "C:\Users\db533\VirtualBox VMs\pycharm-gunabot\venv\lib\site-packages\pywinauto\timings.py", line 458, in wait_until_passes
raise err
pywinauto.timings.TimeoutError
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\db533\PycharmProjects\GunaBot\hma_control.py", line 19, in <module>
dlg_spec.AvastChromiumWindow.Pane2.Document.GroupBox2.Button4.click()
File "C:\Users\db533\VirtualBox VMs\pycharm-gunabot\venv\lib\site-packages\pywinauto\application.py", line 379, in __getattribute__
ctrls = self.__resolve_control(self.criteria)
File "C:\Users\db533\VirtualBox VMs\pycharm-gunabot\venv\lib\site-packages\pywinauto\application.py", line 261, in __resolve_control
raise e.original_exception
File "C:\Users\db533\VirtualBox VMs\pycharm-gunabot\venv\lib\site-packages\pywinauto\timings.py", line 436, in wait_until_passes
func_val = func(*args, **kwargs)
File "C:\Users\db533\VirtualBox VMs\pycharm-gunabot\venv\lib\site-packages\pywinauto\application.py", line 203, in __get_ctrl
dialog = self.backend.generic_wrapper_class(findwindows.find_element(**criteria[0]))
File "C:\Users\db533\VirtualBox VMs\pycharm-gunabot\venv\lib\site-packages\pywinauto\findwindows.py", line 87, in find_element
raise ElementNotFoundError(kwargs)
pywinauto.findwindows.ElementNotFoundError: {'title': 'HMA VPN', 'backend': 'win32', 'process': 40580}
Process finished with exit code 1
Cracked it! The following code let's me toggle the Connect / Disconnect button and change the IP.
from pywinauto import Desktop,Application
vpn_app = Application(backend="uia").start('C:\Program Files\Privax\HMA VPN\Vpn.exe')
dialog=Desktop(backend="uia").HMA
panel0=dialog.Pane
# Command to connect / disconnect the VPN: connect_button.click()
connect_button=panel0.ConnectButton
# Command to change the IP address: changeIP.click()
changeIP=panel0.Button5
# Check VPN state:
# 0 if disconnected
# 1 if connected
print(connect_button.get_toggle_state())
# Command to connect / disconnect the VPN: connect_button.click()
connect_button=panel0.ConnectButton
connect_button.click()
# Command to change the IP address: changeIP.click()
changeIP=panel0.Button5
changeIP.click()
# Check VPN state:
# 0 if disconnected
# 1 if connected
print(connect_button.get_toggle_state())
I'm trying to run a suite of tests for a django project I've been brought into. Running the tests in my Power Shell environment using python manage.py test --settings=tRecorderApi.settings_test returns the following output:
Creating test database for alias 'default'...
DEBUG 2018-03-26 09:05:56,124 base 276900 275184 Configuring Raven for host: http://sentry:9000
EEEEEEEEEEEEEEEE
======================================================================
ERROR: file_transfer (unittest.loader._FailedTest)
----------------------------------------------------------------------
ImportError: Failed to import test module: file_transfer
Traceback (most recent call last):
File "C:\Program Files (x86)\Python36-32\lib\unittest\loader.py", line 462, in _find_test_path
package = self._get_module_from_name(name)
File "C:\Program Files (x86)\Python36-32\lib\unittest\loader.py", line 369, in _get_module_from_name
__import__(name)
File "C:\Users\dipinton\tE-backend\tRecorderApi\api\file_transfer\__init__.py", line 1, in <module>
from .FileUtility import *
File "C:\Users\dipinton\tE-backend\tRecorderApi\api\file_transfer\FileUtility.py", line 12, in <module>
from ..models.language import Language
ValueError: attempted relative import beyond top-level package
======================================================================
ERROR: models (unittest.loader._FailedTest)
----------------------------------------------------------------------
ImportError: Failed to import test module: models
Traceback (most recent call last):
File "C:\Program Files (x86)\Python36-32\lib\unittest\loader.py", line 462, in _find_test_path
package = self._get_module_from_name(name)
File "C:\Program Files (x86)\Python36-32\lib\unittest\loader.py", line 369, in _get_module_from_name
__import__(name)
File "C:\Users\dipinton\tE-backend\tRecorderApi\api\models\__init__.py", line 1, in <module>
from .book import Book
File "C:\Users\dipinton\tE-backend\tRecorderApi\api\models\book.py", line 4, in <module>
class Book(models.Model):
File "C:\Program Files (x86)\Python36-32\lib\site-packages\django\db\models\base.py", line 118, in __new__
"INSTALLED_APPS." % (module, name)
RuntimeError: Model class models.book.Book doesn't declare an explicit app_label and isn't in an application in INSTALLED_APPS.
----------------------------------------------------------------------
Ran 16 tests in 0.000s
FAILED (errors=16)
System check identified no issues (0 silenced).
Destroying test database for alias 'default'...
The rest of the test results all look the same as the first one with the ValueError: attempted relative import beyond top-level package.
My folder structure looks like this (the only important files are under the first tRecorderApi folder):
C:.
| .gitignore
| api_spec.txt
| postgres-setup
| README.md
| __init__.py
|
+---InstallationScripts
| | README.md
| |
| +---translationExchangeRpi
| | | install.deb
| | | prepare.sh
| | | uninstall.sh
| | |
| | \---install
| | +---DEBIAN
| | | control
| | | postinst
| | |
| | \---tmp
| | \---tex_install
| | +---config
| | | dhcpcd.conf
| | | hosts
| | | tex_autorun.sh
| | |
| | \---TranslationExchange
| | | docker-compose.yml
| | | Dockerfile
| | |
| | +---ap
| | | dnsmasq.conf
| | | Dockerfile
| | | entrypoint.sh
| | | hostapd
| | | hostapd.conf
| | |
| | \---config
| | | config.py
| | | requirements.txt
| | | rootCA.crt
| | | self-signed.conf
| | | server.crt
| | | server.key
| | | ssl-params.conf
| | |
| | \---nginx
| | trapi.conf
| |
| \---translationExchangeVM
| | install
| | prepare
| | software
| | uninstall
| |
| +---autorun
| | tex_autorun.sh
| |
| \---TranslationExchange
| | docker-compose.yml
| | Dockerfile
| |
| \---config
| | config.py
| | requirements.txt
| | rootCA.crt
| | self-signed.conf
| | server.crt
| | server.key
| | ssl-params.conf
| |
| \---nginx
| trapi.conf
|
+---tRecorderApi
| | books.json
| | db.sqlite3
| | langnames.json
| | manage.py
| | requirements.txt
| | swaggerAPI.yaml
| | wmta.py
| | __init__.py
| |
| +---api
| | | admin.py
| | | apps.py
| | | parsers.py
| | | serializers.py
| | | tasks.py
| | | urls.py
| | |
| | +---file_transfer
| | | | ArchiveIt.py
| | | | ArchiveProject.py
| | | | AudioUtility.py
| | | | Download.py
| | | | FileTransfer.py
| | | | FileUtility.py
| | | | tinytag.py
| | | | TrIt.py
| | | | Upload.py
| | | | ZipIt.py
| | | | __init__.py
| | | |
| | | \---__pycache__
| | | ArchiveIt.cpython-36.pyc
| | | ArchiveProject.cpython-36.pyc
| | | AudioUtility.cpython-36.pyc
| | | Download.cpython-36.pyc
| | | FileTransfer.cpython-36.pyc
| | | FileUtility.cpython-36.pyc
| | | tinytag.cpython-36.pyc
| | | TrIt.cpython-36.pyc
| | | Upload.cpython-36.pyc
| | | ZipIt.cpython-36.pyc
| | | __init__.cpython-36.pyc
| | |
| | +---migrations
| | | | 0001_initial.py
| | | | __init__.py
| | | |
| | | \---__pycache__
| | | 0001_initial.cpython-36.pyc
| | | __init__.cpython-36.pyc
| | |
| | +---models
| | | | anthology.py
| | | | book.py
| | | | chapter.py
| | | | chunk.py
| | | | comment.py
| | | | language.py
| | | | mode.py
| | | | project.py
| | | | take.py
| | | | version.py
| | | | __init__.py
| | | |
| | | \---__pycache__
| | | anthology.cpython-36.pyc
| | | book.cpython-36.pyc
| | | chapter.cpython-36.pyc
| | | chunk.cpython-36.pyc
| | | comment.cpython-36.pyc
| | | language.cpython-36.pyc
| | | mode.cpython-36.pyc
| | | project.cpython-36.pyc
| | | take.cpython-36.pyc
| | | version.cpython-36.pyc
| | | __init__.cpython-36.pyc
| | |
| | +---templates
| | | index.html
| | |
| | +---tests
| | | | tests_books.py
| | | | tests_get_projects.py
| | | | tests_upload.py
| | | | test_api_anthologies.py
| | | | test_api_books.py
| | | | test_api_chapters.py
| | | | test_api_chunks.py
| | | | test_api_comments.py
| | | | test_api_languages.py
| | | | test_api_modes.py
| | | | test_api_projects.py
| | | | test_api_takes.py
| | | | test_api_versions.py
| | | | test_api_zip.py
| | | | __init__.py
| | | |
| | | \---__pycache__
| | | tests_books.cpython-36.pyc
| | | tests_get_projects.cpython-36.pyc
| | | tests_upload.cpython-36.pyc
| | | test_api_anthologies.cpython-36.pyc
| | | test_api_books.cpython-36.pyc
| | | test_api_chapters.cpython-36.pyc
| | | test_api_chunks.cpython-36.pyc
| | | test_api_comments.cpython-36.pyc
| | | test_api_languages.cpython-36.pyc
| | | test_api_modes.cpython-36.pyc
| | | test_api_projects.cpython-36.pyc
| | | test_api_takes.cpython-36.pyc
| | | test_api_versions.cpython-36.pyc
| | | test_api_zip.cpython-36.pyc
| | | __init__.cpython-36.pyc
| | |
| | +---views
| | | | anthology.py
| | | | book.py
| | | | chapter.py
| | | | chunk.py
| | | | comment.py
| | | | exclude_files.py
| | | | file_upload.py
| | | | frontend.py
| | | | helpers.py
| | | | index.py
| | | | language.py
| | | | mode.py
| | | | project.py
| | | | push_takes.py
| | | | resumable_upload.py
| | | | source_file.py
| | | | source_file_upload.py
| | | | stitch_takes.py
| | | | take.py
| | | | tr.py
| | | | update_project_takes.py
| | | | user.py
| | | | version.py
| | | | zip.py
| | | | __init__.py
| | | |
| | | \---__pycache__
| | | anthology.cpython-36.pyc
| | | book.cpython-36.pyc
| | | chapter.cpython-36.pyc
| | | chunk.cpython-36.pyc
| | | comment.cpython-36.pyc
| | | exclude_files.cpython-36.pyc
| | | file_upload.cpython-36.pyc
| | | frontend.cpython-36.pyc
| | | helpers.cpython-36.pyc
| | | index.cpython-36.pyc
| | | language.cpython-36.pyc
| | | mode.cpython-36.pyc
| | | project.cpython-36.pyc
| | | push_takes.cpython-36.pyc
| | | resumable_upload.cpython-36.pyc
| | | source_file.cpython-36.pyc
| | | source_file_upload.cpython-36.pyc
| | | stitch_takes.cpython-36.pyc
| | | take.cpython-36.pyc
| | | tr.cpython-36.pyc
| | | version.cpython-36.pyc
| | | zip.cpython-36.pyc
| | | __init__.cpython-36.pyc
| | |
| | \---__pycache__
| | admin.cpython-36.pyc
| | serializers.cpython-36.pyc
| | tasks.cpython-36.pyc
| | urls.cpython-36.pyc
| | __init__.cpython-36.pyc
| |
| +---static
| | | loader.gif
| | | resumable.js
| | |
| | \---chunks
| | +---nt
| | | +---1co
| | | | chunks.json
| | | |
| | | +---1jn
| | | | chunks.json
| | | |
| | | +---1pe
| | | | chunks.json
| | | |
| | | +---1th
| | | | chunks.json
| | | |
| | | +---1ti
| | | | chunks.json
| | | |
| | | +---2co
| | | | chunks.json
| | | |
| | | +---2jn
| | | | chunks.json
| | | |
| | | +---2pe
| | | | chunks.json
| | | |
| | | +---2th
| | | | chunks.json
| | | |
| | | +---2ti
| | | | chunks.json
| | | |
| | | +---3jn
| | | | chunks.json
| | | |
| | | +---act
| | | | chunks.json
| | | |
| | | +---col
| | | | chunks.json
| | | |
| | | +---eph
| | | | chunks.json
| | | |
| | | +---gal
| | | | chunks.json
| | | |
| | | +---heb
| | | | chunks.json
| | | |
| | | +---jas
| | | | chunks.json
| | | |
| | | +---jhn
| | | | chunks.json
| | | |
| | | +---jud
| | | | chunks.json
| | | |
| | | +---luk
| | | | chunks.json
| | | |
| | | +---mat
| | | | chunks.json
| | | |
| | | +---mrk
| | | | chunks.json
| | | |
| | | +---phm
| | | | chunks.json
| | | |
| | | +---php
| | | | chunks.json
| | | |
| | | +---rev
| | | | chunks.json
| | | |
| | | +---rom
| | | | chunks.json
| | | |
| | | \---tit
| | | chunks.json
| | |
| | \---ot
| | +---1ch
| | | chunks.json
| | |
| | +---1ki
| | | chunks.json
| | |
| | +---1sa
| | | chunks.json
| | |
| | +---2ch
| | | chunks.json
| | |
| | +---2ki
| | | chunks.json
| | |
| | +---2sa
| | | chunks.json
| | |
| | +---amo
| | | chunks.json
| | |
| | +---dan
| | | chunks.json
| | |
| | +---deu
| | | chunks.json
| | |
| | +---ecc
| | | chunks.json
| | |
| | +---est
| | | chunks.json
| | |
| | +---exo
| | | chunks.json
| | |
| | +---ezk
| | | chunks.json
| | |
| | +---ezr
| | | chunks.json
| | |
| | +---gen
| | | chunks.json
| | |
| | +---hab
| | | chunks.json
| | |
| | +---hag
| | | chunks.json
| | |
| | +---hos
| | | chunks.json
| | |
| | +---isa
| | | chunks.json
| | |
| | +---jdg
| | | chunks.json
| | |
| | +---jer
| | | chunks.json
| | |
| | +---job
| | | chunks.json
| | |
| | +---jol
| | | chunks.json
| | |
| | +---jon
| | | chunks.json
| | |
| | +---jos
| | | chunks.json
| | |
| | +---lam
| | | chunks.json
| | |
| | +---lev
| | | chunks.json
| | |
| | +---mal
| | | chunks.json
| | |
| | +---mic
| | | chunks.json
| | |
| | +---nam
| | | chunks.json
| | |
| | +---neh
| | | chunks.json
| | |
| | +---num
| | | chunks.json
| | |
| | +---oba
| | | chunks.json
| | |
| | +---pro
| | | chunks.json
| | |
| | +---psa
| | | chunks.json
| | |
| | +---rut
| | | chunks.json
| | |
| | +---sng
| | | chunks.json
| | |
| | +---zec
| | | chunks.json
| | |
| | \---zep
| | chunks.json
| |
| +---tRecorderApi
| | | celery.py
| | | settings.py
| | | settings_test.py
| | | urls.py
| | | wsgi.py
| | | __init__.py
| | |
| | \---__pycache__
| | celery.cpython-36.pyc
| | settings.cpython-36.pyc
| | settings_test.cpython-36.pyc
| | urls.cpython-36.pyc
| | wsgi.cpython-36.pyc
| | __init__.cpython-36.pyc
| |
| \---__pycache__
| __init__.cpython-36.pyc
|
\---__pycache__
__init__.cpython-36.pyc
Based on similar questions, I suspect this may have something to do with the __init__.py files in each folder. I already removed one from the 'api' folder, which should be the root of the project (that's why I started receiving the value error). Before that, I was getting the error shown in the second test where it's complaining that my models are not in my list of installed apps in my settings file. The settings file I use can be seen below:
"""
Django settings for tRecorderApi project.
Generated by 'django-admin startproject' using Django 1.11.2.
For more information on this file, see
https://docs.djangoproject.com/en/1.11/topics/settings/
For the full list of settings and their values, see
https://docs.djangoproject.com/en/1.11/ref/settings/
"""
import os
import raven
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/1.11/howto/deployment/checklist/
# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = '&9e^=922_&wi-bw#bbe$id#r$7hb(im03nrow5w#tgg8##hfd('
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True
ALLOWED_HOSTS = ['192.168.96.21', '172.19.145.91',
'172.19.145.88', 'localhost', '127.0.0.1', 'te.loc']
# Application definition
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'rest_framework',
'corsheaders',
'api',
'django_celery_results',
'drf_yasg',
'raven.contrib.django.raven_compat',
]
MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
'whitenoise.middleware.WhiteNoiseMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'corsheaders.middleware.CorsMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
]
"""REST_FRAMEWORK = {
# Use Django's standard `django.contrib.auth` permissions,
# or allow read-only access for unauthenticated users.
'DEFAULT_PERMISSION_CLASSES': [
'rest_framework.permissions.DjangoModelPermissionsOrAnonReadOnly'
]
}"""
CORS_ORIGIN_ALLOW_ALL = True
ROOT_URLCONF = 'tRecorderApi.urls'
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [os.path.join(BASE_DIR, 'api/templates'), ],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
],
},
},
]
WSGI_APPLICATION = 'tRecorderApi.wsgi.application'
# Database
# https://docs.djangoproject.com/en/1.11/ref/settings/#databases
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(BASE_DIR, 'db.sqlite3')
}
}
# DATABASES = {
# 'default': {
# 'ENGINE': 'django.db.backends.postgresql_psycopg2',
# 'NAME': 'postgres',
# 'USER': 'postgres',
# 'HOST': 'db',
# 'PORT': 5432,
# }
# }
RAVEN_CONFIG = {
'dsn': 'http://2e7130f730eb42dfa6bbe67875dfd8ee:15b0167a7b714b7697a63e6678081e3b#sentry:9000/2',
# If you are using git, you can also automatically configure the
# release based on the git info.
'release': raven.fetch_git_sha(os.path.abspath(os.pardir)),
}
LOGGING = {
'version': 1,
'disable_existing_loggers': True,
'root': {
'level': 'WARNING',
'handlers': ['sentry'],
},
'formatters': {
'verbose': {
'format': '%(levelname)s %(asctime)s %(module)s '
'%(process)d %(thread)d %(message)s'
},
},
'handlers': {
'sentry': {
# To capture more than ERROR, change to WARNING, INFO, etc.
'level': 'INFO',
'class': 'raven.contrib.django.raven_compat.handlers.SentryHandler',
'tags': {'custom-tag': 'x'},
},
'console': {
'level': 'DEBUG',
'class': 'logging.StreamHandler',
'formatter': 'verbose'
}
},
'loggers': {
'django.db.backends': {
'level': 'ERROR',
'handlers': ['console'],
'propagate': False,
},
'raven': {
'level': 'DEBUG',
'handlers': ['console'],
'propagate': False,
},
'sentry.errors': {
'level': 'DEBUG',
'handlers': ['console'],
'propagate': False,
},
},
}
# Password validation
# https://docs.djangoproject.com/en/1.11/ref/settings/#auth-password-validators
AUTH_PASSWORD_VALIDATORS = [
{
'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
},
]
# Internationalization
# https://docs.djangoproject.com/en/1.11/topics/i18n/
LANGUAGE_CODE = 'en-us'
TIME_ZONE = 'UTC'
USE_I18N = True
USE_L10N = True
USE_TZ = True
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/1.11/howto/static-files/
STATIC_ROOT = 'static'
STATIC_URL = '/static/'
# MEDIA_ROOT = 'media'
# MEDIA_URL = '/media/'
REACT_APP_DIR = os.path.join(BASE_DIR, 'frontend')
STATICFILES_DIRS = [
os.path.join(REACT_APP_DIR, 'build', 'static'),
]
SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https')
SECURE_SSL_REDIRECT = False
SESSION_COOKIE_SECURE = False
CSRF_COOKIE_SECURE = False
# celery
CELERY_BROKER_URL = 'amqp://te:te#rabbit:5672'
CELERY_RESULT_BACKEND = 'redis://redis:6379/0'
CELERY_ACCEPT_CONTENT = ['pickle']
CELERY_TASK_SERIALIZER = 'pickle'
CELERY_RESULT_SERIALIZER = 'pickle'
CELERY_IGNORE_RESULT = False
CELERY_TASK_TRACK_STARTED = True
My question here is do I need to remove all of the __init__.py files? Is there something in settings that I need to change to get the tests to run properly? Or is my issue something completely different from what I'm thinking it is?
Looks like I was able to solve my own problem. In this case, I did a git reset to get my init.py file back into my api directory. From there, I set the DJANG_SETTINGS_MODULE environment variable to point to my custom settings file. I use a Windows 10 machine so the command looked like this:
set DJANGO_SETTINGS_MODULE=tRecorderApi.settings_test
Running the two steps above got my tests to run without the Value Error.