def test_display_protocols_by_date(self): client.login(username='******', password='******') client.post( '/protocols/add/', { "topics-TOTAL_FORMS": 2, "topics-INITIAL_FORMS": 0, "topics-MAX_NUM_FORMS": 1000, "institution": self.institution.pk, "number": "1234", "start_time": time(10, 0, 0), "scheduled_time": time(9, 0, 0), "quorum": 32, "absent": self.kril.pk, "attendents": self.kril.pk, "majority": 5, "current_majority": 4, "voted_for": 2, "voted_against": 3, "voted_abstain": 0, "information": 'this is the best protocol ever', }) start_date = str(date.today() - timedelta(days=3)) end_date = str(date.today() + timedelta(days=3)) response = client.get('/protocols/search/{}/{}/'.format( start_date, end_date)) self.assertEqual(200, response.status_code) self.assertEqual(1, len(response.context['protocols']))
def test_listing_page_of_protocols_with_over_30_protocols(self): before_add = Protocol.objects.count() client.login(username='******', password='******') for add_protocol in range(35): client.post( '/protocols/add/', { "topics-TOTAL_FORMS": 2, "topics-INITIAL_FORMS": 0, "topics-MAX_NUM_FORMS": 1000, "institution": self.institution.pk, "number": "{}".format(add_protocol), "start_time": time(10, 0, 0), "scheduled_time": time(9, 0, 0), "quorum": 32, "excused": self.kril.pk, "absent": self.kril.pk, "attendents": self.kril.pk, "majority": 5, "current_majority": 4, "voted_for": 2, "voted_against": 3, "voted_abstain": 0, "information": 'this is the best protocol ever', }) response_1 = client.get('/protocols/archive/1/') response_2 = client.get('/protocols/archive/2/') after_add = Protocol.objects.count() self.assertEqual(200, response_1.status_code) self.assertEqual(200, response_2.status_code) self.assertEqual(before_add + 35, after_add) self.assertEqual(30, len(response_1.context['protocols'])) self.assertEqual(5, len(response_2.context['protocols']))
def test_display_protocols_by_date(self): client.login(username='******', password='******') client.post('/protocols/add/', { "topics-TOTAL_FORMS": 2, "topics-INITIAL_FORMS": 0, "topics-MAX_NUM_FORMS": 1000, "institution": self.institution.pk, "number": "1234", "start_time": time(10, 0, 0), "scheduled_time": time(9, 0, 0), "quorum": 32, "absent": self.kril.pk, "attendents": self.kril.pk, "majority": 5, "current_majority": 4, "voted_for": 2, "voted_against": 3, "voted_abstain": 0, "information": 'this is the best protocol ever', }) start_date = str(date.today() - timedelta(days=3)) end_date = str(date.today() + timedelta(days=3)) response = client.get('/protocols/search/{}/{}/'.format(start_date, end_date)) self.assertEqual(200, response.status_code) self.assertEqual(1, len(response.context['protocols']))
def test_user_reports_count_2(self): before_add = Report.objects.count() copies_before_add = Copy.objects.count() client.login(username='******', password='******') response = client.post('/reports/add/', { "copies-TOTAL_FORMS": 2, "copies-INITIAL_FORMS": 0, "copies-MAX_NUM_FORMS": 1000, "addressed_to": "Hackfmi", "reported_from": self.kril.pk, "content": "This is a report test", "copies-0-about_topic": self.topic1.pk, "copies-1-about_topic": self.topic2.pk, "signed_from": "rozovo zaiche", }) self.assertEqual(200, response.status_code) response = client.post('/reports/add/', { "copies-TOTAL_FORMS": 2, "copies-INITIAL_FORMS": 0, "copies-MAX_NUM_FORMS": 1000, "addressed_to": "Hackfmi", "reported_from": self.kril.pk, "content": "This is a report test", "signed_from": "rozovo zaiche", }) after_add = Report.objects.count() copies_after_add = Copy.objects.count() self.assertEqual(200, response.status_code) self.assertEqual(before_add + 2, after_add) self.assertEqual(copies_before_add + 2, copies_after_add)
def test_user_reports_count_2(self): before_add = Report.objects.count() copies_before_add = Copy.objects.count() client.login(username='******', password='******') response = client.post( '/reports/add/', { "copies-TOTAL_FORMS": 2, "copies-INITIAL_FORMS": 0, "copies-MAX_NUM_FORMS": 1000, "addressed_to": "Hackfmi", "reported_from": self.kril.pk, "content": "This is a report test", "copies-0-about_topic": self.topic1.pk, "copies-1-about_topic": self.topic2.pk, "signed_from": "rozovo zaiche", }) self.assertEqual(200, response.status_code) response = client.post( '/reports/add/', { "copies-TOTAL_FORMS": 2, "copies-INITIAL_FORMS": 0, "copies-MAX_NUM_FORMS": 1000, "addressed_to": "Hackfmi", "reported_from": self.kril.pk, "content": "This is a report test", "signed_from": "rozovo zaiche", }) after_add = Report.objects.count() copies_after_add = Copy.objects.count() self.assertEqual(200, response.status_code) self.assertEqual(before_add + 2, after_add) self.assertEqual(copies_before_add + 2, copies_after_add)
def test_listing_page_of_protocols_with_over_30_protocols(self): before_add = Protocol.objects.count() client.login(username='******', password='******') for add_protocol in range(35): client.post('/protocols/add/', { "topics-TOTAL_FORMS": 2, "topics-INITIAL_FORMS": 0, "topics-MAX_NUM_FORMS": 1000, "institution": self.institution.pk, "number": "{}".format(add_protocol), "start_time": time(10, 0, 0), "scheduled_time": time(9, 0, 0), "quorum": 32, "excused": self.kril.pk, "absent": self.kril.pk, "attendents": self.kril.pk, "majority": 5, "current_majority": 4, "voted_for": 2, "voted_against": 3, "voted_abstain": 0, "information": 'this is the best protocol ever', }) response_1 = client.get('/protocols/archive/1/') response_2 = client.get('/protocols/archive/2/') after_add = Protocol.objects.count() self.assertEqual(200, response_1.status_code) self.assertEqual(200, response_2.status_code) self.assertEqual(before_add + 35, after_add) self.assertEqual(30, len(response_1.context['protocols'])) self.assertEqual(5, len(response_2.context['protocols']))
def test_action_unlike(self): client = self.get_client() response = client.post("/api/tweets/action/", {"id": 2, "action": "like"}) self.assertEqual(response.status_code, 200) response = client.post("/api/tweets/action/", {"id": 2, "action": "unlike"}) self.assertEqual(response.status_code, 200) like_count = response.json().get("likes") self.assertEqual(like_count, 0) print(response.json())
def test_add_protocols_with_same_numbers(self): before_add = Protocol.objects.count() client.login(username='******', password='******') response1 = client.post( '/protocols/add/', { "topics-TOTAL_FORMS": 2, "topics-INITIAL_FORMS": 0, "topics-MAX_NUM_FORMS": 1000, "institution": self.institution.pk, "number": "13/11/1992/1234", "start_time": time(10, 0, 0), "scheduled_time": time(9, 0, 0), "quorum": 32, "excused": self.kril.pk, "absent": self.kril.pk, "attendents": self.kril.pk, "majority": 5, "current_majority": 4, "voted_for": 2, "voted_against": 3, "voted_abstain": 0, "information": 'this is the best protocol ever', }) response2 = client.post( '/protocols/add/', { "topics-TOTAL_FORMS": 2, "topics-INITIAL_FORMS": 0, "topics-MAX_NUM_FORMS": 1000, "institution": self.institution.pk, "number": "13/11/1992/1234", "start_time": time(10, 0, 0), "scheduled_time": time(9, 0, 0), "quorum": 32, "excused": self.kril.pk, "absent": self.kril.pk, "attendents": self.kril.pk, "majority": 5, "current_majority": 4, "voted_for": 2, "voted_against": 3, "voted_abstain": 0, "information": 'this is the best protocol ever', }) after_add = Protocol.objects.count() self.assertEqual(200, response1.status_code) self.assertEqual(200, response2.status_code) self.assertEqual(before_add + 1, after_add)
def test_listing_page_of_reports(self): before_add = Report.objects.count() copies_before_add = Copy.objects.count() client.login(username='******', password='******') for report in range(10): response = client.post( '/reports/add/', { "copies-TOTAL_FORMS": 2, "copies-INITIAL_FORMS": 0, "copies-MAX_NUM_FORMS": 1000, "addressed_to": "Hackfmi", "reported_from": self.kril.pk, "content": "This is a report test", "copies-0-about_topic": self.topic1.pk, "copies-1-about_topic": self.topic2.pk, "copies-2-about_topic": self.topic3.pk, "signed_from": "rozovo zaiche", }) response = client.get('/reports/archive/1/') after_add = Report.objects.all().count() copies_after_add = Copy.objects.count() self.assertEqual(200, response.status_code) self.assertEqual(before_add + 10, after_add) self.assertEqual(copies_before_add + 20, copies_after_add) self.assertEqual(after_add, len(response.context['reports']))
def test_display_protocol_by_id(self): client.login(username='******', password='******') c_post = client.post('/protocols/add/', { "topics-TOTAL_FORMS": 2, "topics-INITIAL_FORMS": 0, "topics-MAX_NUM_FORMS": 1000, "institution": self.institution.pk, "number": "1234", "start_time": time(10, 0, 0), "scheduled_time": time(9, 0, 0), "quorum": 32, "excused": self.kril.pk, "absent": self.kril.pk, "attendents": self.kril.pk, "majority": 5, "current_majority": 4, "voted_for": 2, "voted_against": 3, "voted_abstain": 0, "information": 'this is the best protocol ever', }) response = client.get('/protocols/archive/review/{}/'.format( c_post.context['protocol'].pk)) self.assertEqual(200, response.status_code)
def test_update_user_information(self): client.login(username='******', password='******') before_add = Protocol.objects.count() response = client.post('/protocols/add/', { "topics-TOTAL_FORMS": 2, "topics-INITIAL_FORMS": 0, "topics-MAX_NUM_FORMS": 1000, "institution": self.institution.pk, "number": "13/11/1992/1234", "scheduled_time": time(9, 0, 0), "start_time": time(10, 0, 0), "quorum": 32, "excused": self.kril.pk, "absent": self.kril.pk, "attendents": self.kril.pk, "majority": 5, "current_majority": 4, "voted_for": 2, "voted_against": 3, "voted_abstain": 0, "information": 'this is the best protocol ever', }) after_add = Protocol.objects.count() self.assertEqual(200, response.status_code) self.assertEqual(before_add + 1, after_add)
def test_edit_project_impossible_from_this_user(self): '''this user is not the creator of the project''' client.login(username='******', password='******') before_edit = Project.objects.filter(name='some other name').count() project = Project.objects.create( user=self.user, flp=self.user, name='New project', description='spam', tasks='spam', targets='spam', target_group='spam', schedule='spam', resources='spam', finance_description='spam') data_copy = self.test_data.copy() data_copy.update({'name': 'some other name'}) response = client.post('/projects/edit/{}/'.format(project.pk), data_copy) after_edit = Project.objects.filter(name='some other name').count() self.assertEqual(response.status_code, 302) self.assertEqual(before_edit, after_edit)
def test_display_protocol_by_id(self): client.login(username='******', password='******') c_post = client.post( '/protocols/add/', { "topics-TOTAL_FORMS": 2, "topics-INITIAL_FORMS": 0, "topics-MAX_NUM_FORMS": 1000, "institution": self.institution.pk, "number": "1234", "start_time": time(10, 0, 0), "scheduled_time": time(9, 0, 0), "quorum": 32, "excused": self.kril.pk, "absent": self.kril.pk, "attendents": self.kril.pk, "majority": 5, "current_majority": 4, "voted_for": 2, "voted_against": 3, "voted_abstain": 0, "information": 'this is the best protocol ever', }) response = client.get('/protocols/archive/review/{}/'.format( c_post.context['protocol'].pk)) self.assertEqual(200, response.status_code)
def test_add_protocol_with_topic(self): before_add = Protocol.objects.count() topics_count_before = Topic.objects.count() client.login(username='******', password='******') response = client.post( '/protocols/add/', { "topics-TOTAL_FORMS": 1, "topics-INITIAL_FORMS": 0, "topics-MAX_NUM_FORMS": 1000, "institution": self.institution.pk, "number": "13/11/1992/1234", "start_time": time(10, 0, 0), "scheduled_time": time(9, 0, 0), "quorum": 32, "absent": self.kril.pk, "attendents": self.kril.pk, "majority": 5, "current_majority": 4, "information": 'this is the best protocol ever', "topics-0-name": "topic", "topics-0-voted_for": 4, "topics-0-voted_against": 4, "topics-0-voted_abstain": 4, "topics-0-statement": "4", })
def test_listing_page_of_reports(self): before_add = Report.objects.count() copies_before_add = Copy.objects.count() client.login(username='******', password='******') for report in range(10): response = client.post('/reports/add/', { "copies-TOTAL_FORMS": 2, "copies-INITIAL_FORMS": 0, "copies-MAX_NUM_FORMS": 1000, "addressed_to": "Hackfmi", "reported_from": self.kril.pk, "content": "This is a report test", "copies-0-about_topic": self.topic1.pk, "copies-1-about_topic": self.topic2.pk, "copies-2-about_topic": self.topic3.pk, "signed_from": "rozovo zaiche", }) response = client.get('/reports/archive/1/') after_add = Report.objects.all().count() copies_after_add = Copy.objects.count() self.assertEqual(200, response.status_code) self.assertEqual(before_add + 10, after_add) self.assertEqual(copies_before_add + 20, copies_after_add) self.assertEqual(after_add, len(response.context['reports']))
def test_action_like(self): client = self.get_client() response = client.post("/api/tweets/action/", { "id": 1, "action": "like" }) self.assertEqual(response.status_code, 200)
def test_edit_project_impossible_from_this_user(self): '''this user is not the creator of the project''' client.login(username='******', password='******') before_edit = Project.objects.filter(name='some other name').count() project = Project.objects.create(user=self.user, flp=self.user, name='New project', description='spam', tasks='spam', targets='spam', target_group='spam', schedule='spam', resources='spam', finance_description='spam') data_copy = self.test_data.copy() data_copy.update({'name': 'some other name'}) response = client.post('/projects/edit/{}/'.format(project.pk), data_copy) after_edit = Project.objects.filter(name='some other name').count() self.assertEqual(response.status_code, 302) self.assertEqual(before_edit, after_edit)
def test_create_api_view(self): request_data = {"content": "This is my test tweet"} client = self.get_client() response = client.post("/api/tweets/create/", request_data) self.assertEqual(response.status_code, 201) response_data = response.json() new_tweet_id = response_data.get("id") self.assertEqual(self.currentCount + 1, new_tweet_id)
def test_listing_page_of_protocols(self): before_add = Protocol.objects.count() client.login(username='******', password='******') client.post( '/protocols/add/', { "topics-TOTAL_FORMS": 2, "topics-INITIAL_FORMS": 0, "topics-MAX_NUM_FORMS": 1000, "institution": self.institution.pk, "number": "1234", "start_time": time(10, 0, 0), "scheduled_time": time(9, 0, 0), "quorum": 32, "absent": self.kril.pk, "attendents": self.kril.pk, "majority": 5, "current_majority": 4, "information": 'this is the best protocol ever', }) client.post( '/protocols/add/', { "topics-TOTAL_FORMS": 2, "topics-INITIAL_FORMS": 0, "topics-MAX_NUM_FORMS": 1000, "institution": self.institution.pk, "number": "13/11/1992/1235", "start_time": time(10, 0, 0), "scheduled_time": time(9, 0, 0), "quorum": 32, "absent": self.kril.pk, "attendents": self.kril.pk, "majority": 5, "current_majority": 4, "information": 'this is the best protocol ever', }) response = client.get('/protocols/archive/1/') after_add = Protocol.objects.count() topic = Topic.objects.filter(name="topic", statement="4").exists() topics_count_after = Topic.objects.count() self.assertEqual(200, response.status_code) self.assertEqual(before_add + 2, after_add) self.assertEqual(after_add, len(response.context['protocols']))
def test_signup_invalid_key(self): client = Client() user = {'email': '*****@*****.**', 'password': '******'} response = client.post('/user/signup', json.dumps(user), content_type='application/json') self.assertEqual(response.status_code, 400) self.assertEqual(response.json(), {'message': 'KEY_ERROR'})
def test_action_retweet(self): client = self.get_client() current_count = self.currentCount response = client.post("/api/tweets/action/", {"id": 2, "action": "retweet"}) self.assertEqual(response.status_code, 201) data = response.json() new_tweet_id = data.get("id") self.assertNotEqual(2, new_tweet_id) self.assertEqual(current_count + 1, new_tweet_id) print(response.json())
def test_listing_page_of_protocols(self): before_add = Protocol.objects.count() client.login(username='******', password='******') client.post('/protocols/add/', { "topics-TOTAL_FORMS": 2, "topics-INITIAL_FORMS": 0, "topics-MAX_NUM_FORMS": 1000, "institution": self.institution.pk, "number": "1234", "start_time": time(10, 0, 0), "scheduled_time": time(9, 0, 0), "quorum": 32, "absent": self.kril.pk, "attendents": self.kril.pk, "majority": 5, "current_majority": 4, "information": 'this is the best protocol ever', }) client.post('/protocols/add/', { "topics-TOTAL_FORMS": 2, "topics-INITIAL_FORMS": 0, "topics-MAX_NUM_FORMS": 1000, "institution": self.institution.pk, "number": "13/11/1992/1235", "start_time": time(10, 0, 0), "scheduled_time": time(9, 0, 0), "quorum": 32, "absent": self.kril.pk, "attendents": self.kril.pk, "majority": 5, "current_majority": 4, "information": 'this is the best protocol ever', }) response = client.get('/protocols/archive/1/') after_add = Protocol.objects.count() topic = Topic.objects.filter(name="topic", statement="4").exists() topics_count_after = Topic.objects.count() self.assertEqual(200, response.status_code) self.assertEqual(before_add + 2, after_add) self.assertEqual(after_add, len(response.context['protocols']))
def test_login_post_success(self): client = Client() user = { 'email': '*****@*****.**', 'password': '******', 'name': '최인아' } response = client.post('/user/login', json.dumps(user), content_type='application/json') self.assertEqual(response.status_code, 200)
def test_signup_post_success(self): client = Client() user = { 'email': '*****@*****.**', 'password': '******', 'name': 'inah', 'maketing_is_agreed': True, } response = client.post('/user/signup', json.dumps(user), content_type='application/json') self.assertEqual(response.status_code, 201)
def test_login_does_not_exist(self): client = Client() user = { 'email': '*****@*****.**', 'password': '******', 'name': '최왓더' } response = client.post('/user/login', json.dumps(user), content_type='application/json') self.assertEqual(response.status_code, 401) self.assertEqual(response.json(), {'message': 'INVALID_USER'})
def test_signup_password_format_validation(self): client = Client() user = { 'email': '*****@*****.**', 'password': '******', 'name': 'inah', } response = client.post('/user/signup', json.dumps(user), content_type='application/json') self.assertEqual(response.status_code, 400) self.assertEqual(response.json(), {'message': 'INVALID_VALUE'})
def test_signup_email_exists(self): client = Client() user = { 'email': '*****@*****.**', 'password': '******', 'name': 'inah', 'maketing_is_agreed': True, } response = client.post('/user/signup', json.dumps(user), content_type='application/json') self.assertEqual(response.status_code, 400) self.assertEqual(response.json(), {'message': 'ALREADY_EXISTS'})
def test_adding_incomplete_project(self): client.login(username='******', password='******') before_add = Project.objects.count() response = client.post('/projects/add/', { 'team': [self.user.pk], 'name': 'New project', 'description': 'spam', 'target_group': 'spam', 'schedule': 'spam', 'resources': 'spam', 'finance_description': 'spam'}) after_add = Project.objects.count() self.assertEqual(response.status_code, 200) self.assertEqual(before_add, after_add)
def test_adding_new_project_from_user_who_is_not_logged(self): before_add = Project.objects.count() response = client.post('/projects/add/', { 'team': [self.user.pk], 'name': 'New project', 'description': 'spam', 'tasks': 'spam', 'targets': 'spam', 'target_group': 'spam', 'schedule': 'spam', 'resources': 'spam', 'finance_description': 'spam'}) after_add = Project.objects.count() self.assertEqual(response.status_code, 302) self.assertEqual(before_add, after_add)
def test_show_projects_archive(self): client.login(username='******', password='******') for project_number in range(10): project = Project.objects.create( user=self.not_master, flp=self.not_master, name='Project{}'.format(project_number), description='spam', tasks='spam', targets='spam', target_group='spam', schedule='spam', resources='spam', finance_description='spam') if project_number < 4: client.post('/projects/edit_status/{}/'.format(project.pk), {'status': 'approved'}) response = client.get('/projects/archive/') self.assertEqual(200, response.status_code) self.assertEqual(6, len(response.context['unrevised'])) self.assertEqual(4, len(response.context['approved']))
def test_show_projects_archive(self): client.login(username='******', password='******') for project_number in range(10): project = Project.objects.create( user=self.not_master, flp=self.not_master, name='Project{}'.format(project_number), description='spam', tasks='spam', targets='spam', target_group='spam', schedule='spam', resources='spam', finance_description='spam') if project_number < 4: client.post('/projects/edit_status/{}/'.format(project.pk), { 'status': 'approved'}) response = client.get('/projects/archive/') self.assertEqual(200, response.status_code) self.assertEqual(6, len(response.context['unrevised'])) self.assertEqual(4, len(response.context['approved']))
def test_all_protocol_fields(self): before_add = Protocol.objects.count() topics_count_before = Topic.objects.count() client.login(username='******', password='******') with open( os.path.join(settings.PROJECT_PATH, 'static/img/chrome_logo.png')) as f: response = client.post( '/protocols/add/', { "topics-TOTAL_FORMS": 1, "topics-INITIAL_FORMS": 0, "topics-MAX_NUM_FORMS": 1000, "institution": self.institution.pk, "number": "13/11/1992/1234", "start_time": time(10, 0, 0), "scheduled_time": time(9, 0, 0), "quorum": 32, "excused": self.kril.pk, "absent": self.kril.pk, "attendents": self.kril.pk, "majority": 5, "current_majority": 4, "voted_for": 2, "voted_against": 3, "voted_abstain": 0, "information": 'this is the best protocol ever', "topics-0-name": "topic", "topics-0-voted_for": 4, "topics-0-voted_against": 4, "topics-0-voted_abstain": 4, "topics-0-statement": "4", "additional": " Additional", "information": "Information", "files": f, "topics-0-files1": f, "topics-0-files2": f, }) topics_count_after = Topic.objects.count() after_add = Protocol.objects.count() protocol = Protocol.objects.get(number="13/11/1992/1234") self.assertEqual(response.status_code, 200) self.assertEqual(before_add + 1, after_add) self.assertEqual(topics_count_before + 1, topics_count_after) self.assertEqual(protocol.topics.all()[0].name, "topic") self.assertTrue(protocol.files.exists()) self.assertTrue(protocol.topics.all()[0].files.exists()) self.assertEqual(protocol.topics.all()[0].files.all().count(), 2)
def test_add_report_no_copies(self): client.login(username='******', password='******') before_add = Report.objects.count() response = client.post('/reports/add/', { "copies-TOTAL_FORMS": 2, "copies-INITIAL_FORMS": 0, "copies-MAX_NUM_FORMS": 1000, "addressed_to": "Hackfmi", "reported_from": self.kril.pk, "content": "This is a report test", "signed_from": "rozovo zaiche", }) after_add = Report.objects.count() self.assertEqual(200, response.status_code) self.assertEqual(before_add + 1, after_add)
def test_unauthorised_to_report_user(self): before_add = Report.objects.count() client.login(username='******', password='******') for report in range(10): response = client.post('/reports/add/', { "copies-TOTAL_FORMS": 2, "copies-INITIAL_FORMS": 0, "copies-MAX_NUM_FORMS": 1000, "addressed_to": "Hackfmi", "reported_from": self.kril.pk, "content": "This is a report test", "signed_from": "rozovo zaiche", }) after_add = Report.objects.count() self.assertEqual(302, response.status_code) self.assertEqual(before_add, after_add)
def test_adding_incomplete_project(self): client.login(username='******', password='******') before_add = Project.objects.count() response = client.post( '/projects/add/', { 'team': [self.user.pk], 'name': 'New project', 'description': 'spam', 'target_group': 'spam', 'schedule': 'spam', 'resources': 'spam', 'finance_description': 'spam' }) after_add = Project.objects.count() self.assertEqual(response.status_code, 200) self.assertEqual(before_add, after_add)
def test_adding_new_project_from_user_who_is_not_logged(self): before_add = Project.objects.count() response = client.post( '/projects/add/', { 'team': [self.user.pk], 'name': 'New project', 'description': 'spam', 'tasks': 'spam', 'targets': 'spam', 'target_group': 'spam', 'schedule': 'spam', 'resources': 'spam', 'finance_description': 'spam' }) after_add = Project.objects.count() self.assertEqual(response.status_code, 302) self.assertEqual(before_add, after_add)
def test_edit_project_with_not_logged_in_user(self): Project.objects.create(user=self.not_master, flp=self.user, name='New project', description='spam', tasks='spam', targets='spam', target_group='spam', schedule='spam', resources='spam', finance_description='spam') before_add = Project.objects.count() response = client.post('/projects/edit/1/', {'name': 'some other name'}) after_add = Project.objects.count() self.assertEqual(response.status_code, 302) self.assertEqual(before_add, after_add)
def test_add_protocol_without_being_logged(self): response = client.post('/protocols/add/', { "topics-TOTAL_FORMS": 2, "topics-INITIAL_FORMS": 0, "topics-MAX_NUM_FORMS": 1000, "institution": self.institution.pk, "number": "13/11/1992/1234", "scheduled_time": time(9, 0, 0), "start_time": time(10, 0, 0), "quorum": 32, "absent": self.kril.pk, "attendents": self.kril.pk, "majority": 5, "current_majority": 4, "information": 'this is the best protocol ever', }) self.assertEqual(302, response.status_code)
def test_edit_project_with_not_logged_in_user(self): Project.objects.create( user=self.not_master, flp=self.user, name='New project', description='spam', tasks='spam', targets='spam', target_group='spam', schedule='spam', resources='spam', finance_description='spam') before_add = Project.objects.count() response = client.post('/projects/edit/1/', { 'name': 'some other name'}) after_add = Project.objects.count() self.assertEqual(response.status_code, 302) self.assertEqual(before_add, after_add)
def test_edit_status_of_project_user_has_permissions(self): client.login(username='******', password='******') Project.objects.create(user=self.not_master, flp=self.user, name='New project', description='spam', tasks='spam', targets='spam', target_group='spam', schedule='spam', resources='spam', finance_description='spam') before_add = Project.objects.count() response = client.post('/projects/edit_status/1/', {'status': 'approved'}) after_add = Project.objects.count() self.assertEqual(response.status_code, 302) self.assertEqual(before_add, after_add)
def test_add_report_no_copies(self): client.login(username='******', password='******') before_add = Report.objects.count() response = client.post( '/reports/add/', { "copies-TOTAL_FORMS": 2, "copies-INITIAL_FORMS": 0, "copies-MAX_NUM_FORMS": 1000, "addressed_to": "Hackfmi", "reported_from": self.kril.pk, "content": "This is a report test", "signed_from": "rozovo zaiche", }) after_add = Report.objects.count() self.assertEqual(200, response.status_code) self.assertEqual(before_add + 1, after_add)
def test_edit_project_from_its_creator(self): client.login(username='******', password='******') Project.objects.create(user=self.not_master, flp=self.user, name='New project', description='spam', tasks='spam', targets='spam', target_group='spam', schedule='spam', resources='spam', finance_description='spam') before_add = Project.objects.count() response = client.post('/projects/edit/1/', {'name': 'some other name'}) after_add = Project.objects.count() self.assertEqual(response.status_code, 200) self.assertEqual(before_add, after_add)
def test_unauthorised_to_report_user(self): before_add = Report.objects.count() client.login(username='******', password='******') for report in range(10): response = client.post( '/reports/add/', { "copies-TOTAL_FORMS": 2, "copies-INITIAL_FORMS": 0, "copies-MAX_NUM_FORMS": 1000, "addressed_to": "Hackfmi", "reported_from": self.kril.pk, "content": "This is a report test", "signed_from": "rozovo zaiche", }) after_add = Report.objects.count() self.assertEqual(302, response.status_code) self.assertEqual(before_add, after_add)
def test_edit_status_of_project_user_has_permissions(self): client.login(username='******', password='******') Project.objects.create( user=self.not_master, flp=self.user, name='New project', description='spam', tasks='spam', targets='spam', target_group='spam', schedule='spam', resources='spam', finance_description='spam') before_add = Project.objects.count() response = client.post('/projects/edit_status/1/', { 'status': 'approved'}) after_add = Project.objects.count() self.assertEqual(response.status_code, 302) self.assertEqual(before_add, after_add)
def test_add_protocol_without_being_logged(self): response = client.post( '/protocols/add/', { "topics-TOTAL_FORMS": 2, "topics-INITIAL_FORMS": 0, "topics-MAX_NUM_FORMS": 1000, "institution": self.institution.pk, "number": "13/11/1992/1234", "scheduled_time": time(9, 0, 0), "start_time": time(10, 0, 0), "quorum": 32, "absent": self.kril.pk, "attendents": self.kril.pk, "majority": 5, "current_majority": 4, "information": 'this is the best protocol ever', }) self.assertEqual(302, response.status_code)
def test_edit_project_from_its_creator(self): client.login(username='******', password='******') Project.objects.create( user=self.not_master, flp=self.user, name='New project', description='spam', tasks='spam', targets='spam', target_group='spam', schedule='spam', resources='spam', finance_description='spam') before_add = Project.objects.count() response = client.post('/projects/edit/1/', { 'name': 'some other name'}) after_add = Project.objects.count() self.assertEqual(response.status_code, 200) self.assertEqual(before_add, after_add)
def test_add_protocol_with_two_topics(self): before_add = Protocol.objects.count() topics_count_before = Topic.objects.count() client.login(username='******', password='******') response = client.post( '/protocols/add/', { "topics-TOTAL_FORMS": 2, "topics-INITIAL_FORMS": 0, "topics-MAX_NUM_FORMS": 1000, "institution": self.institution.pk, "number": "13/11/1992/1234", "start_time": time(10, 0, 0), "scheduled_time": time(9, 0, 0), "quorum": 32, "excused": self.kril.pk, "absent": self.kril.pk, "attendents": self.kril.pk, "majority": 5, "current_majority": 4, "voted_for": 2, "voted_against": 3, "voted_abstain": 0, "information": 'this is the best protocol ever', "topics-0-name": "topic", "topics-0-voted_for": 4, "topics-0-voted_against": 4, "topics-0-voted_abstain": 4, "topics-0-statement": "4", "topics-1-name": "topic2", "topics-1-voted_for": 4, "topics-1-voted_against": 4, "topics-1-voted_abstain": 4, "topics-1-statement": "4", }) after_add = Protocol.objects.count() topic = Topic.objects.filter(name="topic", statement="4").exists() topics_count_after = Topic.objects.count() self.assertEqual(200, response.status_code) self.assertEqual(before_add + 1, after_add) self.assertTrue(topic) self.assertEqual(topics_count_before + 2, topics_count_after)
def test_change_status_impossible_from_this_user(self): '''this user is the project creator, but cannot edit its status''' client.login(username='******', password='******') Project.objects.create( user=self.not_master, flp=self.user, name='New project', description='spam', tasks='spam', targets='spam', target_group='spam', schedule='spam', resources='spam', finance_description='spam') before_add = Project.objects.count() response = client.post('/projects/edit_status/1/', { 'status': 'approved'}) after_add = Project.objects.count() self.assertEqual(response.status_code, 302) self.assertEqual(before_add, after_add)
def test_user_not_able_to_add_protocols(self): before_add = Protocol.objects.count() client.login(username='******', password='******') response1 = client.post('/protocols/add/', { "topics-TOTAL_FORMS": 2, "topics-INITIAL_FORMS": 0, "topics-MAX_NUM_FORMS": 1000, "institution": self.institution.pk, "number": "13/11/1992/1234", "start_time": time(10, 0, 0), "scheduled_time": time(9, 0, 0), "quorum": 32, "absent": self.kril.pk, "attendents": self.kril.pk, "majority": 5, "current_majority": 4, "information": 'this is the best protocol ever', }) after_add = Protocol.objects.count() self.assertEqual(302, response1.status_code) self.assertEqual(before_add, after_add)
def test_add_protocol_with_two_topics(self): before_add = Protocol.objects.count() topics_count_before = Topic.objects.count() client.login(username='******', password='******') response = client.post('/protocols/add/', { "topics-TOTAL_FORMS": 2, "topics-INITIAL_FORMS": 0, "topics-MAX_NUM_FORMS": 1000, "institution": self.institution.pk, "number": "13/11/1992/1234", "start_time": time(10, 0, 0), "scheduled_time": time(9, 0, 0), "quorum": 32, "excused": self.kril.pk, "absent": self.kril.pk, "attendents": self.kril.pk, "majority": 5, "current_majority": 4, "voted_for": 2, "voted_against": 3, "voted_abstain": 0, "information": 'this is the best protocol ever', "topics-0-name": "topic", "topics-0-voted_for": 4, "topics-0-voted_against": 4, "topics-0-voted_abstain": 4, "topics-0-statement": "4", "topics-1-name": "topic2", "topics-1-voted_for": 4, "topics-1-voted_against": 4, "topics-1-voted_abstain": 4, "topics-1-statement": "4", }) after_add = Protocol.objects.count() topic = Topic.objects.filter(name="topic", statement="4").exists() topics_count_after = Topic.objects.count() self.assertEqual(200, response.status_code) self.assertEqual(before_add + 1, after_add) self.assertTrue(topic) self.assertEqual(topics_count_before + 2, topics_count_after)
def test_master_can_edit_status(self): client.login(username='******', password='******') before_edit = Project.objects.filter(status='rejected').count() project = Project.objects.create( user=self.not_master, flp=self.not_master, name='New project', description='spam', tasks='spam', targets='spam', target_group='spam', schedule='spam', resources='spam', finance_description='spam') response = client.post('/projects/edit_status/{}/'.format(project.pk), { 'status': 'rejected'}) after_edit = Project.objects.filter(status='rejected').count() self.assertEqual(response.status_code, 302) self.assertEqual(before_edit + 1, after_edit)
def test_add_protocol_with_topic(self): before_add = Protocol.objects.count() topics_count_before = Topic.objects.count() client.login(username='******', password='******') response = client.post('/protocols/add/', { "topics-TOTAL_FORMS": 1, "topics-INITIAL_FORMS": 0, "topics-MAX_NUM_FORMS": 1000, "institution": self.institution.pk, "number": "13/11/1992/1234", "start_time": time(10, 0, 0), "scheduled_time": time(9, 0, 0), "quorum": 32, "absent": self.kril.pk, "attendents": self.kril.pk, "majority": 5, "current_majority": 4, "information": 'this is the best protocol ever', "topics-0-name": "topic", "topics-0-voted_for": 4, "topics-0-voted_against": 4, "topics-0-voted_abstain": 4, "topics-0-statement": "4", })
def test_edit_project_with_not_logged_in_user(self): before_edit = Project.objects.filter(name='some other name').count() project = Project.objects.create( user=self.not_master, flp=self.user, name='New project', description='spam', tasks='spam', targets='spam', target_group='spam', schedule='spam', resources='spam', finance_description='spam') data_copy = self.test_data.copy() data_copy.update({'name': 'some other name'}) response = client.post('/projects/edit/{}/'.format(project.pk), data_copy) after_edit = Project.objects.filter(name='some other name').count() self.assertEqual(response.status_code, 302) self.assertEqual(before_edit, after_edit)