-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1494 from gustavomm19/marketing-cohorts
Add micro cohorts to cohort model
- Loading branch information
Showing
14 changed files
with
439 additions
and
4 deletions.
There are no files selected for viewing
34 changes: 34 additions & 0 deletions
34
breathecode/admissions/migrations/0065_cohort_cohorts_order_cohort_micro_cohorts.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
# Generated by Django 5.1.2 on 2024-11-07 22:18 | ||
|
||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
("admissions", "0064_academy_legal_name"), | ||
] | ||
|
||
operations = [ | ||
migrations.AddField( | ||
model_name="cohort", | ||
name="cohorts_order", | ||
field=models.CharField( | ||
blank=True, | ||
default=None, | ||
help_text="An IDs comma separated list to indicate the order in which the micro cohorts will be displayed", | ||
max_length=50, | ||
null=True, | ||
), | ||
), | ||
migrations.AddField( | ||
model_name="cohort", | ||
name="micro_cohorts", | ||
field=models.ManyToManyField( | ||
blank=True, | ||
help_text="This cohorts will represent small courses inside a main course", | ||
related_name="cohorts", | ||
to="admissions.cohort", | ||
), | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
# Generated by Django 5.1.2 on 2024-11-14 12:32 | ||
|
||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
("admissions", "0065_cohort_cohorts_order_cohort_micro_cohorts"), | ||
] | ||
|
||
operations = [ | ||
migrations.AddField( | ||
model_name="cohort", | ||
name="color", | ||
field=models.CharField( | ||
blank=True, | ||
default=None, | ||
help_text="Add the color with hexadecimal format, i.e.: #FFFFFF", | ||
max_length=50, | ||
null=True, | ||
), | ||
), | ||
] |
23 changes: 23 additions & 0 deletions
23
breathecode/admissions/migrations/0067_alter_cohort_micro_cohorts.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# Generated by Django 5.1.2 on 2024-11-15 09:48 | ||
|
||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
("admissions", "0066_cohort_color"), | ||
] | ||
|
||
operations = [ | ||
migrations.AlterField( | ||
model_name="cohort", | ||
name="micro_cohorts", | ||
field=models.ManyToManyField( | ||
blank=True, | ||
help_text="This cohorts will represent small courses inside a main course", | ||
related_name="main_cohorts", | ||
to="admissions.cohort", | ||
), | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
109 changes: 109 additions & 0 deletions
109
breathecode/admissions/tests/receivers/tests_new_cohort_user.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
import random | ||
|
||
import pytest | ||
|
||
from breathecode.tests.mixins.breathecode_mixin.breathecode import Breathecode | ||
|
||
|
||
@pytest.fixture(autouse=True) | ||
def arange(db, bc: Breathecode, fake): | ||
|
||
yield | ||
|
||
|
||
def test_with_one_micro_cohort(enable_signals, bc: Breathecode): | ||
enable_signals() | ||
|
||
model_micro_cohort = bc.database.create( | ||
cohort={"available_as_saas": True}, | ||
) | ||
|
||
model_main_cohort = bc.database.create( | ||
user=1, | ||
cohort_user={"role": "STUDENT"}, | ||
cohort={"available_as_saas": True, "micro_cohorts": [model_micro_cohort.cohort]}, | ||
) | ||
|
||
assert bc.database.list_of("admissions.CohortUser") == [ | ||
{ | ||
**bc.format.to_dict(model_main_cohort.cohort_user), | ||
}, | ||
{ | ||
**bc.format.to_dict(model_main_cohort.cohort_user), | ||
"id": 2, | ||
"cohort_id": 1, | ||
"finantial_status": "FULLY_PAID", | ||
}, | ||
] | ||
|
||
|
||
def test_with_many_micro_cohorts(enable_signals, bc: Breathecode): | ||
enable_signals() | ||
|
||
model_micro_cohort = bc.database.create( | ||
cohort=[{"available_as_saas": True}, {"available_as_saas": True}], | ||
) | ||
|
||
model_main_cohort = bc.database.create( | ||
user=1, | ||
cohort_user={"role": "STUDENT"}, | ||
cohort={ | ||
"available_as_saas": True, | ||
"micro_cohorts": [model_micro_cohort.cohort[0], model_micro_cohort.cohort[1]], | ||
}, | ||
) | ||
|
||
assert bc.database.list_of("admissions.CohortUser") == [ | ||
{ | ||
**bc.format.to_dict(model_main_cohort.cohort_user), | ||
}, | ||
{ | ||
**bc.format.to_dict(model_main_cohort.cohort_user), | ||
"id": 2, | ||
"cohort_id": 1, | ||
"finantial_status": "FULLY_PAID", | ||
}, | ||
{ | ||
**bc.format.to_dict(model_main_cohort.cohort_user), | ||
"id": 3, | ||
"cohort_id": 2, | ||
"finantial_status": "FULLY_PAID", | ||
}, | ||
] | ||
|
||
|
||
def test_with_cohort_users_previously_created(enable_signals, bc: Breathecode): | ||
enable_signals() | ||
|
||
model_micro_cohorts = bc.database.create( | ||
cohort=[{"available_as_saas": True}, {"available_as_saas": True}], | ||
) | ||
|
||
model_cohort_users = bc.database.create( | ||
user=1, | ||
cohort_user=[ | ||
{"role": "STUDENT", "cohort": model_micro_cohorts.cohort[0]}, | ||
{"role": "STUDENT", "cohort": model_micro_cohorts.cohort[1]}, | ||
], | ||
) | ||
|
||
model_main_cohort = bc.database.create( | ||
cohort_user={"user": model_cohort_users.user, "role": "STUDENT"}, | ||
cohort={"available_as_saas": True, "micro_cohorts": [*model_micro_cohorts.cohort]}, | ||
) | ||
|
||
assert bc.database.list_of("admissions.CohortUser") == [ | ||
{ | ||
**bc.format.to_dict(model_main_cohort.cohort_user), | ||
"id": 1, | ||
"cohort_id": 1, | ||
}, | ||
{ | ||
**bc.format.to_dict(model_main_cohort.cohort_user), | ||
"id": 2, | ||
"cohort_id": 2, | ||
}, | ||
{ | ||
**bc.format.to_dict(model_main_cohort.cohort_user), | ||
}, | ||
] |
Oops, something went wrong.