Fixed failing tests
This commit is contained in:
parent
1ad84d7a67
commit
52dc0b5a81
6 changed files with 25 additions and 13 deletions
|
|
@ -6,7 +6,7 @@ run_tests:
|
|||
stage: test
|
||||
image: python:3.12
|
||||
variables:
|
||||
SECRET_KEY: 'random_secret_key_for_ci'
|
||||
DJANGO_SECRET_KEY: 'random_secret_key_for_ci'
|
||||
before_script:
|
||||
- python -m pip install --upgrade pip
|
||||
- pip install --no-cache-dir -r requirements/base.txt
|
||||
|
|
|
|||
|
|
@ -120,3 +120,5 @@ class Dataset(TimeStampMixin, Model):
|
|||
|
||||
def __str__(self) -> str:
|
||||
return f"{self.name} ({self.domain.name})"
|
||||
|
||||
Organisation = Organization
|
||||
|
|
@ -95,12 +95,15 @@ class OrganisationTestCase(TestCase):
|
|||
self.user1 = User.objects.create_user(email_address="manager@test.com", password="pass123")
|
||||
self.user2 = User.objects.create_user(email_address="employee@test.com", password="pass123")
|
||||
self.domain = Domain.objects.create(name="Technology")
|
||||
# Organization model uses `owner` and `members`.
|
||||
self.org1 = Organisation.objects.create(
|
||||
name="TechCorp",
|
||||
managers=self.user1,
|
||||
employees=self.user2,
|
||||
domains=self.domain
|
||||
owner=self.user1,
|
||||
)
|
||||
# add member and link domain
|
||||
self.org1.members.add(self.user2)
|
||||
self.domain.organization = self.org1
|
||||
self.domain.save()
|
||||
|
||||
def test_organisation_creation(self):
|
||||
self.assertEqual(self.org1.name, "TechCorp")
|
||||
|
|
@ -112,19 +115,17 @@ class OrganisationTestCase(TestCase):
|
|||
with self.assertRaises(Exception):
|
||||
Organisation.objects.create(
|
||||
name="TechCorp",
|
||||
managers=self.user1,
|
||||
employees=self.user2,
|
||||
domains=self.domain
|
||||
owner=self.user1,
|
||||
)
|
||||
|
||||
def test_organisation_manager_relationship(self):
|
||||
self.assertEqual(self.org1.managers, self.user1)
|
||||
self.assertEqual(self.org1.owner, self.user1)
|
||||
|
||||
def test_organisation_employee_relationship(self):
|
||||
self.assertEqual(self.org1.employees, self.user2)
|
||||
self.assertTrue(self.org1.members.filter(pk=self.user2.pk).exists())
|
||||
|
||||
def test_organisation_domain_relationship(self):
|
||||
self.assertEqual(self.org1.domains, self.domain)
|
||||
self.assertTrue(self.org1.domains.filter(pk=self.domain.pk).exists())
|
||||
|
||||
def test_organisation_uuid_generated(self):
|
||||
self.assertIsNotNone(self.org1.uuid)
|
||||
|
|
@ -153,7 +154,7 @@ class OrganisationTestCase(TestCase):
|
|||
self.assertEqual(org.id, self.org1.id)
|
||||
|
||||
def test_organisation_filter_by_manager(self):
|
||||
orgs = Organisation.objects.filter(managers=self.user1)
|
||||
orgs = Organisation.objects.filter(owner=self.user1)
|
||||
self.assertEqual(orgs.count(), 1)
|
||||
|
||||
def test_organisation_delete_cascade(self):
|
||||
|
|
|
|||
|
|
@ -322,7 +322,7 @@ class UserSignupActionTests(TestCase):
|
|||
'first_name': 'New',
|
||||
'last_name': 'User'
|
||||
})
|
||||
self.assertEqual(response.status_code, status.HTTP_201_CREATED)
|
||||
self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
|
||||
|
||||
|
||||
class UserChangePasswordActionTests(TestCase):
|
||||
|
|
|
|||
Binary file not shown.
|
|
@ -1,6 +1,7 @@
|
|||
from dotenv import load_dotenv
|
||||
from pathlib import Path
|
||||
import os
|
||||
import sys
|
||||
|
||||
BASE_DIR = Path(__file__).resolve().parent.parent
|
||||
|
||||
|
|
@ -102,6 +103,14 @@ DB_PASSWORD = os.getenv('POSTGRES_PASSWORD')
|
|||
DB_HOST = os.getenv('POSTGRES_HOST')
|
||||
DB_PORT = os.getenv('POSTGRES_PORT', 5432)
|
||||
|
||||
if any(arg.startswith('test') for arg in sys.argv):
|
||||
DB_ENGINE = 'django.db.backends.sqlite3'
|
||||
DB_NAME = ':memory:'
|
||||
DB_USER = None
|
||||
DB_PASSWORD = None
|
||||
DB_HOST = None
|
||||
DB_PORT = None
|
||||
|
||||
DATABASES = {
|
||||
'default': {
|
||||
'ENGINE': DB_ENGINE,
|
||||
|
|
|
|||
Loading…
Reference in a new issue