Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check Test issues #12

Draft
wants to merge 8 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 18 additions & 7 deletions docs/contributing.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,8 @@ Ready to contribute? Here’s how to set up `growth-forge` for local development
$ git clone git@github.com:your_name_here/growth-forge.git
```

3. **Install Dependencies**: Use `mamba` to create a Conda environment and`poetry` for managing Python dependencies.
3. **Install Dependencies**: Use `mamba` to create a Conda environment
and`poetry` for managing Python dependencies.

```bash
$ cd growth-forge/ # in the case you are not in the root of the project
Expand Down Expand Up @@ -118,14 +119,18 @@ $ git push origin name-of-your-bugfix-or-feature
```bash
$ sugar build
```

3. It is important to run the command:

```bash
$ makim django.migrate
```
This command is executed to apply migrations based on the current migration files.

4. To create a superuser, you should use the following commands with your information:
This command is executed to apply migrations based on the current migration
files.

4. To create a superuser, you should use the following commands with your
information:

```bash
$ makim django.create-superuser --email
Expand Down Expand Up @@ -153,12 +158,18 @@ The project will be accessible at `localhost:8000`.
$ sugar ext restart --options
```

The command mentioned is used to restart the project, which can be useful when registering a new user.

After adding a new user, you should check the console for the email verification link. To complete the email verification, click on the link, which will open in your browser. There, you will see the option to verify the email. This step is crucial to ensure the email address is valid and active, enabling the new user to fully utilize their account.
The command mentioned is used to restart the project, which can be useful when
registering a new user.

7. Once you have accessed the verification link and verified your email, you can navigate through the menu of the project "growth-forge." This menu will likely offer various options related to project settings.
After adding a new user, you should check the console for the email verification
link. To complete the email verification, click on the link, which will open in
your browser. There, you will see the option to verify the email. This step is
crucial to ensure the email address is valid and active, enabling the new user
to fully utilize their account.

7. Once you have accessed the verification link and verified your email, you can
navigate through the menu of the project "growth-forge." This menu will
likely offer various options related to project settings.

## Pull Request Guidelines

Expand Down
Empty file.
60 changes: 60 additions & 0 deletions src/growth_forge/tests/test_models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
from django.contrib.auth import get_user_model
from django.test import TestCase
from projects.models import Project

from growth_forge.models import Profile

User = get_user_model()


class ProfileTests(TestCase):
@classmethod
def setUpClass(cls):
# Create a user for testing
cls.user = User.objects.create_user(
password='testpassword2', # noqa
email='test@test.com',
)
cls.user2 = User.objects.create_user(
email='testuser2@example.com',
password='testpassword', # noqa
)

@classmethod
def tearDownClass(cls):
# Create a user for testing
cls.user.delete()

cls.user2.delete()

def test_create_profile(self):
"""
The Profile
should be created automatically
due to the post_save signal
"""
profile = Profile.objects.get(user=self.user)
assert profile is not None
assert profile.user.email == 'test@test.com'

def test_retrieve_profile(self):
profile = Profile.objects.get(user=self.user)
retrieved_profile = Profile.objects.get(id=profile.id)
assert retrieved_profile.user.email == 'test@test.com'

def test_update_profile(self):
profile, _ = Profile.objects.get_or_create(user=self.user)
# Create a Project instance and add it to the profile's projects
project = Project.objects.create(name='Test Project')
profile.projects.add(project)
# Verify the profile has the project added
assert project in profile.projects.all()

def test_delete_profile(self):
profile = Profile.objects.get(user=self.user)
profile_id = profile.id
profile.delete()

# Check that the profile does not exist
profile_exists = Profile.objects.filter(id=profile_id).exists()
assert not profile_exists, "Profile still exists after deletion"
9 changes: 6 additions & 3 deletions src/growth_forge/users/managers.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@ class UserManager(DjangoUserManager['User']):
"""Custom manager for the User model."""

def _create_user(
self, email: str, password: str | None, **extra_fields
self,
email: str,
password: str,
**extra_fields,
) -> User:
"""
Create and save a user with the given email and password.
Expand All @@ -23,7 +26,7 @@ def _create_user(
msg = 'The given email must be set'
raise ValueError(msg)
email = self.normalize_email(email)
user = self.model(email=email, **extra_fields)
user = self.model(email=email)
user.password = make_password(password)
user.save(using=self._db)
return user
Expand All @@ -36,7 +39,7 @@ def create_user(
): # type: ignore[override]
extra_fields.setdefault('is_staff', False)
extra_fields.setdefault('is_superuser', False)
return self._create_user(email, password, **extra_fields)
return self._create_user(email, password)

def create_superuser(
self,
Expand Down
1 change: 0 additions & 1 deletion src/growth_plan/tests.py

This file was deleted.

Empty file.
73 changes: 73 additions & 0 deletions src/growth_plan/tests/test_models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
# test models code yet to be inserted
# test models code yet to be inserted
from datetime import timedelta

from django.contrib.auth import get_user_model
from django.test import TestCase
from django.utils import timezone

from growth_plan.models import GrowthPlanItem

User = get_user_model()


class GrowthPlanItemTests(TestCase):
def setUp(self):
# Create a user for testing
self.user = User.objects.create_user(
password='testpassword', # noqa
email='test@test.com',
)
self.client.login(
password='testpassword', # noqa
email='test@test.com',
)

# Common data for test cases
self.growth_plan_item_data = {
'user': self.user,
'title': 'Test Growth Plan',
'description': 'This is a test description.',
'start_date': timezone.now().date(),
'end_date': (timezone.now() + timedelta(days=10)).date(),
'progress_percentage': 50,
}

def test_create_growth_plan_item(self):
growth_plan_item = GrowthPlanItem.objects.create(
**self.growth_plan_item_data
)
assert GrowthPlanItem.objects.count() == 1
assert growth_plan_item.title == 'Test Growth Plan'

def test_retrieve_growth_plan_item(self):
growth_plan_item = GrowthPlanItem.objects.create(
**self.growth_plan_item_data
)
retrieved_item = GrowthPlanItem.objects.get(id=growth_plan_item.id)
assert retrieved_item.title == growth_plan_item.title

def test_update_growth_plan_item(self):
growth_plan_item = GrowthPlanItem.objects.create(
**self.growth_plan_item_data
)
growth_plan_item.title = 'Updated Title'
growth_plan_item.save()
updated_item = GrowthPlanItem.objects.get(id=growth_plan_item.id)
assert updated_item.title == 'Updated Title'

def test_delete_growth_plan_item(self):
growth_plan_item = GrowthPlanItem.objects.create(
**self.growth_plan_item_data
)
growth_plan_item_id = growth_plan_item.id
growth_plan_item.delete()

try:
GrowthPlanItem.objects.get(id=growth_plan_item_id)
item_exists = True
except GrowthPlanItem.DoesNotExist:
item_exists = False

assert not item_exists, "GrowthPlanItem should not exist after deletion"

1 change: 0 additions & 1 deletion src/one_on_one/tests.py

This file was deleted.

Empty file.
71 changes: 71 additions & 0 deletions src/one_on_one/tests/test_models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
# test models code yet to be inserted
from django.contrib.auth import get_user_model
from django.test import TestCase
from djf_surveys.models import Survey

from one_on_one.models import Link

User = get_user_model()


class LinkTests(TestCase):
def setUp(self):
# Create users for testing
self.mentor = User.objects.create_user(
email='mentor@example.com',
password='testpassword', # noqa
)
self.mentee = User.objects.create_user(
email='mentee@example.com',
password='testpassword', # noqa
)

# Create surveys for testing
self.mentor_survey = Survey.objects.create(name='Mentor Survey')
self.mentee_survey = Survey.objects.create(name='Mentee Survey')

# Common data for test cases
self.link_data = {
'mentor': self.mentor,
'mentee': self.mentee,
'mentor_survey': self.mentor_survey,
'mentee_survey': self.mentee_survey,
'periodicity': 'weekly',
'times': 5,
}

def test_create_link(self):
link = Link.objects.create(**self.link_data)
assert Link.objects.count() == 1
assert link.mentor.email == 'mentor@example.com'
assert link.mentee.email == 'mentee@example.com'
assert link.periodicity == 'weekly'

def test_retrieve_link(self):
link = Link.objects.create(**self.link_data)
retrieved_link = Link.objects.get(id=link.id)
assert retrieved_link.mentor.email == 'mentor@example.com'
assert retrieved_link.mentee.email == 'mentee@example.com'

def test_update_link(self):
link = Link.objects.create(**self.link_data)
link.periodicity = 'monthly'
link.times = 10
link.save()
updated_link = Link.objects.get(id=link.id)
assert updated_link.periodicity == 'monthly'
assert updated_link.times == 10 # noqa

def test_delete_link(self):
link = Link.objects.create(**self.link_data)
link_id = link.id
link.delete()

try:
Link.objects.get(id=link_id)
link_exists = True
except Link.DoesNotExist:
link_exists = False

assert not link_exists, "Link should not exist after deletion"

1 change: 0 additions & 1 deletion src/projects/tests.py

This file was deleted.

Empty file added src/projects/tests/__init__.py
Empty file.
65 changes: 65 additions & 0 deletions src/projects/tests/test_models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
from django.contrib.auth import get_user_model
from django.test import TestCase

from projects.models import Project

User = get_user_model()


class ProjectTests(TestCase):
def setUp(self):
# Create users for testing
self.user1 = User.objects.create_user(
email='user1@example.com',
password='testpassword', # noqa
)
self.user2 = User.objects.create_user(
email='user2@example.com',
password='testpassword', # noqa
)

# Common data for test cases
self.project_data = {
'name': 'Test Project',
}

def test_create_project(self):
project = Project.objects.create(**self.project_data)
project.observers.add(self.user1, self.user2)
assert Project.objects.count() == 1
assert project.name == 'Test Project'
assert self.user1 in project.observers.all()
assert self.user2 == project.observers.all()

def test_retrieve_project(self):
project = Project.objects.create(**self.project_data)
project.observers.add(self.user1, self.user2)
retrieved_project = Project.objects.get(id=project.id)
assert retrieved_project.name == 'Test Project'
assert self.user1 in retrieved_project.observers.all()
assert self.user2 in retrieved_project.observers.all()

def test_update_project(self):
project = Project.objects.create(**self.project_data)
project.observers.add(self.user1)
project.name = 'Updated Project'
project.observers.remove(self.user1)
project.observers.add(self.user2)
project.save()
updated_project = Project.objects.get(id=project.id)
assert updated_project.name == 'Updated Project'
assert self.user1 in updated_project.observers.all()
assert self.user2 in updated_project.observers.all()

def test_delete_project(self):
project = Project.objects.create(**self.project_data)
project_id = project.id
project.delete()

try:
Project.objects.get(id=project_id)
project_exists = True
except Project.DoesNotExist:
project_exists = False

assert not project_exists, "Project should not exist after deletion"
Loading