How to use faculty - 10 common examples

To help you get started, we’ve selected a few faculty examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github sfu-fas / coursys / faculty / tests.py View on Github external
url = reverse('faculty.views.change_event', kwargs={'userid': person.userid, 'event_slug': event.slug})
        resp = c.get(url)
        inputs = [l for l in resp.content.split('\n') if 'name="load"' in l]
        inputs_correct_value = [l for l in inputs if 'value="6"' in l]
        self.assertEquals(len(inputs_correct_value), 1)

        # POST a change and make sure the right value ends up in the DB
        data = {
            'start_date_0': '2000-09-01',
            'end_date_0': '',
            'unit': str(unit.id),
            'load': '5',
            'comments': '',
        }
        c.post(url, data)
        new_ce = CareerEvent.objects.filter(unit=unit, person=person, event_type=etype)[0]
        self.assertEquals(new_ce.config['load'], '5/3')
github sfu-fas / coursys / faculty / tests.py View on Github external
def test_annual_teaching(self):
        """
        Test the annual teaching value entry field
        """
        person = Person.objects.get(userid='ggbaker')
        unit = Unit.objects.get(slug='cmpt')
        editor = Person.objects.get(userid='dzhao')
        etype = 'NORM_TEACH'
        event = CareerEvent.objects.filter(unit=unit, person=person, event_type=etype)[0]
        event.config['load'] = 2 # 2 courses/semester in database should be 6/year to the user
        event.get_handler().save(editor)

        c = Client()
        c.login_user(editor.userid)

        # make sure the form renders with value="6"
        url = reverse('faculty.views.change_event', kwargs={'userid': person.userid, 'event_slug': event.slug})
        resp = c.get(url)
        inputs = [l for l in resp.content.split('\n') if 'name="load"' in l]
        inputs_correct_value = [l for l in inputs if 'value="6"' in l]
        self.assertEquals(len(inputs_correct_value), 1)

        # POST a change and make sure the right value ends up in the DB
        data = {
            'start_date_0': '2000-09-01',
github sfu-fas / coursys / faculty / tests.py View on Github external
def setUp(self):
        faculty_test_data.Command().handle()
        self.p = Person.objects.get(userid='ggbaker')
        self.u = Unit.objects.get(id=1)
        self.date = datetime.date(2014, 1, 1)
        self.e = CareerEvent(person=self.p, unit=self.u, event_type="APPOINT", start_date=self.date)
        self.e.get_handler().save(self.p)
github facultyai / faculty / tests / clients / test_object.py View on Github external
def test_object_client_presign_download(mocker):
    mocker.patch.object(
        ObjectClient, "_post", return_value=SIMPLE_PRESIGN_RESPONSE
    )
    schema_mock = mocker.patch(
        "faculty.clients.object._SimplePresignResponseSchema"
    )

    client = ObjectClient(mocker.Mock())
    returned = client.presign_download(
        PROJECT_ID,
        "/path",
        response_content_disposition="attachement; filename=other",
    )

    assert returned == SIMPLE_PRESIGN_RESPONSE.url

    schema_mock.assert_called_once_with()
    ObjectClient._post.assert_called_once_with(
        "/project/{}/presign/download".format(PROJECT_ID),
        schema_mock.return_value,
        json={
            "path": "/path",
            "responseContentDisposition": "attachement; filename=other",
        },
github facultyai / faculty / tests / clients / test_object.py View on Github external
def test_object_client_delete_default(mocker):
    path = "test-path"
    mocker.patch.object(ObjectClient, "_delete_raw")

    client = ObjectClient(mocker.Mock())
    client.delete(PROJECT_ID, path)

    ObjectClient._delete_raw.assert_called_once_with(
        "/project/{}/object/{}".format(PROJECT_ID, path),
        params={"recursive": 0},
    )
github facultyai / faculty / tests / clients / test_object.py View on Github external
def test_object_client_presign_download_defaults(mocker):
    mocker.patch.object(
        ObjectClient, "_post", return_value=SIMPLE_PRESIGN_RESPONSE
    )
    schema_mock = mocker.patch(
        "faculty.clients.object._SimplePresignResponseSchema"
    )

    client = ObjectClient(mocker.Mock())
    returned = client.presign_download(PROJECT_ID, "/path")

    assert returned == SIMPLE_PRESIGN_RESPONSE.url

    schema_mock.assert_called_once_with()
    ObjectClient._post.assert_called_once_with(
        "/project/{}/presign/download".format(PROJECT_ID),
        schema_mock.return_value,
        json={"path": "/path"},
    )
github facultyai / faculty / tests / clients / test_object.py View on Github external
def test_object_client_create_directory(mocker, parents, expected_parent):
    mocker.patch.object(ObjectClient, "_put_raw")

    client = ObjectClient(mocker.Mock())
    client.create_directory(PROJECT_ID, "test-path", parents=parents)

    ObjectClient._put_raw.assert_called_once_with(
        "/project/{}/directory/{}".format(PROJECT_ID, "test-path"),
        params={"parents": expected_parent},
    )
github facultyai / faculty / tests / clients / test_object.py View on Github external
def test_object_client_copy_source_not_found(mocker):
    error_code = "source_path_not_found"
    exception = NotFound(mocker.Mock(), mocker.Mock(), error_code)
    mocker.patch.object(ObjectClient, "_put_raw", side_effect=exception)

    client = ObjectClient(mocker.Mock())
    with pytest.raises(PathNotFound, match="'source' cannot be found"):
        client.copy(PROJECT_ID, "source", "destination")
github facultyai / faculty / tests / clients / test_object.py View on Github external
def test_object_client_copy_url_encoding(mocker):
    mocker.patch.object(ObjectClient, "_put_raw")

    client = ObjectClient(mocker.Mock())
    client.copy(PROJECT_ID, "source", "/[1]/")

    ObjectClient._put_raw.assert_called_once_with(
        "/project/{}/object/%5B1%5D/".format(PROJECT_ID),
        params={"sourcePath": "source", "recursive": 0},
    )
github facultyai / faculty / tests / clients / experiment / test_client.py View on Github external
def test_delete_runs(mocker):
    delete_runs_response = mocker.Mock()
    mocker.patch.object(
        ExperimentClient, "_post", return_value=delete_runs_response
    )
    response_schema_mock = mocker.patch(
        "faculty.clients.experiment._client.DeleteExperimentRunsResponseSchema"
    )
    filter_schema_mock = mocker.patch(
        "faculty.clients.experiment._client.FilterSchema"
    )
    filter_dump_mock = filter_schema_mock.return_value.dump

    run_ids = [uuid4(), uuid4()]

    client = ExperimentClient(mocker.Mock())
    response = client.delete_runs(PROJECT_ID, run_ids)

    assert response == delete_runs_response

    expected_filter = CompoundFilter(
        LogicalOperator.OR,
        [
            RunIdFilter(ComparisonOperator.EQUAL_TO, run_ids[0]),
            RunIdFilter(ComparisonOperator.EQUAL_TO, run_ids[1]),
        ],
    )
    filter_dump_mock.assert_called_once_with(expected_filter)
    ExperimentClient._post.assert_called_once_with(
        "/project/{}/run/delete/query".format(PROJECT_ID),
        response_schema_mock.return_value,
        json={"filter": filter_dump_mock.return_value},