def create_test_ticket(): ticket = Tickets(issuer_nickname='test_user', server='server', email='*****@*****.**', ip_address='127.0.0.1', files=None) ticket.create() return ticket
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 test_create_ticket_with_files(self): ticket = Tickets(issuer_nickname='test', server='server', email='*****@*****.**', ip_address='127.0.0.2', files=load_test_files()) ticket.create() ticket_files = loads(ticket.files)['files'] for file in ticket_files: self.assertTrue(path.exists(settings.SAVING_FILES_DIR + file))
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_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_should_be_resend_at(self): schedule.clear() ticket = Tickets(issuer_nickname='test', server='server', email='*****@*****.**', ip_address='127.0.0.2',) ticket.create() self.assertEquals(dt.strptime(ticket.datetime, '%Y-%m-%d %H:%M:%S') + timedelta(days=1), ticket.should_be_resend_at()) self.assertEquals(len(schedule.jobs), 1) ticket.add_comment('test answer', [], user='******') self.assertEquals(dt.strptime(ticket.datetime, '%Y-%m-%d %H:%M:%S') + timedelta(days=3), ticket.should_be_resend_at()) self.assertEquals(len(schedule.jobs), 1)
def create(request): issuer_nickname = request.POST['issuer_nickname'] # get files below. 'if not files' is necessary, because there are 2 drop zones with different names on one page files = request.FILES.getlist('dropZone_complaint', None) if not files: files = request.FILES.getlist('dropZone_appeal', None) server = request.POST['select_server'] email = request.POST['email'] ip_address = '127.0.0.1' if settings.DEBUG or settings.TEST_IN_PROGRESS else get_ip(request.META) ticket = Tickets(issuer_nickname=issuer_nickname, server=server, email=email, ip_address=ip_address, files=files) return ticket
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): 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_create_ticket_with_files(self): ticket = Tickets(issuer_nickname='test', server='server', email='*****@*****.**', ip_address='127.0.0.2', files=load_test_files()) ticket.create() ticket_files = loads(ticket.files)['files'] for file in ticket_files: self.assertTrue(path.exists(settings.SAVING_FILES_DIR + file)) def test_toggle_closed(self): self.ticket.toggle_closed() self.assertEquals(self.ticket.isClosed, 1) self.ticket.toggle_closed() self.assertEquals(self.ticket.isClosed, 0) 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 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) def test_add_comment_will_close(self): self.ticket.add_comment(answer='answer', files=None, will_close=False) self.assertEquals(self.ticket.isClosed, 0) self.ticket.add_comment(answer='answer', files=None, will_close=True) self.assertEquals(self.ticket.isClosed, 1) def test_add_comment_with_files(self): self.ticket.add_comment(answer='test', files=load_test_files()) conversation = loads(self.ticket.staff_answer)['comments'][0] self.assertEquals(conversation['text'], 'test') for file in conversation['files']: self.assertTrue(path.exists(settings.SAVING_FILES_DIR + file)) 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) 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_should_be_resend_at(self): schedule.clear() ticket = Tickets(issuer_nickname='test', server='server', email='*****@*****.**', ip_address='127.0.0.2',) ticket.create() self.assertEquals(dt.strptime(ticket.datetime, '%Y-%m-%d %H:%M:%S') + timedelta(days=1), ticket.should_be_resend_at()) self.assertEquals(len(schedule.jobs), 1) ticket.add_comment('test answer', [], user='******') self.assertEquals(dt.strptime(ticket.datetime, '%Y-%m-%d %H:%M:%S') + timedelta(days=3), ticket.should_be_resend_at()) self.assertEquals(len(schedule.jobs), 1)