From a59cbe0b596e3cc3e9d046d2630429d86d2261ff Mon Sep 17 00:00:00 2001
From: magnus2142 <magnus.bredeli@hotmail.com>
Date: Wed, 11 May 2022 10:48:48 +0200
Subject: [PATCH] fixed tests and use pytest instead of nosetests

---
 .gitlab-ci.yml                                |  4 +--
 bbcli/commands/assignments.py                 |  2 +-
 requirements.txt                              |  1 -
 .../test_announcements_services.py            | 31 +++++++++----------
 .../test_assignments_services.py              | 11 +++----
 tests/test_services/test_contents_services.py | 15 +++++----
 tests/test_services/test_courses_services.py  |  5 ++-
 7 files changed, 32 insertions(+), 37 deletions(-)

diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index 1f04b3f..1535375 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -29,13 +29,13 @@ before_script:
   - source venv/bin/activate
   - python -m pip install -r requirements.txt 
 
-py37_nose:
+py37_pytest:
   image: python:3.7
   stage: test
   script:
     - apt-get update -q -y
     - pip install -r requirements.txt
-    - nosetests -v --nocapture
+    - pytest -m pytest
 
 deploy-prod-pypi:
   image: docker.km3net.de/base/python:3
diff --git a/bbcli/commands/assignments.py b/bbcli/commands/assignments.py
index 91a9887..f68f7ba 100644
--- a/bbcli/commands/assignments.py
+++ b/bbcli/commands/assignments.py
@@ -51,7 +51,7 @@ def create_assignment(ctx, course_id: str, parent_id: str, title: str,
 
     response = contents_services.create_assignment(
         ctx.obj['SESSION'], course_id, parent_id, title, standard_options, grading_options, attachments, markdown)
-    assignments_views.print_created_assignment(json.loads(response), print_json)
+    assignments_views.print_created_assignment(response, print_json)
 
 @click.command(name='list', help='List all assignments from a course.')
 @click.option('-c', '--course', 'course_id', required=True, help='COURSE ID, of the course you want assignments from.')
diff --git a/requirements.txt b/requirements.txt
index 1877beb..a49ebfa 100644
--- a/requirements.txt
+++ b/requirements.txt
@@ -12,6 +12,5 @@ python-magic==0.4.25
 python-dateutil==2.8.2
 tabulate==0.8.9
 pwinput==1.0.2
-nose==1.3.7
 Markdown==3.3.6
 markdownify==0.11.2
\ No newline at end of file
diff --git a/tests/test_services/test_announcements_services.py b/tests/test_services/test_announcements_services.py
index cd1056c..ad1a155 100644
--- a/tests/test_services/test_announcements_services.py
+++ b/tests/test_services/test_announcements_services.py
@@ -4,8 +4,9 @@ from typing import List
 from click import Abort, BadParameter
 import requests
 
+import pytest
+
 from unittest.mock import Mock, patch
-from nose.tools import assert_list_equal, assert_equal, raises
 from bbcli.entities.content_builder_entitites import DateInterval
 
 from bbcli.services.announcements_services import create_announcement, delete_announcement, list_announcement, list_announcements, list_course_announcements, update_announcement
@@ -78,7 +79,7 @@ class TestAnnouncementsServices(object):
         # Id is irrelavant here because the API call is mocked anyways
         response = list_announcement(self.test_session, 'test_course_id', 'test_announcement_id')
 
-        assert_equal(response, TEST_ANNOUNCEMENT)
+        assert response == TEST_ANNOUNCEMENT
 
 
     def test_list_course_announcements(self):
@@ -91,9 +92,9 @@ class TestAnnouncementsServices(object):
         # Id is irrelavant here because the API call is mocked anyways
         response = list_course_announcements(self.test_session, 'test_course_id')
 
-        assert_equal(response, {
+        assert response == {
             'results': TEST_COURSE_ANNOUNCEMENTS_LIST
-        })
+        }
 
     def test_list_announcements(self):
         self.mock_auth.return_value.ok = True
@@ -118,7 +119,7 @@ class TestAnnouncementsServices(object):
         mock_get_course_announcements_patcher.stop()
         mock_get_courses_patcher.stop()
 
-        assert_equal(response, TEST_ANNOUNCEMENTS_LIST)
+        assert response == TEST_ANNOUNCEMENTS_LIST
 
     def test_create_annonucement(self):
         self.mock_auth.return_value.ok = True
@@ -138,19 +139,17 @@ class TestAnnouncementsServices(object):
         mock_input_body_patcher.stop()
         mock_post_patcher.stop()
 
-        assert_equal(response, TEST_CREATED_ANNOUNCEMENT)
+        assert response == TEST_CREATED_ANNOUNCEMENT
 
-    @raises(BadParameter)
     def test_create_announcement_with_empty_title(self):
         self.mock_auth.return_value.ok = True
+        with pytest.raises(BadParameter):
+            create_announcement(self.test_session, '_33050_1', '', DateInterval(), False)
 
-        create_announcement(self.test_session, '_33050_1', '', DateInterval(), False)
-
-    @raises(Abort)
     def test_create_annonucement_with_wrong_date_format(self):
         self.mock_auth.return_value.ok = True
-
-        create_announcement(self.test_session, '_33050_1', 'Test annonucement', DateInterval(start=format_date('16-04-22 12:00')), False)
+        with pytest.raises(Abort):
+            create_announcement(self.test_session, '_33050_1', 'Test annonucement', DateInterval(start=format_date('16-04-22 12:00')), False)
 
 
     def test_delete_announcement(self):
@@ -164,9 +163,8 @@ class TestAnnouncementsServices(object):
 
         response = delete_announcement(self.test_session, 'test_course_id', 'test_announcement_id')
 
-        assert_equal(response, '')
+        assert response == ''
 
-    @raises(requests.exceptions.HTTPError)
     def test_delete_announcement_with_wrong_announcement_id(self):
         self.mock_auth.return_value.ok = True
 
@@ -176,7 +174,8 @@ class TestAnnouncementsServices(object):
         mock_delete.return_value = requests.models.Response()
         mock_delete.return_value.status_code = 404
 
-        delete_announcement(self.test_session, 'test_course_id', 'test_announcement_id')
+        with pytest.raises(requests.exceptions.HTTPError):
+            delete_announcement(self.test_session, 'test_course_id', 'test_announcement_id')
 
     def test_update_announcement(self):
         self.mock_auth.return_value.ok = True
@@ -205,4 +204,4 @@ class TestAnnouncementsServices(object):
         mock_edit_title_patcher.stop()
         mock_edit_body_patcher.stop()
 
-        assert_equal(response, UPDATED_TEST_ANNOUNCEMENT)
\ No newline at end of file
+        assert response == UPDATED_TEST_ANNOUNCEMENT
\ No newline at end of file
diff --git a/tests/test_services/test_assignments_services.py b/tests/test_services/test_assignments_services.py
index ea3e06f..ccf76eb 100644
--- a/tests/test_services/test_assignments_services.py
+++ b/tests/test_services/test_assignments_services.py
@@ -5,7 +5,6 @@ from click import Abort, BadParameter
 import requests
 
 from unittest.mock import Mock, patch
-from nose.tools import assert_list_equal, assert_equal, raises
 from bbcli.entities.content_builder_entitites import DateInterval, FileOptions, GradingOptions, StandardOptions, WeblinkOptions
 from bbcli.services.assignments_services import create_column_attempt, get_assignments, get_column_attempt, get_column_attempts, update_column_attempt
 
@@ -67,7 +66,7 @@ class TestAssignmentsServices(object):
 
         response = get_assignments(self.test_session, 'test_course_id')
 
-        assert_equal(response, TEST_ASSIGNMENTS_LIST['results'])
+        assert response == TEST_ASSIGNMENTS_LIST['results']
 
     def test_get_column_attempts(self):
         self.mock_auth.return_value.ok = True
@@ -76,7 +75,7 @@ class TestAssignmentsServices(object):
 
         response = get_column_attempts(self.test_session, 'test_course_id', 'test_column_id')
 
-        assert_equal(json.dumps(response), json.dumps(TEST_ASSIGNMENT_ATTEMPTS_LIST['results']))
+        assert json.dumps(response) == json.dumps(TEST_ASSIGNMENT_ATTEMPTS_LIST['results'])
 
     def test_get_column_attempt(self):
         self.mock_auth.return_value.ok = True
@@ -85,7 +84,7 @@ class TestAssignmentsServices(object):
 
         response = get_column_attempt(self.test_session, 'test_course_id', 'test_column_id', 'test_attempt_id')
 
-        assert_equal(response, json.dumps(TEST_ATTEMPT, indent=2))
+        assert response == json.dumps(TEST_ATTEMPT, indent=2)
 
     def create_column_attempt(self):
         self.mock_auth.return_value.ok = True
@@ -94,7 +93,7 @@ class TestAssignmentsServices(object):
         
         response = create_column_attempt(self.test_session, 'test_course_id', 'test_column_id')
 
-        assert_equal(response, TEST_SUBMITTED_ATTEMPT)
+        assert response == TEST_SUBMITTED_ATTEMPT
 
     def test_update_column_attempt(self):
         self.mock_auth.return_value.ok = True
@@ -103,5 +102,5 @@ class TestAssignmentsServices(object):
 
         response = update_column_attempt(self.test_session, 'test_course_id', 'test_column_id', 'test_attempt_id')
 
-        assert_equal(json.loads(response), TEST_GRADE_ATTEMPT)
+        assert json.loads(response) == TEST_GRADE_ATTEMPT
 
diff --git a/tests/test_services/test_contents_services.py b/tests/test_services/test_contents_services.py
index 50614b8..1bbe121 100644
--- a/tests/test_services/test_contents_services.py
+++ b/tests/test_services/test_contents_services.py
@@ -5,7 +5,6 @@ from click import Abort, BadParameter
 import requests
 
 from unittest.mock import Mock, patch
-from nose.tools import assert_list_equal, assert_equal, raises
 from bbcli.entities.content_builder_entitites import DateInterval, FileOptions, GradingOptions, StandardOptions, WeblinkOptions
 from bbcli.services.contents_services import create_assignment, create_document, create_externallink, create_file, create_folder, delete_content, update_content
 
@@ -55,7 +54,7 @@ class TestContentsServices(object):
 
         mock_input_body_patcher.stop()
 
-        assert_equal(response, TEST_CREATED_DOCUMENT)
+        assert response == TEST_CREATED_DOCUMENT
 
     def test_create_file(self):
         self.mock_auth.return_value.ok = True
@@ -72,7 +71,7 @@ class TestContentsServices(object):
 
         mock_upload_file_patcher.stop()
 
-        assert_equal(response, TEST_CREATED_FILE)
+        assert response == TEST_CREATED_FILE
 
     
     def test_create_externallink(self):
@@ -84,7 +83,7 @@ class TestContentsServices(object):
 
         response = create_externallink(self.test_session, 'test_course_id', 'test_parent_id', 'Test web-link', 'https://vg.no/', WeblinkOptions(), standard_options)
 
-        assert_equal(response, TEST_CREATED_EXTERNALLINK)
+        assert response == TEST_CREATED_EXTERNALLINK
 
     def test_create_folder(self):
         self.mock_auth.return_value.ok = True
@@ -102,7 +101,7 @@ class TestContentsServices(object):
 
         mock_input_body_patcher.stop()
 
-        assert_equal(response, TEST_CREATED_FOLDER)
+        assert response == TEST_CREATED_FOLDER
 
     def test_create_assignment(self):
         self.mock_auth.return_value.ok = True
@@ -122,7 +121,7 @@ class TestContentsServices(object):
         mock_input_body_patcher.stop()
         mock_upload_file_patcher.stop()
 
-        assert_equal(response, TEST_CREATED_ASSIGNMENT)
+        assert response == TEST_CREATED_ASSIGNMENT
 
 
     def test_delete_content(self):
@@ -136,7 +135,7 @@ class TestContentsServices(object):
 
         mock_delete_patcher.stop()
 
-        assert_equal(response.status_code, 204)
+        assert response.status_code == 204
 
     def test_update_content(self):
         self.mock_auth.return_value.ok = True
@@ -160,4 +159,4 @@ class TestContentsServices(object):
         mock_edit_title_patcher.stop()
         mock_edit_body_patcher.stop()
 
-        assert_equal(response, TEST_GET_CONTENT_UPDATED)
\ No newline at end of file
+        assert response == TEST_GET_CONTENT_UPDATED
\ No newline at end of file
diff --git a/tests/test_services/test_courses_services.py b/tests/test_services/test_courses_services.py
index 236ad2d..29c2fa0 100644
--- a/tests/test_services/test_courses_services.py
+++ b/tests/test_services/test_courses_services.py
@@ -5,7 +5,6 @@ import requests
 from bbcli.services.courses_services import list_all_courses, list_course
 
 from unittest.mock import Mock, patch
-from nose.tools import assert_list_equal, assert_equal
 
 TEST_COURSE = {
         'id':'_33050_1',
@@ -71,7 +70,7 @@ class TestCoursesServices(object):
         # Id is irrelavant here because the API call is mocked anyways
         response = list_course(test_session, '_33050_1')
 
-        assert_equal(response, TEST_COURSE)
+        assert response == TEST_COURSE
 
     # def test_list_courses(self):
     #     self.mock_auth.return_value.ok = True
@@ -111,4 +110,4 @@ class TestCoursesServices(object):
         test_session = requests.Session()
         response = list_all_courses(test_session, 'test_user')
 
-        assert_equal(response, TEST_COURSE_LIST)
\ No newline at end of file
+        assert response == TEST_COURSE_LIST
\ No newline at end of file
-- 
GitLab