Skip to content

Commit

Permalink
unittest: account controller - url_test (resolve)
Browse files Browse the repository at this point in the history
  • Loading branch information
janik committed Aug 14, 2024
1 parent 8703569 commit 64f7b21
Show file tree
Hide file tree
Showing 14 changed files with 63 additions and 29 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ MANIFEST
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
# Unit tests / coverage reports
htmlcov/
.tox/
.nox/
Expand Down
2 changes: 1 addition & 1 deletion quafelweb/account_controller/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ MANIFEST
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
# Unit tests / coverage reports
htmlcov/
.tox/
.nox/
Expand Down
2 changes: 1 addition & 1 deletion quafelweb/account_controller/templates/account.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
{% if request.session.admin_ident != account.identifier %}
<button class='icon_button' name="admin_ident" value="{{account.identifier}}"><span class="material-symbols-outlined">delete</span></button>
{% endif %}
</form>
</form>
{% endfor %}
</div>
<form action="add/" method="post" id='new_account_div'>
Expand Down
34 changes: 34 additions & 0 deletions quafelweb/account_controller/tests/test_urls.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
from django.test import SimpleTestCase
from django.urls import reverse, resolve
from account_controller.views import AccountView

class TestUrls(SimpleTestCase):
def test_add_url_is_resolved(self):
url = reverse('add')
print(resolve(url))
self.assertEquals(resolve(url).func, AccountView.manage_accounts)

def test_delete_url_is_resolved(self):
url = reverse('delete')
print(resolve(url))
self.assertEquals(resolve(url).func, AccountView.remove_admin)

def test_login_url_is_resolved(self):
url = reverse('login')
print(resolve(url))
self.assertEquals(resolve(url).func, AccountView.authenticate)

def test_logout_url_is_resolved(self):
url = reverse('logout')
print(resolve(url))
self.assertEquals(resolve(url).func, AccountView.logout)

def test_auth_url_is_resolved(self):
url = reverse('auth')
print(resolve(url))
self.assertEquals(resolve(url).func, AccountView.authenticate_callback)

def test_denied_url_is_resolved(self):
url = reverse('denied')
print(resolve(url))
self.assertEquals(resolve(url).func, AccountView.denied)
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def handle(self, *args, **kwargs):
sim_run = SimulationRun(
hardware_profile=random_hwp,
simulator_name=random_smp,
user="test",
user="tests",
shots=s,
qbits=q,
depth=d,
Expand Down
2 changes: 1 addition & 1 deletion quafelweb/hardware_controller/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class HardwareProfile(models.Model):

description = models.CharField(max_length=500)

# example "clust-gpu" or "clust-cpu" or "test"
# example "clust-gpu" or "clust-cpu" or "tests"
protocol = models.CharField(max_length=100)

ip_addr = models.CharField(default="240.0.0.0")
Expand Down
2 changes: 1 addition & 1 deletion quafelweb/quafel_simulators/tests/.gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# Ignore test outputs
# Ignore tests outputs

sandbox/
4 changes: 2 additions & 2 deletions quafelweb/quafel_simulators/tests/connection_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ def test_connecting_and_disconnecting_without_totp(self):
def test_connecting_and_disconnecting_with_totp(self):
"""
Test the connection and disconnection to the hardware with a totp
This test tries to connect to the bwUniCluster2.0
If you do not have credentials, you can skip this test
This tests tries to connect to the bwUniCluster2.0
If you do not have credentials, you can skip this tests
"""

logging.basicConfig()
Expand Down
16 changes: 8 additions & 8 deletions quafelweb/quafel_simulators/tests/json_handler_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ def test_read_dict_without_file(self):
"""

# assure the file is not existent
Path("test.json").unlink(missing_ok=True)
Path("tests.json").unlink(missing_ok=True)

# read the dict
read = read_dict("test.json")
read = read_dict("tests.json")

# check if the dict is empty
assert read == {}
Expand All @@ -37,24 +37,24 @@ def test_write_and_read_dict(self):
"""

# write the dict
write_json_file("test.json", {"test": "test"})
write_json_file("tests.json", {"tests": "tests"})

# read the dict
read = read_json_file("test.json")
read = read_json_file("tests.json")

# check if the dict is correct
assert read == {"test": "test"}
assert read == {"tests": "tests"}

def test_write_and_read_list(self):
"""
Test if the write and read of a list works
"""

# write the list
write_json_file("test.json", ["test", "test"])
write_json_file("tests.json", ["tests", "tests"])

# read the list
read = read_json_file("test.json")
read = read_json_file("tests.json")

# check if the list is correct
assert read == ["test", "test"]
assert read == ["tests", "tests"]
4 changes: 2 additions & 2 deletions quafelweb/quafel_simulators/tests/output_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def test_read_output_hardware_configuration_file(self):
write_json_file(
"output.json",
{
"output_location": "test",
"output_location": "tests",
"host": "localhost",
"port": 2223,
"username": "user",
Expand All @@ -60,7 +60,7 @@ def test_read_output_hardware_configuration_file(self):
output_hardware = QuafelOutputHardware()
assert output_hardware.update()

assert output_hardware.get_output_location() == "test"
assert output_hardware.get_output_location() == "tests"
assert output_hardware.get_host() == "localhost"
assert output_hardware.get_port() == 2223
assert output_hardware.get_username() == "user"
Expand Down
10 changes: 5 additions & 5 deletions quafelweb/quafel_simulators/tests/quafelsubmitter_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ class TestSubmitter(TestCase):
Test the submitter module
"""

# Run This test if other test cases are not running
@unittest.skip("This test does take a long time to run.")
# Run This tests if other tests cases are not running
@unittest.skip("This tests does take a long time to run.")
def test_forced_initiate(self):
"""
Test the forced initiation of the hardware
Expand All @@ -81,7 +81,7 @@ def test_forced_initiate(self):

assert hardware_connection.disconnect()

@unittest.skip("Just run the simultaneous submissions test")
@unittest.skip("Just run the simultaneous submissions tests")
def test_submitter_class(self):
"""
Test the submitter class
Expand Down Expand Up @@ -186,7 +186,7 @@ def test_submission_with_handler(self):
submitter = QuafelSubmitter()

def handle(r: QuafelSimulationRequest):
sleep(2.0) # Wait for the test to read the state of the request
sleep(2.0) # Wait for the tests to read the state of the request
write_output_file_pull_output()
assert submitter.get_state(r) == QuafelSubmissionState.READY
assert submitter.quafel_output_hardware.update()
Expand All @@ -195,7 +195,7 @@ def handle(r: QuafelSimulationRequest):
o = connection.get_output()

if o is None:
submitter.quafel_output_hardware = None # To make assertion in test thread
submitter.quafel_output_hardware = None # To make assertion in tests thread

assert o is not None

Expand Down
2 changes: 1 addition & 1 deletion quafelweb/quafel_simulators/tests/script_builder_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,5 +58,5 @@ def test_build_quafel_script_pull_output(self):
Test the building of the pull output script
"""

build_script = build_quafel_script_pull_output(QuafelOutputHardware(), "test")
build_script = build_quafel_script_pull_output(QuafelOutputHardware(), "tests")
print(build_script)
8 changes: 4 additions & 4 deletions quafelweb/quafel_simulators/tests/util.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""
Here are util classes that are used in the tests.
The tests need some interfaces implemented to test the simulators.
Also, the docker needs to be running for the tests to pass, because hardware.profiles and the output server are
The tests need some interfaces implemented to tests the simulators.
Also, the docker needs to be running for the tests to pass, because hardware.profiles and the output server are
required for the tests to pass.
"""

Expand Down Expand Up @@ -61,7 +61,7 @@ def get_name(self) -> str:
return "cirq_fw"

def get_version(self) -> str:
return "test"
return "tests"


class TestClassSimulationRequest(QuafelSimulationRequest):
Expand Down Expand Up @@ -124,7 +124,7 @@ def get_max_shots(self) -> int:
class TestCase(unittest.TestCase):
"""
Base class for the tests
This class changes the sandbox directory to the test directory
This class changes the sandbox directory to the tests directory
"""

@classmethod
Expand Down

0 comments on commit 64f7b21

Please sign in to comment.