openfun / joanie

👛 A headless ERP for education to manage course enrollment/subscription, payment and certificates delivery.
MIT License
20 stars 2 forks source link

Unique constraint on field resource_link in the CourseRun model is not working #738

Closed lunika closed 3 months ago

lunika commented 3 months ago

Bug Report

Problematic behavior

In the CourseModel, the resource_link attribute has a unique constraint. Despite this constraint, we are able to create multiple CourseRun with the same resource_link.

I wrote this test to reproduce:

    def test_course_run_resource_link_unicity(self):
        resource_link = "https://moodle.test/session1"

        course_run1 = factories.CourseRunFactory(resource_link=resource_link)

        self.assertEqual(course_run1.resource_link, resource_link)

        course_run2 = factories.CourseRunFactory(resource_link=resource_link)

        self.assertEqual(course_run2.resource_link, resource_link)

The seconde CourseRun creation should fail.

Expected behavior/code

When an existing resource_link exists in the CourseRun table, an exception should be raised.

lunika commented 3 months ago

It's not a bug. It's a feature :tm:

The factory is creating only one CourseRun.