def test_resend_multiple(self): schedule.clear() user = MyUser('authorized_2') user.create(True, False, 'pass', 'fist', 'last') user.manage_access(['control']) ticket1 = Tickets(issuer_nickname='test', server='server', email='*****@*****.**', ip_address='127.0.0.2', ) ticket1.create() ticket2 = Tickets(issuer_nickname='test', server='server', email='*****@*****.**', ip_address='127.0.0.2', ) ticket2.create() ticket_2_current_time = ticket2.datetime schedule.jobs[0].tag('TICKET 1') schedule.jobs[1].tag('TICKET 2') sleep(2) schedule.jobs[0].run() schedule.clear('TICKET 1') self.assertEquals(dt.strftime(dt.now(), '%Y-%m-%d %H:%M:%S'), ticket1.datetime) self.assertEquals(ticket_2_current_time, ticket2.datetime) self.assertEquals(len(schedule.jobs), 2)
def test_create_complaint_forbidden_violator(self): user = MyUser('osx11') user.create(True, False, 'pass', 'fist', 'last') user.manage_access(['staff']) with self.assertRaises(FieldContainsForbiddenException): self.ticket.create_complaint(violator_nickname='osx11', description='test_description', evidence=None)
class TestViews(TestCase): def setUp(self): self.username = '******' self.moderator = MyUser(self.username) self.moderator.create(True, False, 'pass', 'first', 'last') self.moderator.manage_access(['moders']) self.year = dt.now().isocalendar()[0] @staticmethod def __get_current_week(): return dt.now().isocalendar()[1] def __create_report_with_custom_week(self, week): report = Reports(violator_nickname='violator', violator_donate='donate', violation='violation', comment='comment', server='server', evidence_text='evidence_text', pinned_admin=self.username, date=dt.now().strftime('%Y-%m-%d %H:%M:%S'), week=week, year=self.year, isImportant=False, isWarning=False, files=None, dialogue=None) return report def test_weekly(self): report = self.__create_report_with_custom_week( self.__get_current_week() - 1) report.save() report = self.__create_report_with_custom_week( self.__get_current_week() - 1) report.save() report = self.__create_report_with_custom_week( self.__get_current_week()) report.save() client = Client() client.login(username=self.username, password='******') response = client.get(reverse('weekly')) filled_weeks = response.context['filled_weeks'] self.assertEquals( filled_weeks[self.__get_current_week()][1]['moderator'][0], 1) self.assertEquals( filled_weeks[self.__get_current_week()][1]['moderator'][1], -1) self.assertEquals( filled_weeks[self.__get_current_week() - 1][1]['moderator'][0], 2) self.assertEquals( filled_weeks[self.__get_current_week() - 1][1]['moderator'][1], 2)
def test_create_complaint_forbidden_issuer(self): user = MyUser('osx11') user.create(True, False, 'pass', 'fist', 'last') user.manage_access(['staff']) ticket = Tickets(issuer_nickname='osx11', server='server', email='*****@*****.**', ip_address='127.0.0.3', files=None) with self.assertRaises(FieldContainsForbiddenException): ticket.create_complaint(violator_nickname='test', description='desc', evidence=None)
def setUp(self): user = MyUser('test') user.create(True, False, 'pass', 'fist', 'last') user.manage_access(['control']) self.ticket = Tickets( issuer_nickname='test', server='test_server', email='*****@*****.**', ip_address='127.0.0.1', files=None ) self.ticket.create()
def test_resend(self): ticket = Tickets(issuer_nickname='test', server='server', email='*****@*****.**', ip_address='127.0.0.2',) ticket.create() schedule.clear() user = MyUser('authorized_2') user.create(True, False, 'pass', 'fist', 'last') user.manage_access(['control']) current_pinned_admin = ticket.pinned_admin ticket.resend() self.assertNotEquals(current_pinned_admin, ticket.pinned_admin) self.assertTrue(MyUser(ticket.pinned_admin.split(' ')[0]).has_access('control')) self.assertEquals(dt.strftime(dt.now(), '%Y-%m-%d %H:%M:%S'), ticket.datetime) self.assertEquals(len(schedule.jobs), 1) self.assertTrue(ticket.secret_key in schedule.jobs[0].tags)
class TestModels(TestCase): def setUp(self): self.username = '******' self.moderator = MyUser(self.username) self.moderator.create(True, False, 'pass', 'first', 'last') self.osx11 = MyUser('osx11') self.osx11.create(False, False, 'pass', 'Grigory', 'Albertov') self.report = Reports(violator_nickname='test_violator', violator_donate='test_donate', violation='test_violation', comment='test_comment', server='test_server', evidence_text='test_evidence', pinned_admin=self.username, isImportant=True, isWarning=False, files=load_test_files()) @staticmethod def __get_user_notifications(user): return user.notifications.unread()[0] def test_create_new_report(self): self.report.create() self.report.refresh_from_db() report_files = loads(self.report.files)['files'] for file in report_files: self.assertTrue(path.exists(settings.SAVING_FILES_DIR + file)) notification = self.__get_user_notifications(self.osx11.user) self.assertEquals( notification.verb, '%s отправил важный отчет (#%d)' % (self.username, self.report.id)) def test_remove(self): self.report.create() report_id = self.report.id self.report.remove(self.osx11.user) with self.assertRaises(ObjectDoesNotExist): self.report.refresh_from_db() notification = self.__get_user_notifications(self.moderator.user) self.assertEquals(notification.verb, '%s удалил ваш отчет (#%d)' % ('osx11', report_id)) def test_set_non_important(self): self.report.create() self.report.set_non_important(self.osx11.user) self.report.refresh_from_db() self.assertEquals(self.report.isImportant, 0) notification = self.__get_user_notifications(self.moderator.user) self.assertEquals( notification.verb, '%s просмотрел ваш важный отчет (#%d)' % ('osx11', self.report.id)) def test_add_comment(self): self.report.create() self.report.add_comment(load_test_files(), 'test_answer', self.osx11.user) self.report.refresh_from_db() comment_files = loads(self.report.dialogue)['comments'][0]['files'] for file in comment_files: self.assertTrue(path.exists(settings.SAVING_FILES_DIR + file)) notification = self.__get_user_notifications(self.moderator.user) self.assertEquals( notification.verb, '%s добавил комментарий к вашему отчету (#%d)' % ('osx11', self.report.id))
def setUp(self): user = MyUser('test') user.create(True, False, 'pass', 'fist', 'last')
def setUp(self): user = MyUser('test') user.create(True, False, 'pass', 'fist', 'last') user.manage_access(['control'])
def __create_authorized_user(): user = MyUser('authorized_user') user.create(True, False, 'pass', 'first', 'last') user.manage_access(['control']) return user