def test_related_tickets_attribute_accepts_list_of_Ticket_instances(self): """testing if the related tickets attribute accepts only list of stalker.models.ticket.Ticket instances """ new_ticket1 = Ticket(**self.kwargs) new_ticket2 = Ticket(**self.kwargs) self.test_ticket.related_tickets = [new_ticket1, new_ticket2]
def test_number_attribute_is_not_created_per_project(self): """testing if the number attribute is not created per project and continues to increase for every created ticket """ from stalker import Project proj1 = Project(name='Test Project 1', code='TP1', repository=self.test_repo, status_list=self.test_project_status_list) proj2 = Project(name='Test Project 2', code='TP2', repository=self.test_repo, status_list=self.test_project_status_list) proj3 = Project(name='Test Project 3', code='TP3', repository=self.test_repo, status_list=self.test_project_status_list) from stalker import db, Ticket p1_t1 = Ticket(project=proj1) db.DBSession.add(p1_t1) db.DBSession.commit() self.assertEqual(p1_t1.number, 2) p1_t2 = Ticket(project=proj1) db.DBSession.add(p1_t2) db.DBSession.commit() self.assertEqual(p1_t2.number, 3) p2_t1 = Ticket(project=proj2) db.DBSession.add(p2_t1) db.DBSession.commit() self.assertEqual(p2_t1.number, 4) p1_t3 = Ticket(project=proj1) db.DBSession.add(p1_t3) db.DBSession.commit() self.assertEqual(p1_t3.number, 5) p3_t1 = Ticket(project=proj3) db.DBSession.add(p3_t1) db.DBSession.commit() self.assertEqual(p3_t1.number, 6) p2_t2 = Ticket(project=proj2) db.DBSession.add(p2_t2) db.DBSession.commit() self.assertEqual(p2_t2.number, 7) p3_t2 = Ticket(project=proj3) db.DBSession.add(p3_t2) db.DBSession.commit() self.assertEqual(p3_t2.number, 8) p2_t3 = Ticket(project=proj2) db.DBSession.add(p2_t3) db.DBSession.commit() self.assertEqual(p2_t3.number, 9)
def test_number_attribute_is_automatically_increased(self): """testing if the number attribute is automatically increased """ # create two new tickets ticket1 = Ticket(**self.kwargs) DBSession.add(ticket1) DBSession.commit() ticket2 = Ticket(**self.kwargs) DBSession.add(ticket2) DBSession.commit() self.assertEqual(ticket1.number + 1, ticket2.number) self.assertEqual(ticket1.number, 2) self.assertEqual(ticket2.number, 3)
def test_related_tickets_attribute_accepts_list_of_Ticket_instances(self): """testing if the related tickets attribute accepts only list of stalker.models.ticket.Ticket instances """ from stalker import Ticket new_ticket1 = Ticket(**self.kwargs) from stalker.db.session import DBSession DBSession.add(new_ticket1) DBSession.commit() new_ticket2 = Ticket(**self.kwargs) DBSession.add(new_ticket2) DBSession.commit() self.test_ticket.related_tickets = [new_ticket1, new_ticket2]
def test_summary_argument_can_be_None(self): """testing if the summary argument can be None """ from stalker import Ticket self.kwargs['summary'] = None new_ticket = Ticket(**self.kwargs) self.assertEqual(new_ticket.summary, '')
def test_priority_argument_is_skipped_will_set_it_to_zero(self): """testing if the priority argument is skipped will set the priority of the Ticket to 0 or TRIVIAL """ self.kwargs.pop('priority') new_ticket = Ticket(**self.kwargs) self.assertEqual(new_ticket.priority, 'TRIVIAL')
def test_project_argument_is_working_properly(self): """testing if the project argument is working properly """ from stalker import Ticket self.kwargs['project'] = self.test_project new_ticket = Ticket(**self.kwargs) self.assertEqual(new_ticket.project, self.test_project)
def test_name_argument_is_not_used(self): """testing if the given name argument is not used """ test_value = 'Test Name' self.kwargs['name'] = test_value new_ticket = Ticket(**self.kwargs) self.assertNotEqual(new_ticket.name, test_value)
def test_status_for_newly_created_tickets_will_be_NEW_when_skipped(self): """testing if the status of newly created tickets will be New """ # get the status NEW from the session from stalker import Ticket new_ticket = Ticket(**self.kwargs) self.assertEqual(new_ticket.status, self.status_new)
def test_name_argument_is_skipped_will_not_raise_error(self): """testing if skipping the name argument is not important and an automatically generated name will be used in that case """ if 'name' in self.kwargs: self.kwargs.pop('name') # expect no errors Ticket(**self.kwargs)
def test_priority_argument_is_skipped_will_set_it_to_zero(self): """testing if the priority argument is skipped will set the priority of the Ticket to 0 or TRIVIAL """ from stalker import Ticket self.kwargs.pop('priority') new_ticket = Ticket(**self.kwargs) assert new_ticket.priority == 'TRIVIAL'
def test_number_attribute_is_automatically_increased(self): """testing if the number attribute is automatically increased """ # create two new tickets from stalker import Ticket ticket1 = Ticket(**self.kwargs) from stalker.db.session import DBSession DBSession.add(ticket1) DBSession.commit() ticket2 = Ticket(**self.kwargs) DBSession.add(ticket2) DBSession.commit() assert ticket1.number + 1 == ticket2.number assert ticket1.number == 2 assert ticket2.number == 3
def test_name_argument_is_not_used(self): """testing if the given name argument is not used """ from stalker import Ticket test_value = 'Test Name' self.kwargs['name'] = test_value new_ticket = Ticket(**self.kwargs) assert new_ticket.name != test_value
def test_summary_argument_is_working_properly(self): """testing if the summary argument value is passed to summary attribute correctly """ test_value = 'test summary' self.kwargs['summary'] = test_value new_ticket = Ticket(**self.kwargs) self.assertEqual(new_ticket.summary, test_value)
def test_summary_argument_skipped(self): """testing if the summary argument can be skipped """ try: self.kwargs.pop('summary') except KeyError: pass new_ticket = Ticket(**self.kwargs) self.assertEqual(new_ticket.summary, '')
def test_summary_argument_is_working_properly(self): """testing if the summary argument value is passed to summary attribute correctly """ from stalker import Ticket test_value = 'test summary' self.kwargs['summary'] = test_value new_ticket = Ticket(**self.kwargs) assert new_ticket.summary == test_value
def test_summary_argument_skipped(self): """testing if the summary argument can be skipped """ from stalker import Ticket try: self.kwargs.pop('summary') except KeyError: pass new_ticket = Ticket(**self.kwargs) assert new_ticket.summary == ''
def test_links_argument_accepts_anything_derived_from_SimpleEntity(self): """testing if links accepting anything derived from SimpleEntity """ self.kwargs['links'] = [ self.test_project, self.test_project_status1, self.test_project_status2, self.test_repo, self.test_version ] new_ticket = Ticket(**self.kwargs) self.assertEqual(sorted(self.kwargs['links'], key=lambda x: x.name), sorted(new_ticket.links, key=lambda x: x.name))
def test_project_argument_accepts_Project_instances_only(self): """testing if the project argument accepts Project instances only """ from stalker import Ticket self.kwargs['project'] = 'Not a Project instance' with pytest.raises(TypeError) as cm: Ticket(**self.kwargs) assert str(cm.value) == \ 'Ticket.project should be an instance of ' \ 'stalker.models.project.Project, not str'
def test_project_argument_accepts_Project_instances_only(self): """testing if the project argument accepts Project instances only """ from stalker import Ticket self.kwargs['project'] = 'Not a Project instance' with self.assertRaises(TypeError) as cm: Ticket(**self.kwargs) self.assertEqual( str(cm.exception), 'Ticket.project should be an instance of ' 'stalker.models.project.Project, not str')
def test_summary_argument_is_not_a_string(self): """testing if a TypeError will be raised when the summary argument value is not a string """ from stalker import Ticket self.kwargs['summary'] = ['not a string instance'] with self.assertRaises(TypeError) as cm: Ticket(self.kwargs) self.assertEqual( str(cm.exception), 'Ticket.project should be an instance of ' 'stalker.models.project.Project, not dict')
def test_project_argument_is_None(self): """testing if a TypeError will be raised when the project argument is None """ from stalker import Ticket self.kwargs['project'] = None with self.assertRaises(TypeError) as cm: Ticket(**self.kwargs) self.assertEqual( str(cm.exception), 'Ticket.project should be an instance of ' 'stalker.models.project.Project, not NoneType')
def test_project_argument_is_None(self): """testing if a TypeError will be raised when the project argument is None """ from stalker import Ticket self.kwargs['project'] = None with pytest.raises(TypeError) as cm: Ticket(**self.kwargs) assert str(cm.value) == \ 'Ticket.project should be an instance of ' \ 'stalker.models.project.Project, not NoneType'
def setUp(self): """setup the test """ # setup a test database self.TEST_DATABASE_URI = "sqlite:///:memory:" db.setup() db.init() # need to have some test object for # a department self.test_department1 = Department(name="Test Department 1") self.test_department2 = Department(name="Test Department 2") self.test_department3 = Department(name="Test Department 3") DBSession.add_all([self.test_department1, self.test_department2, self.test_department3]) # a couple of groups self.test_group1 = Group(name="Test Group 1") self.test_group2 = Group(name="Test Group 2") self.test_group3 = Group(name="Test Group 3") DBSession.add_all([self.test_group1, self.test_group2, self.test_group3]) # a couple of statuses self.test_status1 = Status(name="Completed", code="CMPLT") self.test_status2 = Status(name="Work In Progress", code="WIP") self.test_status3 = Status(name="Waiting To Start", code="WTS") self.test_status4 = Status(name="Pending Review", code="PRev") DBSession.add_all([self.test_status1, self.test_status2, self.test_status3, self.test_status4]) # a project status list self.project_status_list = StatusList( name="Project Status List", statuses=[self.test_status1, self.test_status2, self.test_status3, self.test_status4], target_entity_type=Project, ) # a repository type self.test_repository_type = Type(name="Test", code="test", target_entity_type=Repository) # a repository self.test_repository = Repository(name="Test Repository", type=self.test_repository_type) # a project type self.commercial_project_type = Type(name="Commercial Project", code="comm", target_entity_type=Project) # a couple of projects self.test_project1 = Project( name="Test Project 1", code="tp1", status_list=self.project_status_list, type=self.commercial_project_type, repository=self.test_repository, ) self.test_project2 = Project( name="Test Project 2", code="tp2", status_list=self.project_status_list, type=self.commercial_project_type, repository=self.test_repository, ) self.test_project3 = Project( name="Test Project 3", code="tp3", status_list=self.project_status_list, type=self.commercial_project_type, repository=self.test_repository, ) DBSession.add_all([self.test_project1, self.test_project2, self.test_project3]) # a task status list self.task_status_list = StatusList.query.filter_by(target_entity_type="Task").first() # a couple of tasks self.test_task1 = Task(name="Test Task 1", status_list=self.task_status_list, project=self.test_project1) self.test_task2 = Task(name="Test Task 2", status_list=self.task_status_list, project=self.test_project1) self.test_task3 = Task(name="Test Task 3", status_list=self.task_status_list, project=self.test_project2) self.test_task4 = Task(name="Test Task 4", status_list=self.task_status_list, project=self.test_project3) DBSession.add_all([self.test_task1, self.test_task2, self.test_task3, self.test_task4]) # for task1 self.test_version1 = Version(task=self.test_task1, full_path="some/path") DBSession.add(self.test_version1) self.test_version2 = Version(task=self.test_task1, full_path="some/path") DBSession.add(self.test_version2) self.test_version3 = Version(task=self.test_task1, full_path="some/path") DBSession.add(self.test_version3) # for task2 self.test_version4 = Version(task=self.test_task2, full_path="some/path") DBSession.add(self.test_version4) self.test_version5 = Version(task=self.test_task2, full_path="some/path") DBSession.add(self.test_version5) self.test_version6 = Version(task=self.test_task2, full_path="some/path") DBSession.add(self.test_version6) # for task3 self.test_version7 = Version(task=self.test_task3, full_path="some/path") DBSession.add(self.test_version7) self.test_version8 = Version(task=self.test_task3, full_path="some/path") DBSession.add(self.test_version8) self.test_version9 = Version(task=self.test_task3, full_path="some/path") DBSession.add(self.test_version9) # for task4 self.test_version10 = Version(task=self.test_task4, full_path="some/path") DBSession.add(self.test_version10) self.test_version11 = Version(task=self.test_task4, full_path="some/path") DBSession.add(self.test_version11) self.test_version12 = Version(task=self.test_task4, full_path="some/path") DBSession.add(self.test_version12) # ********************************************************************* # Tickets # ********************************************************************* # no need to create status list for tickets cause we have a database # set up an running so it will be automatically linked # tickets for version1 self.test_ticket1 = Ticket(project=self.test_project1, links=[self.test_version1]) DBSession.add(self.test_ticket1) # set it to closed self.test_ticket1.resolve() # create a new ticket and leave it open self.test_ticket2 = Ticket(project=self.test_project1, links=[self.test_version1]) DBSession.add(self.test_ticket2) # create a new ticket and close and then reopen it self.test_ticket3 = Ticket(project=self.test_project1, links=[self.test_version1]) DBSession.add(self.test_ticket3) self.test_ticket3.resolve() self.test_ticket3.reopen() # ********************************************************************* # tickets for version2 # create a new ticket and leave it open self.test_ticket4 = Ticket(project=self.test_project1, links=[self.test_version2]) DBSession.add(self.test_ticket4) # create a new Ticket and close it self.test_ticket5 = Ticket(project=self.test_project1, links=[self.test_version2]) DBSession.add(self.test_ticket5) self.test_ticket5.resolve() # create a new Ticket and close it self.test_ticket6 = Ticket(project=self.test_project1, links=[self.test_version3]) DBSession.add(self.test_ticket6) self.test_ticket6.resolve() # ********************************************************************* # tickets for version3 # create a new ticket and close it self.test_ticket7 = Ticket(project=self.test_project1, links=[self.test_version3]) DBSession.add(self.test_ticket7) self.test_ticket7.resolve() # create a new ticket and close it self.test_ticket8 = Ticket(project=self.test_project1, links=[self.test_version3]) DBSession.add(self.test_ticket8) self.test_ticket8.resolve() # ********************************************************************* # tickets for version4 # create a new ticket and close it self.test_ticket9 = Ticket(project=self.test_project1, links=[self.test_version4]) DBSession.add(self.test_ticket9) self.test_ticket9.resolve() # no tickets for any other version # ********************************************************************* # a status list for sequence self.sequence_status_list = StatusList.query.filter_by(target_entity_type="Sequence").first() # a couple of sequences self.test_sequence1 = Sequence( name="Test Seq 1", code="ts1", project=self.test_project1, status_list=self.sequence_status_list ) self.test_sequence2 = Sequence( name="Test Seq 2", code="ts2", project=self.test_project1, status_list=self.sequence_status_list ) self.test_sequence3 = Sequence( name="Test Seq 3", code="ts3", project=self.test_project1, status_list=self.sequence_status_list ) self.test_sequence4 = Sequence( name="Test Seq 4", code="ts4", project=self.test_project1, status_list=self.sequence_status_list ) DBSession.add_all([self.test_sequence1, self.test_sequence2, self.test_sequence3, self.test_sequence4]) # a test admin # self.test_admin = User( # name='Admin', # login='******', # email='*****@*****.**', # password='******' # ) self.test_admin = User.query.filter_by(name=defaults.admin_name).first() self.assertIsNotNone(self.test_admin) # create the default values for parameters self.kwargs = { "name": "Erkan Ozgur Yilmaz", "login": "******", "description": "this is a test user", "password": "******", "email": "*****@*****.**", "departments": [self.test_department1], "groups": [self.test_group1, self.test_group2], "created_by": self.test_admin, "updated_by": self.test_admin, } # create a proper user object self.test_user = User(**self.kwargs) DBSession.add(self.test_user) DBSession.commit() # just change the kwargs for other tests self.kwargs["name"] = "some other name" self.kwargs["email"] = "*****@*****.**"
class UserTest(unittest2.TestCase): """Tests the user class """ @classmethod def setUpClass(cls): """set up the test for class """ DBSession.remove() @classmethod def tearDownClass(cls): """clean up the test """ DBSession.remove() def setUp(self): """setup the test """ # setup a test database self.TEST_DATABASE_URI = "sqlite:///:memory:" db.setup() db.init() # need to have some test object for # a department self.test_department1 = Department(name="Test Department 1") self.test_department2 = Department(name="Test Department 2") self.test_department3 = Department(name="Test Department 3") DBSession.add_all([self.test_department1, self.test_department2, self.test_department3]) # a couple of groups self.test_group1 = Group(name="Test Group 1") self.test_group2 = Group(name="Test Group 2") self.test_group3 = Group(name="Test Group 3") DBSession.add_all([self.test_group1, self.test_group2, self.test_group3]) # a couple of statuses self.test_status1 = Status(name="Completed", code="CMPLT") self.test_status2 = Status(name="Work In Progress", code="WIP") self.test_status3 = Status(name="Waiting To Start", code="WTS") self.test_status4 = Status(name="Pending Review", code="PRev") DBSession.add_all([self.test_status1, self.test_status2, self.test_status3, self.test_status4]) # a project status list self.project_status_list = StatusList( name="Project Status List", statuses=[self.test_status1, self.test_status2, self.test_status3, self.test_status4], target_entity_type=Project, ) # a repository type self.test_repository_type = Type(name="Test", code="test", target_entity_type=Repository) # a repository self.test_repository = Repository(name="Test Repository", type=self.test_repository_type) # a project type self.commercial_project_type = Type(name="Commercial Project", code="comm", target_entity_type=Project) # a couple of projects self.test_project1 = Project( name="Test Project 1", code="tp1", status_list=self.project_status_list, type=self.commercial_project_type, repository=self.test_repository, ) self.test_project2 = Project( name="Test Project 2", code="tp2", status_list=self.project_status_list, type=self.commercial_project_type, repository=self.test_repository, ) self.test_project3 = Project( name="Test Project 3", code="tp3", status_list=self.project_status_list, type=self.commercial_project_type, repository=self.test_repository, ) DBSession.add_all([self.test_project1, self.test_project2, self.test_project3]) # a task status list self.task_status_list = StatusList.query.filter_by(target_entity_type="Task").first() # a couple of tasks self.test_task1 = Task(name="Test Task 1", status_list=self.task_status_list, project=self.test_project1) self.test_task2 = Task(name="Test Task 2", status_list=self.task_status_list, project=self.test_project1) self.test_task3 = Task(name="Test Task 3", status_list=self.task_status_list, project=self.test_project2) self.test_task4 = Task(name="Test Task 4", status_list=self.task_status_list, project=self.test_project3) DBSession.add_all([self.test_task1, self.test_task2, self.test_task3, self.test_task4]) # for task1 self.test_version1 = Version(task=self.test_task1, full_path="some/path") DBSession.add(self.test_version1) self.test_version2 = Version(task=self.test_task1, full_path="some/path") DBSession.add(self.test_version2) self.test_version3 = Version(task=self.test_task1, full_path="some/path") DBSession.add(self.test_version3) # for task2 self.test_version4 = Version(task=self.test_task2, full_path="some/path") DBSession.add(self.test_version4) self.test_version5 = Version(task=self.test_task2, full_path="some/path") DBSession.add(self.test_version5) self.test_version6 = Version(task=self.test_task2, full_path="some/path") DBSession.add(self.test_version6) # for task3 self.test_version7 = Version(task=self.test_task3, full_path="some/path") DBSession.add(self.test_version7) self.test_version8 = Version(task=self.test_task3, full_path="some/path") DBSession.add(self.test_version8) self.test_version9 = Version(task=self.test_task3, full_path="some/path") DBSession.add(self.test_version9) # for task4 self.test_version10 = Version(task=self.test_task4, full_path="some/path") DBSession.add(self.test_version10) self.test_version11 = Version(task=self.test_task4, full_path="some/path") DBSession.add(self.test_version11) self.test_version12 = Version(task=self.test_task4, full_path="some/path") DBSession.add(self.test_version12) # ********************************************************************* # Tickets # ********************************************************************* # no need to create status list for tickets cause we have a database # set up an running so it will be automatically linked # tickets for version1 self.test_ticket1 = Ticket(project=self.test_project1, links=[self.test_version1]) DBSession.add(self.test_ticket1) # set it to closed self.test_ticket1.resolve() # create a new ticket and leave it open self.test_ticket2 = Ticket(project=self.test_project1, links=[self.test_version1]) DBSession.add(self.test_ticket2) # create a new ticket and close and then reopen it self.test_ticket3 = Ticket(project=self.test_project1, links=[self.test_version1]) DBSession.add(self.test_ticket3) self.test_ticket3.resolve() self.test_ticket3.reopen() # ********************************************************************* # tickets for version2 # create a new ticket and leave it open self.test_ticket4 = Ticket(project=self.test_project1, links=[self.test_version2]) DBSession.add(self.test_ticket4) # create a new Ticket and close it self.test_ticket5 = Ticket(project=self.test_project1, links=[self.test_version2]) DBSession.add(self.test_ticket5) self.test_ticket5.resolve() # create a new Ticket and close it self.test_ticket6 = Ticket(project=self.test_project1, links=[self.test_version3]) DBSession.add(self.test_ticket6) self.test_ticket6.resolve() # ********************************************************************* # tickets for version3 # create a new ticket and close it self.test_ticket7 = Ticket(project=self.test_project1, links=[self.test_version3]) DBSession.add(self.test_ticket7) self.test_ticket7.resolve() # create a new ticket and close it self.test_ticket8 = Ticket(project=self.test_project1, links=[self.test_version3]) DBSession.add(self.test_ticket8) self.test_ticket8.resolve() # ********************************************************************* # tickets for version4 # create a new ticket and close it self.test_ticket9 = Ticket(project=self.test_project1, links=[self.test_version4]) DBSession.add(self.test_ticket9) self.test_ticket9.resolve() # no tickets for any other version # ********************************************************************* # a status list for sequence self.sequence_status_list = StatusList.query.filter_by(target_entity_type="Sequence").first() # a couple of sequences self.test_sequence1 = Sequence( name="Test Seq 1", code="ts1", project=self.test_project1, status_list=self.sequence_status_list ) self.test_sequence2 = Sequence( name="Test Seq 2", code="ts2", project=self.test_project1, status_list=self.sequence_status_list ) self.test_sequence3 = Sequence( name="Test Seq 3", code="ts3", project=self.test_project1, status_list=self.sequence_status_list ) self.test_sequence4 = Sequence( name="Test Seq 4", code="ts4", project=self.test_project1, status_list=self.sequence_status_list ) DBSession.add_all([self.test_sequence1, self.test_sequence2, self.test_sequence3, self.test_sequence4]) # a test admin # self.test_admin = User( # name='Admin', # login='******', # email='*****@*****.**', # password='******' # ) self.test_admin = User.query.filter_by(name=defaults.admin_name).first() self.assertIsNotNone(self.test_admin) # create the default values for parameters self.kwargs = { "name": "Erkan Ozgur Yilmaz", "login": "******", "description": "this is a test user", "password": "******", "email": "*****@*****.**", "departments": [self.test_department1], "groups": [self.test_group1, self.test_group2], "created_by": self.test_admin, "updated_by": self.test_admin, } # create a proper user object self.test_user = User(**self.kwargs) DBSession.add(self.test_user) DBSession.commit() # just change the kwargs for other tests self.kwargs["name"] = "some other name" self.kwargs["email"] = "*****@*****.**" def tearDown(self): """tear down the test """ DBSession.remove() def test___auto_name__class_attribute_is_set_to_False(self): """testing if the __auto_name__ class attribute is set to False for User class """ self.assertFalse(User.__auto_name__) def test_email_argument_accepting_only_string_or_unicode(self): """testing if email argument accepting only string or unicode values """ # try to create a new user with wrong attribute test_values = [1, 1.3, ["an email"], {"an": "email"}] for test_value in test_values: self.kwargs["email"] = test_value self.assertRaises(TypeError, User, **self.kwargs) def test_email_attribute_accepting_only_string_or_unicode(self): """testing if email attribute accepting only string or unicode values """ # try to assign something else than a string or unicode test_value = 1 self.assertRaises(TypeError, setattr, self.test_user, "email", test_value) test_value = ["an email"] self.assertRaises(TypeError, setattr, self.test_user, "email", test_value) def test_email_argument_format(self): """testing if given an email in wrong format will raise a ValueError """ test_values = ["an email in no format", "an_email_with_no_part2", "@an_email_with_only_part2", "@"] # any of this values should raise a ValueError for test_value in test_values: self.kwargs["email"] = test_value self.assertRaises(ValueError, User, **self.kwargs) def test_email_attribute_format(self): """testing if given an email in wrong format will raise a ValueError """ test_values = [ "an email in no format", "an_email_with_no_part2", "@an_email_with_only_part2", "@", "eoyilmaz@", "[email protected]@com", ] # any of these email values should raise a ValueError for value in test_values: self.assertRaises(ValueError, setattr, self.test_user, "email", value) def test_email_argument_should_be_a_unique_value(self): """testing if the email argument should be a unique value """ # this test should include a database test_email = "*****@*****.**" self.kwargs["login"] = "******" self.kwargs["email"] = test_email user1 = User(**self.kwargs) DBSession.add(user1) DBSession.commit() self.kwargs["login"] = "******" user2 = User(**self.kwargs) DBSession.add(user2) self.assertRaises(Exception, DBSession.commit) def test_email_attribute_is_working_properly(self): """testing if email attribute works properly """ test_email = "*****@*****.**" self.test_user.email = test_email self.assertEqual(self.test_user.email, test_email) def test_login_argument_conversion_to_strings(self): """testing if a ValueError will be raised when the given objects conversion to string results an empty string """ test_values = ["----++==#@#$"] for test_value in test_values: self.kwargs["login"] = test_value self.assertRaises(ValueError, User, **self.kwargs) def test_login_argument_for_empty_string(self): """testing if a ValueError will be raised when trying to assign an empty string to login argument """ self.kwargs["login"] = "" self.assertRaises(ValueError, User, **self.kwargs) def test_login_attribute_for_empty_string(self): """testing if a ValueError will be raised when trying to assign an empty string to login attribute """ self.assertRaises(ValueError, setattr, self.test_user, "login", "") def test_login_argument_is_skipped(self): """testing if a TypeError will be raised when the login argument is skipped """ self.kwargs.pop("login") self.assertRaises(TypeError, User, **self.kwargs) def test_login_argument_is_None(self): """testing if a TypeError will be raised when trying to assign None to login argument """ self.kwargs["login"] = None self.assertRaises(TypeError, User, **self.kwargs) def test_login_attribute_is_None(self): """testing if a TypeError will be raised when trying to assign None to login attribute """ self.assertRaises(TypeError, setattr, self.test_user, "login", None) def test_login_argument_formatted_correctly(self): """testing if login argument formatted correctly """ # input expected test_values = [ ("e. ozgur", "eozgur"), ("erkan", "erkan"), ("Ozgur", "ozgur"), ("Erkan ozgur", "erkanozgur"), ("eRKAN", "erkan"), ("eRkaN", "erkan"), (" eRkAn", "erkan"), (" eRkan ozGur", "erkanozgur"), ("213 e.ozgur", "eozgur"), ] for valuePair in test_values: # set the input and expect the expected output self.kwargs["login"] = valuePair[0] test_user = User(**self.kwargs) self.assertEqual(test_user.login, valuePair[1]) def test_login_attribute_formatted_correctly(self): """testing if login attribute formatted correctly """ # input expected test_values = [ ("e. ozgur", "eozgur"), ("erkan", "erkan"), ("Ozgur", "ozgur"), ("Erkan ozgur", "erkanozgur"), ("eRKAN", "erkan"), ("eRkaN", "erkan"), (" eRkAn", "erkan"), (" eRkan ozGur", "erkanozgur"), ] for valuePair in test_values: # set the input and expect the expected output self.test_user.login = valuePair[0] self.assertEqual(self.test_user.login, valuePair[1]) def test_login_argument_should_be_a_unique_value(self): """testing if the login argument should be a unique value """ # this test should include a database test_login = "******" self.kwargs["login"] = test_login self.kwargs["email"] = "*****@*****.**" user1 = User(**self.kwargs) DBSession.add(user1) DBSession.commit() self.kwargs["email"] = "*****@*****.**" user2 = User(**self.kwargs) DBSession.add(user2) self.assertRaises(Exception, DBSession.commit) def test_login_argument_is_working_properly(self): """testing if the login argument is working properly """ self.assertEqual(self.test_user.login, self.kwargs["login"]) def test_login_attribute_is_working_properly(self): """testing if the login attribute is working properly """ test_value = "newlogin" self.test_user.login = test_value self.assertEqual(self.test_user.login, test_value) def test_last_login_attribute_None(self): """testing if nothing happens when the last login attribute is set to None """ # nothing should happen self.test_user.last_login = None def test_last_login_attribute_accepts_only_datetime_instance_or_None(self): """testing if a TypeError will be raised for values other than datetime.datetime instances tried to be assigned to last_login attribute """ test_values = [1, 2.3, "login time", ["last login time"], {"a last": "login time"}] for test_value in test_values: self.assertRaises(TypeError, setattr, self.test_user, "last_login", test_value) def test_last_login_attribute_works_properly(self): """testing if the last_login attribute works properly """ test_value = datetime.datetime.now() self.test_user.last_login = test_value self.assertEqual(self.test_user.last_login, test_value) def test_departments_argument_is_skipped(self): """testing if a User can be created without a Department instance """ try: self.kwargs.pop("departments") except KeyError: pass new_user = User(**self.kwargs) self.assertEqual(new_user.departments, []) def test_departments_argument_is_None(self): """testing if a User can be created with the departments argument value is to None """ self.kwargs["departments"] = None new_user = User(**self.kwargs) self.assertEqual(new_user.departments, []) def test_departments_attribute_is_set_None(self): """testing if a TypeError will be raised when the User's departments attribute set to None """ self.assertRaises(TypeError, setattr, self.test_user, "departments", None) def test_departments_argument_is_an_empty_list(self): """testing if a User can be created with the departments argument is an empty list """ self.kwargs["departments"] = [] new_user = User(**self.kwargs) def test_departments_attribute_is_an_empty_list(self): """testing if the departments attribute can be set to an empty list """ self.test_user.departments = [] self.assertEqual(self.test_user.departments, []) def test_departments_argument_only_accepts_list_of_department_objects(self): """testing if a TypeError will be raised when trying to assign anything other than a Department object to departments argument """ # try to assign something other than a department object test_values = ["A department", 1, 1.0, ["a department"], {"a": "deparment"}] self.kwargs["departments"] = test_values self.assertRaises(TypeError, User, **self.kwargs) def test_departments_attribute_only_accepts_department_objects(self): """testing if a TypeError will be raised when trying to assign anything other than a Department object to departments attribute """ # try to assign something other than a department test_value = "a department" self.assertRaises(TypeError, setattr, self.test_user, "departments", test_value) def test_departments_attribute_works_properly(self): """testing if departments attribute works properly """ # try to set and get the same value back self.test_user.departments = [self.test_department2] self.assertItemsEqual(self.test_user.departments, [self.test_department2]) def test_departments_attribute_supports_appending(self): """testing if departments attribute supports appending """ self.test_user.departments = [] self.test_user.departments.append(self.test_department1) self.test_user.departments.append(self.test_department2) self.assertItemsEqual(self.test_user.departments, [self.test_department1, self.test_department2]) def test_password_argument_being_None(self): """testing if a TypeError will be raised when trying to assign None to the password argument """ self.kwargs["password"] = None self.assertRaises(TypeError, User, **self.kwargs) def test_password_attribute_being_None(self): """testing if a TypeError will be raised when tyring to assign None to the password attribute """ self.assertRaises(TypeError, setattr, self.test_user, "password", None) def test_password_attribute_works_properly(self): """testing if password attribute works properly """ test_password = "******" self.test_user.password = test_password self.assertNotEquals(self.test_user.password, test_password) def test_password_argument_being_scrambled(self): """testing if password is scrambled when trying to store it """ test_password = "******" self.kwargs["password"] = test_password aNew_user = User(**self.kwargs) self.assertNotEquals(aNew_user.password, test_password) def test_password_attribute_being_scrambled(self): """testing if password is scrambled when trying to store it """ test_password = "******" self.test_user.password = test_password # test if they are not the same any more self.assertNotEquals(self.test_user.password, test_password) def test_check_password_works_properly(self): """testing if check_password method works properly """ test_password = "******" self.test_user.password = test_password # check if it is scrambled self.assertNotEquals(self.test_user.password, test_password) # check if check_password returns True self.assertTrue(self.test_user.check_password(test_password)) # check if check_password returns False self.assertFalse(self.test_user.check_password("wrong pass")) def test_groups_argument_for_None(self): """testing if the groups attribute will be an empty list when the groups argument is None """ self.kwargs["groups"] = None new_user = User(**self.kwargs) self.assertEqual(new_user.groups, []) def test_groups_attribute_for_None(self): """testing if a TypeError will be raised when groups attribute is set to None """ self.assertRaises(TypeError, setattr, self.test_user, "groups", None) def test_groups_argument_accepts_only_Group_instances(self): """testing if a TypeError will be raised when trying to assign anything other then a Group instances to the group argument """ test_values = [23123, 1231.43122, "a_group", ["group1", "group2", 234]] for test_value in test_values: self.kwargs["groups"] = test_value self.assertRaises(TypeError, User, **self.kwargs) def test_groups_attribute_accepts_only_Group_instances(self): """testing if a TypeError will be raised when trying to assign anything other then a Group instances to the group attribute """ test_values = [23123, 1231.43122, "a_group", ["group1", "group2", 234]] for test_value in test_values: self.assertRaises(TypeError, setattr, self.test_user, "groups", test_value) def test_groups_attribute_works_properly(self): """testing if groups attribute works properly """ test_pg = [self.test_group3] self.test_user.groups = test_pg self.assertEqual(self.test_user.groups, test_pg) def test_groups_attribute_elements_accepts_Group_only(self): """testing if a TypeError will be raised when trying to assign something other than a Group instances to the groups list """ # append self.assertRaises(TypeError, self.test_user.groups.append, 0) # __setitem__ self.assertRaises(TypeError, self.test_user.groups.__setitem__, 0, 0) def test_projects_attribute_is_None(self): """testing if a TypeError will be raised when the projects attribute is set to None """ self.assertRaises(TypeError, setattr, self.test_user, "projects", None) def test_projects_attribute_is_set_to_a_value_which_is_not_a_list(self): """testing if the projects attribute is accepting lists only """ self.assertRaises(TypeError, setattr, self.test_user, "projects", "not a list") def test_projects_attribute_is_set_to_list_of_other_objects_than_Project_instances(self): """testing if a TypeError will be raised when the projects attribute is set to a value which is a list of other values than Projects instances """ self.assertRaises(TypeError, setattr, self.test_user, "projects", ["not", "a", "list", "of", "projects", 32]) def test_projects_attribute_is_working_properly(self): """testing if the projects attribute is working properly """ test_list = [self.test_project1, self.test_project2] self.test_user.projects = test_list self.assertItemsEqual(test_list, self.test_user.projects) self.test_user.projects.append(self.test_project3) self.assertIn(self.test_project3, self.test_user.projects) # also check the backref self.assertIn(self.test_user, self.test_project1.users) self.assertIn(self.test_user, self.test_project2.users) self.assertIn(self.test_user, self.test_project3.users) def test_projects_lead_attribute_None(self): """testing if a TypeError will be raised when the project_lead attribute is set to None """ self.assertRaises(TypeError, setattr, self.test_user, "projects_lead", None) def test_projects_lead_attribute_accepts_empty_list(self): """testing if projects_lead attribute accepts an empty list """ # this should work without any problem self.test_user.projects_lead = [] def test_projects_lead_attribute_accepts_only_lists(self): """testing if a TypeError will be raised when trying to assign a list of other objects than a list of Project objects to the projects_lead attribute """ test_values = ["a project", 123123, {}, 12.2132] for test_value in test_values: self.assertRaises(TypeError, setattr, self.test_user, "projects_lead", test_value) def test_projects_lead_attribute_accepts_only_list_of_project_obj(self): """testing if a TypeError will be raised when trying to assign a list of other object than a list of Project objects to the projects_lead attribute """ test_value = ["a project", 123123, [], {}, 12.2132] self.assertRaises(TypeError, setattr, self.test_user, "projects_lead", test_value) def test_projects_lead_attribute_working_properly(self): """testing if the projects_lead attribute is working properly """ projects_lead = [self.test_project1, self.test_project2, self.test_project3] self.test_user.projects_lead = projects_lead self.assertEqual(self.test_user.projects_lead, projects_lead) def test_projects_lead_attribute_elements_accepts_Project_only(self): """testing if a TypeError will be raised when trying to assign something other than a Project object to the projects_lead list """ # append self.assertRaises(TypeError, self.test_user.projects_lead.append, 0) def test_tasks_attribute_None(self): """testing if a TypeError will be raised when the tasks attribute is set to None """ self.assertRaises(TypeError, setattr, self.test_user, "tasks", None) def test_tasks_attribute_accepts_only_list_of_task_objects(self): """testing if a TypeError will be raised when trying to assign anything other than a list of task objects to the tasks argument """ test_values = [12312, 1233244.2341, ["aTask1", "aTask2"], "a_task"] for test_value in test_values: self.assertRaises(TypeError, setattr, self.test_user, "tasks", test_value) def test_tasks_attribute_accepts_an_empty_list(self): """testing if nothing happens when trying to assign an empty list to tasks attribute """ # this should work without any error self.test_user.tasks = [] def test_tasks_attribute_works_properly(self): """testing if tasks attribute is working properly """ tasks = [self.test_task1, self.test_task2, self.test_task3, self.test_task4] self.test_user.tasks = tasks self.assertEqual(self.test_user.tasks, tasks) def test_tasks_attribute_elements_accepts_Tasks_only(self): """testing if a TypeError will be raised when trying to assign something other than a Task object to the tasks list """ # append self.assertRaises(TypeError, self.test_user.tasks.append, 0) def test_equality_operator(self): """testing equality of two users """ self.kwargs.update( { "name": "Generic User", "description": "this is a different user", "login": "******", "email": "*****@*****.**", "password": "******", } ) new_user = User(**self.kwargs) self.assertFalse(self.test_user == new_user) def test_inequality_operator(self): """testing inequality of two users """ self.kwargs.update( { "name": "Generic User", "description": "this is a different user", "login": "******", "email": "*****@*****.**", "password": "******", } ) new_user = User(**self.kwargs) self.assertTrue(self.test_user != new_user) def test___repr__(self): """testing the representation """ self.assertEqual(self.test_user.__repr__(), "<%s ('%s') (User)>" % (self.test_user.name, self.test_user.login)) def test_tickets_attribute_is_an_empty_list_by_default(self): """testing if the User.tickets is an empty list by default """ self.assertEqual(self.test_user.tickets, []) def test_open_tickets_attribute_is_an_empty_list_by_default(self): """testing if the User.open_tickets is an empty list by default """ self.assertEqual(self.test_user.open_tickets, []) def test_tickets_attribute_is_read_only(self): """testing if the User.tickets attribute is a read only attribute """ self.assertRaises(AttributeError, setattr, self.test_user, "tickets", []) def test_open_tickets_attribute_is_read_only(self): """testing if the User.open_tickets attribute is a read only attribute """ self.assertRaises(AttributeError, setattr, self.test_user, "open_tickets", []) def test_tickets_attribute_returns_all_tickets_owned_by_this_user(self): """testing if User.tickets returns all the tickets owned by this user """ self.assertEqual(len(self.test_user.tasks), 0) # there should be no tickets assigned to this user self.assertTrue(self.test_user.tickets == []) # be careful not all of these are open tickets self.test_ticket1.reassign(self.test_user, self.test_user) self.test_ticket2.reassign(self.test_user, self.test_user) self.test_ticket3.reassign(self.test_user, self.test_user) self.test_ticket4.reassign(self.test_user, self.test_user) self.test_ticket5.reassign(self.test_user, self.test_user) self.test_ticket6.reassign(self.test_user, self.test_user) self.test_ticket7.reassign(self.test_user, self.test_user) self.test_ticket8.reassign(self.test_user, self.test_user) # now we should have some tickets self.assertTrue(len(self.test_user.tickets) > 0) # now check for exact items self.assertItemsEqual(self.test_user.tickets, [self.test_ticket2, self.test_ticket3, self.test_ticket4]) def test_open_tickets_attribute_returns_all_open_tickets_owned_by_this_user(self): """testing if User.open_tickets returns all the open tickets owned by this user """ self.assertEqual(len(self.test_user.tasks), 0) # there should be no tickets assigned to this user self.assertTrue(self.test_user.open_tickets == []) # assign the user to some tickets self.test_ticket1.reopen(self.test_user) self.test_ticket2.reopen(self.test_user) self.test_ticket3.reopen(self.test_user) self.test_ticket4.reopen(self.test_user) self.test_ticket5.reopen(self.test_user) self.test_ticket6.reopen(self.test_user) self.test_ticket7.reopen(self.test_user) self.test_ticket8.reopen(self.test_user) # be careful not all of these are open tickets self.test_ticket1.reassign(self.test_user, self.test_user) self.test_ticket2.reassign(self.test_user, self.test_user) self.test_ticket3.reassign(self.test_user, self.test_user) self.test_ticket4.reassign(self.test_user, self.test_user) self.test_ticket5.reassign(self.test_user, self.test_user) self.test_ticket6.reassign(self.test_user, self.test_user) self.test_ticket7.reassign(self.test_user, self.test_user) self.test_ticket8.reassign(self.test_user, self.test_user) # now we should have some open tickets self.assertTrue(len(self.test_user.open_tickets) > 0) # now check for exact items self.assertItemsEqual( self.test_user.open_tickets, [ self.test_ticket1, self.test_ticket2, self.test_ticket3, self.test_ticket4, self.test_ticket5, self.test_ticket6, self.test_ticket7, self.test_ticket8, ], ) # close a couple of them from stalker.models.ticket import FIXED, CANTFIX, WONTFIX, DUPLICATE, WORKSFORME, INVALID self.test_ticket1.resolve(self.test_user, FIXED) self.test_ticket2.resolve(self.test_user, INVALID) self.test_ticket3.resolve(self.test_user, CANTFIX) # new check again self.assertItemsEqual( self.test_user.open_tickets, [self.test_ticket4, self.test_ticket5, self.test_ticket6, self.test_ticket7, self.test_ticket8], ) def test_tjp_id_is_working_properly(self): """testing if the tjp_id is working properly """ self.assertEqual(self.test_user.tjp_id, "User_%s" % self.test_user.id) def test_to_tjp_is_working_properly(self): """testing if the to_tjp property is working properly """ expected_tjp = 'resource User_82 "Erkan Ozgur Yilmaz"' self.assertEqual(expected_tjp, self.test_user.to_tjp) def test_to_tjp_is_working_properly_for_a_user_with_vacations(self): """testing if the to_tjp property is working properly for a user with vacations """ personal_vacation = Type(name="Personal", code="PERS", target_entity_type="Vacation") vac1 = Vacation( user=self.test_user, type=personal_vacation, start=datetime.datetime(2013, 6, 7, 0, 0), end=datetime.datetime(2013, 6, 21, 0, 0), ) vac2 = Vacation( user=self.test_user, type=personal_vacation, start=datetime.datetime(2013, 7, 1, 0, 0), end=datetime.datetime(2013, 7, 15, 0, 0), ) expected_tjp = """resource User_82 "Erkan Ozgur Yilmaz" { vacation 2013-06-07-00:00:00 - 2013-06-21-00:00:00 vacation 2013-07-01-00:00:00 - 2013-07-15-00:00:00 }""" # print expected_tjp # print '---------------' # print self.test_user.to_tjp self.assertEqual(expected_tjp, self.test_user.to_tjp) def test_vacations_attribute_is_set_to_None(self): """testing if a TypeError will be raised when the vacations attribute is set to None """ self.assertRaises(TypeError, setattr, self.test_user, "vacations", None) def test_vacations_attribute_is_not_a_list(self): """testing if a TypeError will be raised when the vacations attribute is set to a value other than a list """ self.assertRaises(TypeError, setattr, self.test_user, "vacations", "not a list of Vacation instances") def test_vacations_attribute_is_not_a_list_of_Vacation_instances(self): """testing if a TypeError will be raised when the vacations attribute is set to a list of other objects than Vacation instances """ self.assertRaises(TypeError, setattr, self.test_user, "vacations", ["list of", "other", "instances", 1]) def test_vacations_attribute_is_working_properly(self): """testing if the vacations attribute is working properly """ some_other_user = User(name="Some Other User", login="******", email="*****@*****.**", password="******") personal_vac_type = Type(name="Personal Vacation", code="PERS", target_entity_type="Vacation") vac1 = Vacation( user=some_other_user, type=personal_vac_type, start=datetime.datetime(2013, 6, 7), end=datetime.datetime(2013, 6, 10), ) self.assertNotIn(vac1, self.test_user.vacations) self.test_user.vacations.append(vac1) self.assertIn(vac1, self.test_user.vacations)
def setUp(self): """set up the test """ # create the db DBSession.remove() db.setup() # db.init() # we just need statuses so create them instead of initializing the db db.create_ticket_statuses() db.create_entity_statuses(entity_type='Task', status_names=defaults.task_status_names, status_codes=defaults.task_status_codes) db.create_entity_statuses(entity_type='Asset', status_names=defaults.task_status_names, status_codes=defaults.task_status_codes) db.create_entity_statuses(entity_type='Shot', status_names=defaults.task_status_names, status_codes=defaults.task_status_codes) db.create_entity_statuses(entity_type='Sequence', status_names=defaults.task_status_names, status_codes=defaults.task_status_codes) db.create_entity_statuses(entity_type='Review', status_names=defaults.review_status_names, status_codes=defaults.review_status_codes) # create statuses self.test_status1 = Status(name='N', code='N') self.test_status2 = Status(name='R', code='R') # get the ticket types ticket_types = Type.query \ .filter(Type.target_entity_type == 'Ticket').all() self.ticket_type_1 = ticket_types[0] self.ticket_type_2 = ticket_types[1] # create a User self.test_user = User( name='Test User', login='******', email='*****@*****.**', password='******' ) # create a Repository self.test_repo = Repository(name="Test Repo") # create a Project Type self.test_project_type = Type( name='Commercial Project', code='comm', target_entity_type=Project, ) # create a Project StatusList self.test_project_status1 = Status(name='PrjStat1', code='PrjStat1') self.test_project_status2 = Status(name='PrjStat2', code='PrjStat2') self.test_project_status_list = StatusList( name="Project Status List", target_entity_type=Project, statuses=[ self.test_project_status1, self.test_project_status2, ] ) self.test_task_status_list = StatusList.query\ .filter_by(target_entity_type='Task').first() # create a Project self.test_project = Project( name="Test Project 1", code="TEST_PROJECT_1", type=self.test_project_type, repository=self.test_repo, status_list=self.test_project_status_list ) # create an Asset self.test_asset_status_list = StatusList.query\ .filter_by(target_entity_type='Asset').first() self.test_asset_type = Type( name='Character Asset', code='char', target_entity_type=Asset ) self.test_asset = Asset( name="Test Asset", code='ta', project=self.test_project, status_list=self.test_asset_status_list, type=self.test_asset_type ) # create a Task self.test_task = Task( name="Modeling of Asset 1", resources=[self.test_user], status_list=self.test_task_status_list, parent=self.test_asset ) # create a Version self.test_version_status_list = StatusList( name='Version Statuses', target_entity_type=Version, statuses=[self.test_status1, self.test_status2] ) self.test_version = Version( name='Test Version', task=self.test_task, status_list=self.test_version_status_list, version=1, full_path='some/path' ) # create the Ticket self.kwargs = { 'project': self.test_project, 'links': [self.test_version], 'summary': 'This is a test ticket', 'description': 'This is the long description', 'priority': 'TRIVIAL', 'reported_by': self.test_user, } self.test_ticket = Ticket(**self.kwargs) DBSession.add(self.test_ticket) DBSession.commit() # get the Ticket Statuses self.status_new = Status.query.filter_by(name='New').first() self.status_accepted = Status.query.filter_by(name='Accepted').first() self.status_assigned = Status.query.filter_by(name='Assigned').first() self.status_reopened = Status.query.filter_by(name='Reopened').first() self.status_closed = Status.query.filter_by(name='Closed').first()
class TicketTester(unittest2.TestCase): """Tests the :class:`~stalker.models.ticket.Ticket` class """ def setUp(self): """set up the test """ # create the db DBSession.remove() db.setup() # db.init() # we just need statuses so create them instead of initializing the db db.create_ticket_statuses() db.create_entity_statuses(entity_type='Task', status_names=defaults.task_status_names, status_codes=defaults.task_status_codes) db.create_entity_statuses(entity_type='Asset', status_names=defaults.task_status_names, status_codes=defaults.task_status_codes) db.create_entity_statuses(entity_type='Shot', status_names=defaults.task_status_names, status_codes=defaults.task_status_codes) db.create_entity_statuses(entity_type='Sequence', status_names=defaults.task_status_names, status_codes=defaults.task_status_codes) db.create_entity_statuses(entity_type='Review', status_names=defaults.review_status_names, status_codes=defaults.review_status_codes) # create statuses self.test_status1 = Status(name='N', code='N') self.test_status2 = Status(name='R', code='R') # get the ticket types ticket_types = Type.query \ .filter(Type.target_entity_type == 'Ticket').all() self.ticket_type_1 = ticket_types[0] self.ticket_type_2 = ticket_types[1] # create a User self.test_user = User( name='Test User', login='******', email='*****@*****.**', password='******' ) # create a Repository self.test_repo = Repository(name="Test Repo") # create a Project Type self.test_project_type = Type( name='Commercial Project', code='comm', target_entity_type=Project, ) # create a Project StatusList self.test_project_status1 = Status(name='PrjStat1', code='PrjStat1') self.test_project_status2 = Status(name='PrjStat2', code='PrjStat2') self.test_project_status_list = StatusList( name="Project Status List", target_entity_type=Project, statuses=[ self.test_project_status1, self.test_project_status2, ] ) self.test_task_status_list = StatusList.query\ .filter_by(target_entity_type='Task').first() # create a Project self.test_project = Project( name="Test Project 1", code="TEST_PROJECT_1", type=self.test_project_type, repository=self.test_repo, status_list=self.test_project_status_list ) # create an Asset self.test_asset_status_list = StatusList.query\ .filter_by(target_entity_type='Asset').first() self.test_asset_type = Type( name='Character Asset', code='char', target_entity_type=Asset ) self.test_asset = Asset( name="Test Asset", code='ta', project=self.test_project, status_list=self.test_asset_status_list, type=self.test_asset_type ) # create a Task self.test_task = Task( name="Modeling of Asset 1", resources=[self.test_user], status_list=self.test_task_status_list, parent=self.test_asset ) # create a Version self.test_version_status_list = StatusList( name='Version Statuses', target_entity_type=Version, statuses=[self.test_status1, self.test_status2] ) self.test_version = Version( name='Test Version', task=self.test_task, status_list=self.test_version_status_list, version=1, full_path='some/path' ) # create the Ticket self.kwargs = { 'project': self.test_project, 'links': [self.test_version], 'summary': 'This is a test ticket', 'description': 'This is the long description', 'priority': 'TRIVIAL', 'reported_by': self.test_user, } self.test_ticket = Ticket(**self.kwargs) DBSession.add(self.test_ticket) DBSession.commit() # get the Ticket Statuses self.status_new = Status.query.filter_by(name='New').first() self.status_accepted = Status.query.filter_by(name='Accepted').first() self.status_assigned = Status.query.filter_by(name='Assigned').first() self.status_reopened = Status.query.filter_by(name='Reopened').first() self.status_closed = Status.query.filter_by(name='Closed').first() def tearDown(self): """clean up the test """ DBSession.remove() @classmethod def tearDownClass(cls): """clean up the test """ DBSession.remove() def test___auto_name__class_attribute_is_set_to_True(self): """testing if the __auto_name__ class attribute is set to True for Ticket class """ self.assertTrue(Ticket.__auto_name__) def test_name_argument_is_not_used(self): """testing if the given name argument is not used """ test_value = 'Test Name' self.kwargs['name'] = test_value new_ticket = Ticket(**self.kwargs) self.assertNotEqual(new_ticket.name, test_value) def test_name_argument_is_skipped_will_not_raise_error(self): """testing if skipping the name argument is not important and an automatically generated name will be used in that case """ if 'name' in self.kwargs: self.kwargs.pop('name') # expect no errors Ticket(**self.kwargs) def test_number_attribute_is_not_created_per_project(self): """testing if the number attribute is not created per project and continues to increase for every created ticket """ proj1 = Project( name='Test Project 1', code='TP1', repository=self.test_repo, status_list=self.test_project_status_list ) proj2 = Project( name='Test Project 2', code='TP2', repository=self.test_repo, status_list=self.test_project_status_list ) proj3 = Project( name='Test Project 3', code='TP3', repository=self.test_repo, status_list=self.test_project_status_list ) p1_t1 = Ticket(project=proj1) DBSession.add(p1_t1) DBSession.commit() self.assertEqual(p1_t1.number, 2) p1_t2 = Ticket(project=proj1) DBSession.add(p1_t2) DBSession.commit() self.assertEqual(p1_t2.number, 3) p2_t1 = Ticket(project=proj2) DBSession.add(p2_t1) DBSession.commit() self.assertEqual(p2_t1.number, 4) p1_t3 = Ticket(project=proj1) DBSession.add(p1_t3) DBSession.commit() self.assertEqual(p1_t3.number, 5) p3_t1 = Ticket(project=proj3) DBSession.add(p3_t1) DBSession.commit() self.assertEqual(p3_t1.number, 6) p2_t2 = Ticket(project=proj2) DBSession.add(p2_t2) DBSession.commit() self.assertEqual(p2_t2.number, 7) p3_t2 = Ticket(project=proj3) DBSession.add(p3_t2) DBSession.commit() self.assertEqual(p3_t2.number, 8) p2_t3 = Ticket(project=proj2) DBSession.add(p2_t3) DBSession.commit() self.assertEqual(p2_t3.number, 9) def test_number_attribute_is_read_only(self): """testing if the number attribute is read-only """ self.assertRaises(AttributeError, setattr, self.test_ticket, 'number', 234) def test_number_attribute_is_automatically_increased(self): """testing if the number attribute is automatically increased """ # create two new tickets ticket1 = Ticket(**self.kwargs) DBSession.add(ticket1) DBSession.commit() ticket2 = Ticket(**self.kwargs) DBSession.add(ticket2) DBSession.commit() self.assertEqual(ticket1.number + 1, ticket2.number) self.assertEqual(ticket1.number, 2) self.assertEqual(ticket2.number, 3) def test_links_argument_accepts_anything_derived_from_SimpleEntity(self): """testing if links accepting anything derived from SimpleEntity """ self.kwargs['links'] = [ self.test_project, self.test_project_status1, self.test_project_status2, self.test_repo, self.test_version ] new_ticket = Ticket(**self.kwargs) self.assertItemsEqual( self.kwargs['links'], new_ticket.links ) def test_links_attribute_accepts_anything_derived_from_SimpleEntity(self): """testing if links attribute is accepting anything derived from SimpleEntity """ links = [ self.test_project, self.test_project_status1, self.test_project_status2, self.test_repo, self.test_version ] self.test_ticket.links = links self.assertItemsEqual(links, self.test_ticket.links) def test_related_tickets_attribute_is_an_empty_list_on_init(self): """testing if the related_tickets attribute is an empty list on init """ self.assertEqual(self.test_ticket.related_tickets, []) def test_related_tickets_attribute_is_set_to_something_other_then_a_list_of_Tickets(self): """testing if a TypeError will be raised when the related_tickets attribute is set to something other than a list of Tickets """ self.assertRaises(TypeError, setattr, self.test_ticket, 'related_tickets', ['a ticket']) def test_related_tickets_attribute_accepts_list_of_Ticket_instances(self): """testing if the related tickets attribute accepts only list of stalker.models.ticket.Ticket instances """ new_ticket1 = Ticket(**self.kwargs) new_ticket2 = Ticket(**self.kwargs) self.test_ticket.related_tickets = [new_ticket1, new_ticket2] def test_related_ticket_attribute_will_not_accept_self(self): """testing if the related_tickets attribute will not accept the Ticket itself and will raise ValueError """ self.assertRaises(ValueError, setattr, self.test_ticket, 'related_tickets', [self.test_ticket]) def test_priority_argument_is_skipped_will_set_it_to_zero(self): """testing if the priority argument is skipped will set the priority of the Ticket to 0 or TRIVIAL """ self.kwargs.pop('priority') new_ticket = Ticket(**self.kwargs) self.assertEqual(new_ticket.priority, 'TRIVIAL') def test_comments_attribute_is_synonym_for_notes_attribute(self): """testing if the comments attribute is the synonym for the notes attribute, so setting one will also set the other """ note1 = Note(name='Test Note 1', content='Test note 1') note2 = Note(name='Test Note 2', content='Test note 2') self.test_ticket.comments.append(note1) self.test_ticket.comments.append(note2) self.assertIn(note1, self.test_ticket.notes) self.assertIn(note2, self.test_ticket.notes) self.test_ticket.notes.remove(note1) self.assertNotIn(note1, self.test_ticket.comments) self.test_ticket.notes.remove(note2) self.assertNotIn(note2, self.test_ticket.comments) def test_reported_by_attribute_is_synonym_of_created_by(self): """testing if the reported_by attribute is a synonym for the created_by attribute """ user1 = User( name='user1', login='******', password='******', email='*****@*****.**' ) self.test_ticket.reported_by = user1 self.assertEqual(user1, self.test_ticket.created_by) def test_status_for_newly_created_tickets_will_be_NEW_when_skipped(self): """testing if the status of newly created tickets will be New """ # get the status NEW from the session new_ticket = Ticket(**self.kwargs) self.assertEqual(new_ticket.status, self.status_new) def test_project_argument_is_skipped(self): """testing if a TypeError will be raised when the project argument is skipped """ self.kwargs.pop('project') self.assertRaises(TypeError, Ticket, **self.kwargs) def test_project_argument_is_None(self): """testing if a TypeError will be raised when the project argument is None """ self.kwargs['project'] = None self.assertRaises(TypeError, Ticket, **self.kwargs) def test_project_argument_accepts_Project_instances_only(self): """testing if the project argument accepts Project instances only """ self.kwargs['project'] = 'Not a Project instance' self.assertRaises(TypeError, Ticket, **self.kwargs) def test_project_argument_is_working_properly(self): """testing if the project argument is working properly """ self.kwargs['project'] = self.test_project new_ticket = Ticket(**self.kwargs) self.assertEqual(new_ticket.project, self.test_project) def test_project_attribute_is_read_only(self): """testing if the project attribute is read only """ self.assertRaises(AttributeError, setattr, self.test_ticket, 'project', self.test_project) ## STATUSES ## ## resolve ## def test_resolve_method_will_change_the_status_from_New_to_Closed_and_creates_a_log(self): """testing if invoking the resolve method will change the status of the Ticket from New to Closed """ self.assertEqual(self.test_ticket.status, self.status_new) ticket_log = self.test_ticket.resolve() self.assertEqual(self.test_ticket.status, self.status_closed) self.assertEqual(ticket_log.from_status, self.status_new) self.assertEqual(ticket_log.to_status, self.status_closed) self.assertEqual(ticket_log.action, 'resolve') def test_resolve_method_will_change_the_status_from_Accepted_to_Closed(self): """testing if invoking the resolve method will change the status of the Ticket from Accepted to Closed """ self.test_ticket.status = self.status_accepted self.assertEqual(self.test_ticket.status, self.status_accepted) ticket_log = self.test_ticket.resolve() self.assertEqual(self.test_ticket.status, self.status_closed) self.assertEqual(ticket_log.from_status, self.status_accepted) self.assertEqual(ticket_log.to_status, self.status_closed) self.assertEqual(ticket_log.action, 'resolve') def test_resolve_method_will_change_the_status_from_Assigned_to_Closed(self): """testing if invoking the resolve method will change the status of the Ticket from Assigned to Closed """ self.test_ticket.status = self.status_assigned self.assertEqual(self.test_ticket.status, self.status_assigned) ticket_log = self.test_ticket.resolve() self.assertEqual(self.test_ticket.status, self.status_closed) self.assertEqual(ticket_log.from_status, self.status_assigned) self.assertEqual(ticket_log.to_status, self.status_closed) self.assertEqual(ticket_log.action, 'resolve') def test_resolve_method_will_change_the_status_from_Reopened_to_Closed(self): """testing if invoking the accept method will change the status of the Ticket from Reopened to closed """ self.test_ticket.status = self.status_reopened self.assertEqual(self.test_ticket.status, self.status_reopened) ticket_log = self.test_ticket.resolve() self.assertEqual(self.test_ticket.status, self.status_closed) self.assertEqual(ticket_log.from_status, self.status_reopened) self.assertEqual(ticket_log.to_status, self.status_closed) self.assertEqual(ticket_log.action, 'resolve') def test_resolve_method_will_not_change_the_status_from_Closed_to_anything(self): """testing if invoking the resolve method will not change the status of the Ticket from Closed to anything """ self.test_ticket.status = self.status_closed self.assertEqual(self.test_ticket.status, self.status_closed) ticket_log = self.test_ticket.resolve() self.assertIsNone(ticket_log) self.assertEqual(self.test_ticket.status, self.status_closed) ## reopen ## def test_reopen_method_will_not_change_the_status_from_New_to_anything(self): """testing if invoking the reopen method will not change the status of the Ticket from New to anything """ self.test_ticket.status = self.status_new self.assertEqual(self.test_ticket.status, self.status_new) ticket_log = self.test_ticket.reopen() self.assertIsNone(ticket_log) self.assertEqual(self.test_ticket.status, self.status_new) def test_reopen_method_will_not_change_the_status_from_Accepted_to_anything(self): """testing if invoking the reopen method will not change the status of the Ticket from Accepted to anything """ self.test_ticket.status = self.status_accepted self.assertEqual(self.test_ticket.status, self.status_accepted) ticket_log = self.test_ticket.reopen() self.assertIsNone(ticket_log) self.assertEqual(self.test_ticket.status, self.status_accepted) def test_reopen_method_will_not_change_the_status_from_Assigned_to_anything(self): """testing if invoking the reopen method will not change the status of the Ticket from Assigned to anything """ self.test_ticket.status = self.status_assigned self.assertEqual(self.test_ticket.status, self.status_assigned) ticket_log = self.test_ticket.reopen() self.assertIsNone(ticket_log) self.assertEqual(self.test_ticket.status, self.status_assigned) def test_reopen_method_will_not_change_the_status_from_Reopened_to_anything(self): """testing if invoking the reopen method will not change the status of the Ticket from Reopened to anything """ self.test_ticket.status = self.status_reopened self.assertEqual(self.test_ticket.status, self.status_reopened) ticket_log = self.test_ticket.reopen() self.assertIsNone(ticket_log) self.assertEqual(self.test_ticket.status, self.status_reopened) def test_reopen_method_will_change_the_status_from_Closed_to_Reopened(self): """testing if invoking the reopen method will change the status of the Ticket from Closed to Reopened """ self.test_ticket.status = self.status_closed self.assertEqual(self.test_ticket.status, self.status_closed) ticket_log = self.test_ticket.reopen() self.assertEqual(self.test_ticket.status, self.status_reopened) self.assertEqual(ticket_log.from_status, self.status_closed) self.assertEqual(ticket_log.to_status, self.status_reopened) self.assertEqual(ticket_log.action, 'reopen') ## accept ## def test_accept_method_will_change_the_status_from_New_to_Accepted(self): """testing if invoking the accept method will change the status of the Ticket from New to Accepted """ self.test_ticket.status = self.status_new self.assertEqual(self.test_ticket.status, self.status_new) ticket_log = self.test_ticket.accept() self.assertEqual(self.test_ticket.status, self.status_accepted) self.assertEqual(ticket_log.from_status, self.status_new) self.assertEqual(ticket_log.to_status, self.status_accepted) self.assertEqual(ticket_log.action, 'accept') def test_accept_method_will_change_the_status_from_Accepted_to_Accepted(self): """testing if invoking the accept method will change the status of the Ticket from Accepted to Accepted """ self.test_ticket.status = self.status_accepted self.assertEqual(self.test_ticket.status, self.status_accepted) ticket_log = self.test_ticket.accept() self.assertEqual(self.test_ticket.status, self.status_accepted) self.assertEqual(ticket_log.from_status, self.status_accepted) self.assertEqual(ticket_log.to_status, self.status_accepted) self.assertEqual(ticket_log.action, 'accept') def test_accept_method_will_change_the_status_from_Assigned_to_Accepted(self): """testing if invoking the accept method will change the status of the Ticket from Assigned to Accepted """ self.test_ticket.status = self.status_assigned self.assertEqual(self.test_ticket.status, self.status_assigned) ticket_log = self.test_ticket.accept() self.assertEqual(self.test_ticket.status, self.status_accepted) self.assertEqual(ticket_log.from_status, self.status_assigned) self.assertEqual(ticket_log.to_status, self.status_accepted) self.assertEqual(ticket_log.action, 'accept') def test_accept_method_will_change_the_status_from_Reopened_to_Accepted(self): """testing if invoking the accept method will change the status of the Ticket from Reopened to Accepted """ self.test_ticket.status = self.status_reopened self.assertEqual(self.test_ticket.status, self.status_reopened) ticket_log = self.test_ticket.accept() self.assertEqual(self.test_ticket.status, self.status_accepted) self.assertEqual(ticket_log.from_status, self.status_reopened) self.assertEqual(ticket_log.to_status, self.status_accepted) self.assertEqual(ticket_log.action, 'accept') def test_accept_method_will_not_change_the_status_of_Closed_to_Anything(self): """testing if invoking the accept method will not change the status of the Ticket from Closed to Anything """ self.test_ticket.status = self.status_closed self.assertEqual(self.test_ticket.status, self.status_closed) ticket_log = self.test_ticket.accept() self.assertIsNone(ticket_log) self.assertEqual(self.test_ticket.status, self.status_closed) ## reassign ## def test_reassign_method_will_change_the_status_from_New_to_Assigned(self): """testing if invoking the reassign method will change the status of the Ticket from New to Assigned """ self.test_ticket.status = self.status_new self.assertEqual(self.test_ticket.status, self.status_new) ticket_log = self.test_ticket.reassign() self.assertEqual(self.test_ticket.status, self.status_assigned) self.assertEqual(ticket_log.from_status, self.status_new) self.assertEqual(ticket_log.to_status, self.status_assigned) self.assertEqual(ticket_log.action, 'reassign') def test_reassign_method_will_change_the_status_from_Accepted_to_Assigned(self): """testing if invoking the reassign method will change the status of the Ticket from Accepted to Accepted """ self.test_ticket.status = self.status_accepted self.assertEqual(self.test_ticket.status, self.status_accepted) ticket_log = self.test_ticket.reassign() self.assertEqual(self.test_ticket.status, self.status_assigned) self.assertEqual(ticket_log.from_status, self.status_accepted) self.assertEqual(ticket_log.to_status, self.status_assigned) self.assertEqual(ticket_log.action, 'reassign') def test_reassign_method_will_change_the_status_from_Assigned_to_Assigned(self): """testing if invoking the reassign method will change the status of the Ticket from Assigned to Accepted """ self.test_ticket.status = self.status_assigned self.assertEqual(self.test_ticket.status, self.status_assigned) ticket_log = self.test_ticket.reassign() self.assertEqual(self.test_ticket.status, self.status_assigned) self.assertEqual(ticket_log.from_status, self.status_assigned) self.assertEqual(ticket_log.to_status, self.status_assigned) self.assertEqual(ticket_log.action, 'reassign') def test_reassign_method_will_change_the_status_from_Reopened_to_Assigned(self): """testing if invoking the accept method will change the status of the Ticket from Reopened to Assigned """ self.test_ticket.status = self.status_reopened self.assertEqual(self.test_ticket.status, self.status_reopened) ticket_log = self.test_ticket.reassign() self.assertEqual(self.test_ticket.status, self.status_assigned) self.assertEqual(ticket_log.from_status, self.status_reopened) self.assertEqual(ticket_log.to_status, self.status_assigned) self.assertEqual(ticket_log.action, 'reassign') def test_reassign_method_will_not_change_the_status_of_Closed_to_Anything(self): """testing if invoking the reassign method will not change the status of the Ticket from Closed to Anything """ self.test_ticket.status = self.status_closed self.assertEqual(self.test_ticket.status, self.status_closed) ticket_log = self.test_ticket.reassign() self.assertIsNone(ticket_log) self.assertEqual(self.test_ticket.status, self.status_closed) def test_resolve_method_will_set_the_resolution(self): """testing if invoking the resolve method will change the status of the Ticket from New to Closed """ self.assertEqual(self.test_ticket.status, self.status_new) ticket_log = self.test_ticket.resolve(resolution='fixed') self.assertEqual(self.test_ticket.status, self.status_closed) self.assertEqual(ticket_log.from_status, self.status_new) self.assertEqual(ticket_log.to_status, self.status_closed) self.assertEqual(ticket_log.action, 'resolve') self.assertEqual(self.test_ticket.resolution, 'fixed') def test_reopen_will_clear_resolution(self): """testing if invoking the reopen method will clear the timing_resolution """ self.assertEqual(self.test_ticket.status, self.status_new) self.test_ticket.resolve(resolution='fixed') self.assertEqual(self.test_ticket.resolution, 'fixed') ticket_log = self.test_ticket.reopen() self.assertIsInstance(ticket_log, TicketLog) self.assertEqual(self.test_ticket.resolution, '') def test_reassign_will_set_the_owner(self): """testing if invoking the reassign method will set the owner """ self.assertEqual(self.test_ticket.status, self.status_new) self.assertNotEqual(self.test_ticket.owner, self.test_user) ticket_log = self.test_ticket.reassign(assign_to=self.test_user) self.assertIsInstance(ticket_log, TicketLog) self.assertEqual(self.test_ticket.owner, self.test_user) def test_accept_will_set_the_owner(self): """testing if invoking the accept method will set the owner """ self.assertEqual(self.test_ticket.status, self.status_new) self.assertNotEqual(self.test_ticket.owner, self.test_user) ticket_log = self.test_ticket.accept(created_by=self.test_user) self.assertIsInstance(ticket_log, TicketLog) self.assertEqual(self.test_ticket.owner, self.test_user) def test_summary_argument_skipped(self): """testing if the summary argument can be skipped """ try: self.kwargs.pop('summary') except KeyError: pass new_ticket = Ticket(**self.kwargs) self.assertEqual(new_ticket.summary, '') def test_summary_argument_can_be_None(self): """testing if the summary argument can be None """ self.kwargs['summary'] = None new_ticket = Ticket(**self.kwargs) self.assertEqual(new_ticket.summary, '') def test_summary_attribute_can_be_set_to_None(self): """testing if the summary attribute can be set to None """ self.test_ticket.summary = None self.assertEqual(self.test_ticket.summary, '') def test_summary_argument_is_not_a_string_or_unicode_instance(self): """testing if a TypeError will be raised when the summary argument value is not a string or unicode """ self.kwargs['summary'] = ['not a string instance'] self.assertRaises(TypeError, Ticket, self.kwargs) def test_summary_attribute_is_set_to_a_value_other_than_a_string_or_unicode(self): """testing if the summary attribute is set to a value other than a string or unicode """ self.assertRaises(TypeError, setattr, self.test_ticket, 'summary', ['not a string or unicode']) def test_summary_argument_is_working_properly(self): """testing if the summary argument value is passed to summary attribute correctly """ test_value = 'test summary' self.kwargs['summary'] = test_value new_ticket = Ticket(**self.kwargs) self.assertEqual(new_ticket.summary, test_value) def test_summary_attribute_is_working_properly(self): """testing if the summary attribute is working properly """ test_value = 'test_summary' self.assertNotEqual(self.test_ticket.summary, test_value) self.test_ticket.summary = test_value self.assertEqual(self.test_ticket.summary, test_value)
def setUp(self): """set up the test """ # create the db DBSession.remove() db.setup() # db.init() # we just need statuses so create them instead of initializing the db db.create_ticket_statuses() db.create_entity_statuses(entity_type='Task', status_names=defaults.task_status_names, status_codes=defaults.task_status_codes) db.create_entity_statuses(entity_type='Asset', status_names=defaults.task_status_names, status_codes=defaults.task_status_codes) db.create_entity_statuses(entity_type='Shot', status_names=defaults.task_status_names, status_codes=defaults.task_status_codes) db.create_entity_statuses(entity_type='Sequence', status_names=defaults.task_status_names, status_codes=defaults.task_status_codes) db.create_entity_statuses(entity_type='Review', status_names=defaults.review_status_names, status_codes=defaults.review_status_codes) # create statuses self.test_status1 = Status(name='N', code='N') self.test_status2 = Status(name='R', code='R') # get the ticket types ticket_types = Type.query \ .filter(Type.target_entity_type == 'Ticket').all() self.ticket_type_1 = ticket_types[0] self.ticket_type_2 = ticket_types[1] # create a User self.test_user = User(name='Test User', login='******', email='*****@*****.**', password='******') # create a Repository self.test_repo = Repository(name="Test Repo") # create a Project Type self.test_project_type = Type( name='Commercial Project', code='comm', target_entity_type=Project, ) # create a Project StatusList self.test_project_status1 = Status(name='PrjStat1', code='PrjStat1') self.test_project_status2 = Status(name='PrjStat2', code='PrjStat2') self.test_project_status_list = StatusList( name="Project Status List", target_entity_type=Project, statuses=[ self.test_project_status1, self.test_project_status2, ]) self.test_task_status_list = StatusList.query\ .filter_by(target_entity_type='Task').first() # create a Project self.test_project = Project(name="Test Project 1", code="TEST_PROJECT_1", type=self.test_project_type, repository=self.test_repo, status_list=self.test_project_status_list) # create an Asset self.test_asset_status_list = StatusList.query\ .filter_by(target_entity_type='Asset').first() self.test_asset_type = Type(name='Character Asset', code='char', target_entity_type=Asset) self.test_asset = Asset(name="Test Asset", code='ta', project=self.test_project, status_list=self.test_asset_status_list, type=self.test_asset_type) # create a Task self.test_task = Task(name="Modeling of Asset 1", resources=[self.test_user], status_list=self.test_task_status_list, parent=self.test_asset) # create a Version self.test_version_status_list = StatusList( name='Version Statuses', target_entity_type=Version, statuses=[self.test_status1, self.test_status2]) self.test_version = Version(name='Test Version', task=self.test_task, status_list=self.test_version_status_list, version=1, full_path='some/path') # create the Ticket self.kwargs = { 'project': self.test_project, 'links': [self.test_version], 'summary': 'This is a test ticket', 'description': 'This is the long description', 'priority': 'TRIVIAL', 'reported_by': self.test_user, } self.test_ticket = Ticket(**self.kwargs) DBSession.add(self.test_ticket) DBSession.commit() # get the Ticket Statuses self.status_new = Status.query.filter_by(name='New').first() self.status_accepted = Status.query.filter_by(name='Accepted').first() self.status_assigned = Status.query.filter_by(name='Assigned').first() self.status_reopened = Status.query.filter_by(name='Reopened').first() self.status_closed = Status.query.filter_by(name='Closed').first()
def create_ticket(request): """runs when creating a ticket """ logged_in_user = get_logged_in_user(request) #************************************************************************** # collect data description = request.params.get('description') summary = request.params.get('summary') project_id = request.params.get('project_id', None) project = Project.query.filter(Project.id == project_id).first() owner_id = request.params.get('owner_id', None) owner = User.query.filter(User.id == owner_id).first() priority = request.params.get('priority', "TRIVIAL") type_name = request.params.get('type') send_email = request.params.get('send_email', 1) # for testing purposes logger.debug('*******************************') logger.debug('create_ticket is running') logger.debug('project_id : %s' % project_id) logger.debug('owner_id : %s' % owner_id) logger.debug('owner: %s' % owner) if not summary: return Response('Please supply a summary', 500) if not description: return Response('Please supply a description', 500) if not type_name: return Response('Please supply a type for this ticket', 500) type_ = Type.query.filter_by(name=type_name).first() if not project: return Response('There is no project with id: %s' % project_id, 500) if owner_id: if not owner: # there is an owner id but no resource found return Response('There is no user with id: %s' % owner_id, 500) else: return Response('Please supply an owner for this ticket', 500) link_ids = get_multi_integer(request, 'link_ids') links = Task.query.filter(Task.id.in_(link_ids)).all() # we are ready to create the time log # Ticket should handle the extension of the effort utc_now = local_to_utc(datetime.datetime.now()) ticket = Ticket( project=project, summary=summary, description=description, priority=priority, type=type_, created_by=logged_in_user, date_created=utc_now, date_updated=utc_now ) ticket.links = links ticket.set_owner(owner) # email the ticket to the owner and to the created by if send_email: # send email to responsible and resources of the task mailer = get_mailer(request) recipients = [logged_in_user.email, owner.email] # append link resources for link in links: for resource in link.resources: recipients.append(resource.email) # make recipients unique recipients = list(set(recipients)) description_text = \ 'A New Ticket for project "%s" has been created by %s with the ' \ 'following description:\n\n%s' % ( project.name, logged_in_user.name, description ) # TODO: add project link, after the server can be reached outside description_html = \ 'A <strong>New Ticket</strong> for project <strong>%s</strong> ' \ 'has been created by <strong>%s</strong> and assigned to ' \ '<strong>%s</strong> with the following description:<br><br>%s' % ( project.name, logged_in_user.name, owner.name, description.replace('\n', '<br>') ) message = Message( subject='New Ticket: %s' % summary, sender=dummy_email_address, recipients=recipients, body=description_text, html=description_html ) mailer.send(message) DBSession.add(ticket) return Response('Ticket Created successfully')
def test_number_attribute_is_not_created_per_project(self): """testing if the number attribute is not created per project and continues to increase for every created ticket """ from stalker import Project proj1 = Project( name='Test Project 1', code='TP1', repository=self.test_repo, ) proj2 = Project( name='Test Project 2', code='TP2', repository=self.test_repo, ) proj3 = Project( name='Test Project 3', code='TP3', repository=self.test_repo, ) from stalker import Ticket p1_t1 = Ticket(project=proj1) from stalker.db.session import DBSession DBSession.add(p1_t1) DBSession.commit() assert p1_t1.number == 2 p1_t2 = Ticket(project=proj1) DBSession.add(p1_t2) DBSession.commit() assert p1_t2.number == 3 p2_t1 = Ticket(project=proj2) DBSession.add(p2_t1) DBSession.commit() assert p2_t1.number == 4 p1_t3 = Ticket(project=proj1) DBSession.add(p1_t3) DBSession.commit() assert p1_t3.number == 5 p3_t1 = Ticket(project=proj3) DBSession.add(p3_t1) DBSession.commit() assert p3_t1.number == 6 p2_t2 = Ticket(project=proj2) DBSession.add(p2_t2) DBSession.commit() assert p2_t2.number == 7 p3_t2 = Ticket(project=proj3) DBSession.add(p3_t2) DBSession.commit() assert p3_t2.number == 8 p2_t3 = Ticket(project=proj2) DBSession.add(p2_t3) DBSession.commit() assert p2_t3.number == 9
def setUp(self): """set up the test """ super(TicketTester, self).setUp() # create statuses from stalker import Status self.test_status1 = Status(name='N', code='N') self.test_status2 = Status(name='R', code='R') # get the ticket types from stalker import Type ticket_types = Type.query \ .filter(Type.target_entity_type == 'Ticket').all() self.ticket_type_1 = ticket_types[0] self.ticket_type_2 = ticket_types[1] # create a User from stalker import User self.test_user = User(name='Test User', login='******', email='*****@*****.**', password='******') # create a Repository from stalker import Repository self.test_repo = Repository(name="Test Repo") # create a Project Type self.test_project_type = Type( name='Commercial Project', code='comm', target_entity_type='Project', ) # create a Project StatusList self.test_project_status1 = Status(name='PrjStat1', code='PrjStat1') self.test_project_status2 = Status(name='PrjStat2', code='PrjStat2') from stalker import StatusList self.test_project_status_list = StatusList( name="Project Status List", target_entity_type='Project', statuses=[ self.test_project_status1, self.test_project_status2, ]) self.test_task_status_list = \ StatusList.query.filter_by(target_entity_type='Task').first() # create a Project from stalker import Project self.test_project = Project(name="Test Project 1", code="TEST_PROJECT_1", type=self.test_project_type, repository=self.test_repo, status_list=self.test_project_status_list) # create an Asset self.test_asset_status_list = StatusList.query\ .filter_by(target_entity_type='Asset').first() self.test_asset_type = Type(name='Character Asset', code='char', target_entity_type='Asset') from stalker import Asset self.test_asset = Asset(name="Test Asset", code='ta', project=self.test_project, status_list=self.test_asset_status_list, type=self.test_asset_type) # create a Task from stalker import Task self.test_task = Task(name="Modeling of Asset 1", resources=[self.test_user], status_list=self.test_task_status_list, parent=self.test_asset) # create a Version self.test_version_status_list = StatusList( name='Version Statuses', target_entity_type='Version', statuses=[self.test_status1, self.test_status2]) from stalker import Version self.test_version = Version(name='Test Version', task=self.test_task, status_list=self.test_version_status_list, version=1, full_path='some/path') # create the Ticket self.kwargs = { 'project': self.test_project, 'links': [self.test_version], 'summary': 'This is a test ticket', 'description': 'This is the long description', 'priority': 'TRIVIAL', 'reported_by': self.test_user, } from stalker import db, Ticket self.test_ticket = Ticket(**self.kwargs) db.DBSession.add(self.test_ticket) db.DBSession.commit() # get the Ticket Statuses self.status_new = Status.query.filter_by(name='New').first() self.status_accepted = Status.query.filter_by(name='Accepted').first() self.status_assigned = Status.query.filter_by(name='Assigned').first() self.status_reopened = Status.query.filter_by(name='Reopened').first() self.status_closed = Status.query.filter_by(name='Closed').first()
class TicketTester(UnitTestBase): """Tests the :class:`~stalker.models.ticket.Ticket` class """ def setUp(self): """set up the test """ super(TicketTester, self).setUp() # create statuses from stalker import Status self.test_status1 = Status(name='N', code='N') self.test_status2 = Status(name='R', code='R') # get the ticket types from stalker import Type ticket_types = Type.query \ .filter(Type.target_entity_type == 'Ticket').all() self.ticket_type_1 = ticket_types[0] self.ticket_type_2 = ticket_types[1] # create a User from stalker import User self.test_user = User(name='Test User', login='******', email='*****@*****.**', password='******') # create a Repository from stalker import Repository self.test_repo = Repository(name="Test Repo") # create a Project Type self.test_project_type = Type( name='Commercial Project', code='comm', target_entity_type='Project', ) # create a Project StatusList self.test_project_status1 = Status(name='PrjStat1', code='PrjStat1') self.test_project_status2 = Status(name='PrjStat2', code='PrjStat2') from stalker import StatusList self.test_project_status_list = StatusList( name="Project Status List", target_entity_type='Project', statuses=[ self.test_project_status1, self.test_project_status2, ]) self.test_task_status_list = \ StatusList.query.filter_by(target_entity_type='Task').first() # create a Project from stalker import Project self.test_project = Project(name="Test Project 1", code="TEST_PROJECT_1", type=self.test_project_type, repository=self.test_repo, status_list=self.test_project_status_list) # create an Asset self.test_asset_status_list = StatusList.query\ .filter_by(target_entity_type='Asset').first() self.test_asset_type = Type(name='Character Asset', code='char', target_entity_type='Asset') from stalker import Asset self.test_asset = Asset(name="Test Asset", code='ta', project=self.test_project, status_list=self.test_asset_status_list, type=self.test_asset_type) # create a Task from stalker import Task self.test_task = Task(name="Modeling of Asset 1", resources=[self.test_user], status_list=self.test_task_status_list, parent=self.test_asset) # create a Version self.test_version_status_list = StatusList( name='Version Statuses', target_entity_type='Version', statuses=[self.test_status1, self.test_status2]) from stalker import Version self.test_version = Version(name='Test Version', task=self.test_task, status_list=self.test_version_status_list, version=1, full_path='some/path') # create the Ticket self.kwargs = { 'project': self.test_project, 'links': [self.test_version], 'summary': 'This is a test ticket', 'description': 'This is the long description', 'priority': 'TRIVIAL', 'reported_by': self.test_user, } from stalker import db, Ticket self.test_ticket = Ticket(**self.kwargs) db.DBSession.add(self.test_ticket) db.DBSession.commit() # get the Ticket Statuses self.status_new = Status.query.filter_by(name='New').first() self.status_accepted = Status.query.filter_by(name='Accepted').first() self.status_assigned = Status.query.filter_by(name='Assigned').first() self.status_reopened = Status.query.filter_by(name='Reopened').first() self.status_closed = Status.query.filter_by(name='Closed').first() def test___auto_name__class_attribute_is_set_to_True(self): """testing if the __auto_name__ class attribute is set to True for Ticket class """ from stalker import Ticket self.assertTrue(Ticket.__auto_name__) def test_name_argument_is_not_used(self): """testing if the given name argument is not used """ from stalker import Ticket test_value = 'Test Name' self.kwargs['name'] = test_value new_ticket = Ticket(**self.kwargs) self.assertNotEqual(new_ticket.name, test_value) def test_name_argument_is_skipped_will_not_raise_error(self): """testing if skipping the name argument is not important and an automatically generated name will be used in that case """ from stalker import Ticket if 'name' in self.kwargs: self.kwargs.pop('name') # expect no errors Ticket(**self.kwargs) def test_number_attribute_is_not_created_per_project(self): """testing if the number attribute is not created per project and continues to increase for every created ticket """ from stalker import Project proj1 = Project(name='Test Project 1', code='TP1', repository=self.test_repo, status_list=self.test_project_status_list) proj2 = Project(name='Test Project 2', code='TP2', repository=self.test_repo, status_list=self.test_project_status_list) proj3 = Project(name='Test Project 3', code='TP3', repository=self.test_repo, status_list=self.test_project_status_list) from stalker import db, Ticket p1_t1 = Ticket(project=proj1) db.DBSession.add(p1_t1) db.DBSession.commit() self.assertEqual(p1_t1.number, 2) p1_t2 = Ticket(project=proj1) db.DBSession.add(p1_t2) db.DBSession.commit() self.assertEqual(p1_t2.number, 3) p2_t1 = Ticket(project=proj2) db.DBSession.add(p2_t1) db.DBSession.commit() self.assertEqual(p2_t1.number, 4) p1_t3 = Ticket(project=proj1) db.DBSession.add(p1_t3) db.DBSession.commit() self.assertEqual(p1_t3.number, 5) p3_t1 = Ticket(project=proj3) db.DBSession.add(p3_t1) db.DBSession.commit() self.assertEqual(p3_t1.number, 6) p2_t2 = Ticket(project=proj2) db.DBSession.add(p2_t2) db.DBSession.commit() self.assertEqual(p2_t2.number, 7) p3_t2 = Ticket(project=proj3) db.DBSession.add(p3_t2) db.DBSession.commit() self.assertEqual(p3_t2.number, 8) p2_t3 = Ticket(project=proj2) db.DBSession.add(p2_t3) db.DBSession.commit() self.assertEqual(p2_t3.number, 9) def test_number_attribute_is_read_only(self): """testing if the number attribute is read-only """ with self.assertRaises(AttributeError) as cm: self.test_ticket.number = 234 self.assertEqual(str(cm.exception), "can't set attribute") def test_number_attribute_is_automatically_increased(self): """testing if the number attribute is automatically increased """ # create two new tickets from stalker import db, Ticket ticket1 = Ticket(**self.kwargs) db.DBSession.add(ticket1) db.DBSession.commit() ticket2 = Ticket(**self.kwargs) db.DBSession.add(ticket2) db.DBSession.commit() self.assertEqual(ticket1.number + 1, ticket2.number) self.assertEqual(ticket1.number, 2) self.assertEqual(ticket2.number, 3) def test_links_argument_accepts_anything_derived_from_SimpleEntity(self): """testing if links accepting anything derived from SimpleEntity """ self.kwargs['links'] = [ self.test_project, self.test_project_status1, self.test_project_status2, self.test_repo, self.test_version ] from stalker import Ticket new_ticket = Ticket(**self.kwargs) self.assertEqual(sorted(self.kwargs['links'], key=lambda x: x.name), sorted(new_ticket.links, key=lambda x: x.name)) def test_links_attribute_accepts_anything_derived_from_SimpleEntity(self): """testing if links attribute is accepting anything derived from SimpleEntity """ links = [ self.test_project, self.test_project_status1, self.test_project_status2, self.test_repo, self.test_version ] self.test_ticket.links = links self.assertEqual(sorted(links, key=lambda x: x.name), sorted(self.test_ticket.links, key=lambda x: x.name)) def test_related_tickets_attribute_is_an_empty_list_on_init(self): """testing if the related_tickets attribute is an empty list on init """ self.assertEqual(self.test_ticket.related_tickets, []) def test_related_tickets_attribute_is_set_to_something_other_then_a_list_of_Tickets( self): """testing if a TypeError will be raised when the related_tickets attribute is set to something other than a list of Tickets """ with self.assertRaises(TypeError) as cm: self.test_ticket.related_tickets = ['a ticket'] self.assertEqual( str(cm.exception), 'Ticket.related_ticket attribute should be a list of other ' 'stalker.models.ticket.Ticket instances not str') def test_related_tickets_attribute_accepts_list_of_Ticket_instances(self): """testing if the related tickets attribute accepts only list of stalker.models.ticket.Ticket instances """ from stalker import Ticket new_ticket1 = Ticket(**self.kwargs) new_ticket2 = Ticket(**self.kwargs) self.test_ticket.related_tickets = [new_ticket1, new_ticket2] def test_related_ticket_attribute_will_not_accept_self(self): """testing if the related_tickets attribute will not accept the Ticket itself and will raise ValueError """ with self.assertRaises(ValueError) as cm: self.test_ticket.related_tickets = [self.test_ticket] def test_priority_argument_is_skipped_will_set_it_to_zero(self): """testing if the priority argument is skipped will set the priority of the Ticket to 0 or TRIVIAL """ from stalker import Ticket self.kwargs.pop('priority') new_ticket = Ticket(**self.kwargs) self.assertEqual(new_ticket.priority, 'TRIVIAL') def test_comments_attribute_is_synonym_for_notes_attribute(self): """testing if the comments attribute is the synonym for the notes attribute, so setting one will also set the other """ from stalker import Note note1 = Note(name='Test Note 1', content='Test note 1') note2 = Note(name='Test Note 2', content='Test note 2') self.test_ticket.comments.append(note1) self.test_ticket.comments.append(note2) self.assertTrue(note1 in self.test_ticket.notes) self.assertTrue(note2 in self.test_ticket.notes) self.test_ticket.notes.remove(note1) self.assertFalse(note1 in self.test_ticket.comments) self.test_ticket.notes.remove(note2) self.assertFalse(note2 in self.test_ticket.comments) def test_reported_by_attribute_is_synonym_of_created_by(self): """testing if the reported_by attribute is a synonym for the created_by attribute """ from stalker import User user1 = User(name='user1', login='******', password='******', email='*****@*****.**') self.test_ticket.reported_by = user1 self.assertEqual(user1, self.test_ticket.created_by) def test_status_for_newly_created_tickets_will_be_NEW_when_skipped(self): """testing if the status of newly created tickets will be New """ # get the status NEW from the session from stalker import Ticket new_ticket = Ticket(**self.kwargs) self.assertEqual(new_ticket.status, self.status_new) def test_project_argument_is_skipped(self): """testing if a TypeError will be raised when the project argument is skipped """ from stalker import Ticket self.kwargs.pop('project') with self.assertRaises(TypeError) as cm: Ticket(**self.kwargs) self.assertEqual( str(cm.exception), 'Ticket.project should be an instance of ' 'stalker.models.project.Project, not NoneType') def test_project_argument_is_None(self): """testing if a TypeError will be raised when the project argument is None """ from stalker import Ticket self.kwargs['project'] = None with self.assertRaises(TypeError) as cm: Ticket(**self.kwargs) self.assertEqual( str(cm.exception), 'Ticket.project should be an instance of ' 'stalker.models.project.Project, not NoneType') def test_project_argument_accepts_Project_instances_only(self): """testing if the project argument accepts Project instances only """ from stalker import Ticket self.kwargs['project'] = 'Not a Project instance' with self.assertRaises(TypeError) as cm: Ticket(**self.kwargs) self.assertEqual( str(cm.exception), 'Ticket.project should be an instance of ' 'stalker.models.project.Project, not str') def test_project_argument_is_working_properly(self): """testing if the project argument is working properly """ from stalker import Ticket self.kwargs['project'] = self.test_project new_ticket = Ticket(**self.kwargs) self.assertEqual(new_ticket.project, self.test_project) def test_project_attribute_is_read_only(self): """testing if the project attribute is read only """ with self.assertRaises(AttributeError) as cm: self.test_ticket.project = self.test_project self.assertEqual(str(cm.exception), "can't set attribute") ## STATUSES ## ## resolve ## def test_resolve_method_will_change_the_status_from_New_to_Closed_and_creates_a_log( self): """testing if invoking the resolve method will change the status of the Ticket from New to Closed """ self.assertEqual(self.test_ticket.status, self.status_new) ticket_log = self.test_ticket.resolve() self.assertEqual(self.test_ticket.status, self.status_closed) self.assertEqual(ticket_log.from_status, self.status_new) self.assertEqual(ticket_log.to_status, self.status_closed) self.assertEqual(ticket_log.action, 'resolve') def test_resolve_method_will_change_the_status_from_Accepted_to_Closed( self): """testing if invoking the resolve method will change the status of the Ticket from Accepted to Closed """ self.test_ticket.status = self.status_accepted self.assertEqual(self.test_ticket.status, self.status_accepted) ticket_log = self.test_ticket.resolve() self.assertEqual(self.test_ticket.status, self.status_closed) self.assertEqual(ticket_log.from_status, self.status_accepted) self.assertEqual(ticket_log.to_status, self.status_closed) self.assertEqual(ticket_log.action, 'resolve') def test_resolve_method_will_change_the_status_from_Assigned_to_Closed( self): """testing if invoking the resolve method will change the status of the Ticket from Assigned to Closed """ self.test_ticket.status = self.status_assigned self.assertEqual(self.test_ticket.status, self.status_assigned) ticket_log = self.test_ticket.resolve() self.assertEqual(self.test_ticket.status, self.status_closed) self.assertEqual(ticket_log.from_status, self.status_assigned) self.assertEqual(ticket_log.to_status, self.status_closed) self.assertEqual(ticket_log.action, 'resolve') def test_resolve_method_will_change_the_status_from_Reopened_to_Closed( self): """testing if invoking the accept method will change the status of the Ticket from Reopened to closed """ self.test_ticket.status = self.status_reopened self.assertEqual(self.test_ticket.status, self.status_reopened) ticket_log = self.test_ticket.resolve() self.assertEqual(self.test_ticket.status, self.status_closed) self.assertEqual(ticket_log.from_status, self.status_reopened) self.assertEqual(ticket_log.to_status, self.status_closed) self.assertEqual(ticket_log.action, 'resolve') def test_resolve_method_will_not_change_the_status_from_Closed_to_anything( self): """testing if invoking the resolve method will not change the status of the Ticket from Closed to anything """ self.test_ticket.status = self.status_closed self.assertEqual(self.test_ticket.status, self.status_closed) ticket_log = self.test_ticket.resolve() self.assertTrue(ticket_log is None) self.assertEqual(self.test_ticket.status, self.status_closed) ## reopen ## def test_reopen_method_will_not_change_the_status_from_New_to_anything( self): """testing if invoking the reopen method will not change the status of the Ticket from New to anything """ self.test_ticket.status = self.status_new self.assertEqual(self.test_ticket.status, self.status_new) ticket_log = self.test_ticket.reopen() self.assertTrue(ticket_log is None) self.assertEqual(self.test_ticket.status, self.status_new) def test_reopen_method_will_not_change_the_status_from_Accepted_to_anything( self): """testing if invoking the reopen method will not change the status of the Ticket from Accepted to anything """ self.test_ticket.status = self.status_accepted self.assertEqual(self.test_ticket.status, self.status_accepted) ticket_log = self.test_ticket.reopen() self.assertTrue(ticket_log is None) self.assertEqual(self.test_ticket.status, self.status_accepted) def test_reopen_method_will_not_change_the_status_from_Assigned_to_anything( self): """testing if invoking the reopen method will not change the status of the Ticket from Assigned to anything """ self.test_ticket.status = self.status_assigned self.assertEqual(self.test_ticket.status, self.status_assigned) ticket_log = self.test_ticket.reopen() self.assertTrue(ticket_log is None) self.assertEqual(self.test_ticket.status, self.status_assigned) def test_reopen_method_will_not_change_the_status_from_Reopened_to_anything( self): """testing if invoking the reopen method will not change the status of the Ticket from Reopened to anything """ self.test_ticket.status = self.status_reopened self.assertEqual(self.test_ticket.status, self.status_reopened) ticket_log = self.test_ticket.reopen() self.assertTrue(ticket_log is None) self.assertEqual(self.test_ticket.status, self.status_reopened) def test_reopen_method_will_change_the_status_from_Closed_to_Reopened( self): """testing if invoking the reopen method will change the status of the Ticket from Closed to Reopened """ self.test_ticket.status = self.status_closed self.assertEqual(self.test_ticket.status, self.status_closed) ticket_log = self.test_ticket.reopen() self.assertEqual(self.test_ticket.status, self.status_reopened) self.assertEqual(ticket_log.from_status, self.status_closed) self.assertEqual(ticket_log.to_status, self.status_reopened) self.assertEqual(ticket_log.action, 'reopen') ## accept ## def test_accept_method_will_change_the_status_from_New_to_Accepted(self): """testing if invoking the accept method will change the status of the Ticket from New to Accepted """ self.test_ticket.status = self.status_new self.assertEqual(self.test_ticket.status, self.status_new) ticket_log = self.test_ticket.accept() self.assertEqual(self.test_ticket.status, self.status_accepted) self.assertEqual(ticket_log.from_status, self.status_new) self.assertEqual(ticket_log.to_status, self.status_accepted) self.assertEqual(ticket_log.action, 'accept') def test_accept_method_will_change_the_status_from_Accepted_to_Accepted( self): """testing if invoking the accept method will change the status of the Ticket from Accepted to Accepted """ self.test_ticket.status = self.status_accepted self.assertEqual(self.test_ticket.status, self.status_accepted) ticket_log = self.test_ticket.accept() self.assertEqual(self.test_ticket.status, self.status_accepted) self.assertEqual(ticket_log.from_status, self.status_accepted) self.assertEqual(ticket_log.to_status, self.status_accepted) self.assertEqual(ticket_log.action, 'accept') def test_accept_method_will_change_the_status_from_Assigned_to_Accepted( self): """testing if invoking the accept method will change the status of the Ticket from Assigned to Accepted """ self.test_ticket.status = self.status_assigned self.assertEqual(self.test_ticket.status, self.status_assigned) ticket_log = self.test_ticket.accept() self.assertEqual(self.test_ticket.status, self.status_accepted) self.assertEqual(ticket_log.from_status, self.status_assigned) self.assertEqual(ticket_log.to_status, self.status_accepted) self.assertEqual(ticket_log.action, 'accept') def test_accept_method_will_change_the_status_from_Reopened_to_Accepted( self): """testing if invoking the accept method will change the status of the Ticket from Reopened to Accepted """ self.test_ticket.status = self.status_reopened self.assertEqual(self.test_ticket.status, self.status_reopened) ticket_log = self.test_ticket.accept() self.assertEqual(self.test_ticket.status, self.status_accepted) self.assertEqual(ticket_log.from_status, self.status_reopened) self.assertEqual(ticket_log.to_status, self.status_accepted) self.assertEqual(ticket_log.action, 'accept') def test_accept_method_will_not_change_the_status_of_Closed_to_Anything( self): """testing if invoking the accept method will not change the status of the Ticket from Closed to Anything """ self.test_ticket.status = self.status_closed self.assertEqual(self.test_ticket.status, self.status_closed) ticket_log = self.test_ticket.accept() self.assertTrue(ticket_log is None) self.assertEqual(self.test_ticket.status, self.status_closed) ## reassign ## def test_reassign_method_will_change_the_status_from_New_to_Assigned(self): """testing if invoking the reassign method will change the status of the Ticket from New to Assigned """ self.test_ticket.status = self.status_new self.assertEqual(self.test_ticket.status, self.status_new) ticket_log = self.test_ticket.reassign() self.assertEqual(self.test_ticket.status, self.status_assigned) self.assertEqual(ticket_log.from_status, self.status_new) self.assertEqual(ticket_log.to_status, self.status_assigned) self.assertEqual(ticket_log.action, 'reassign') def test_reassign_method_will_change_the_status_from_Accepted_to_Assigned( self): """testing if invoking the reassign method will change the status of the Ticket from Accepted to Accepted """ self.test_ticket.status = self.status_accepted self.assertEqual(self.test_ticket.status, self.status_accepted) ticket_log = self.test_ticket.reassign() self.assertEqual(self.test_ticket.status, self.status_assigned) self.assertEqual(ticket_log.from_status, self.status_accepted) self.assertEqual(ticket_log.to_status, self.status_assigned) self.assertEqual(ticket_log.action, 'reassign') def test_reassign_method_will_change_the_status_from_Assigned_to_Assigned( self): """testing if invoking the reassign method will change the status of the Ticket from Assigned to Accepted """ self.test_ticket.status = self.status_assigned self.assertEqual(self.test_ticket.status, self.status_assigned) ticket_log = self.test_ticket.reassign() self.assertEqual(self.test_ticket.status, self.status_assigned) self.assertEqual(ticket_log.from_status, self.status_assigned) self.assertEqual(ticket_log.to_status, self.status_assigned) self.assertEqual(ticket_log.action, 'reassign') def test_reassign_method_will_change_the_status_from_Reopened_to_Assigned( self): """testing if invoking the accept method will change the status of the Ticket from Reopened to Assigned """ self.test_ticket.status = self.status_reopened self.assertEqual(self.test_ticket.status, self.status_reopened) ticket_log = self.test_ticket.reassign() self.assertEqual(self.test_ticket.status, self.status_assigned) self.assertEqual(ticket_log.from_status, self.status_reopened) self.assertEqual(ticket_log.to_status, self.status_assigned) self.assertEqual(ticket_log.action, 'reassign') def test_reassign_method_will_not_change_the_status_of_Closed_to_Anything( self): """testing if invoking the reassign method will not change the status of the Ticket from Closed to Anything """ self.test_ticket.status = self.status_closed self.assertEqual(self.test_ticket.status, self.status_closed) ticket_log = self.test_ticket.reassign() self.assertTrue(ticket_log is None) self.assertEqual(self.test_ticket.status, self.status_closed) def test_resolve_method_will_set_the_resolution(self): """testing if invoking the resolve method will change the status of the Ticket from New to Closed """ self.assertEqual(self.test_ticket.status, self.status_new) ticket_log = self.test_ticket.resolve(resolution='fixed') self.assertEqual(self.test_ticket.status, self.status_closed) self.assertEqual(ticket_log.from_status, self.status_new) self.assertEqual(ticket_log.to_status, self.status_closed) self.assertEqual(ticket_log.action, 'resolve') self.assertEqual(self.test_ticket.resolution, 'fixed') def test_reopen_will_clear_resolution(self): """testing if invoking the reopen method will clear the timing_resolution """ from stalker import TicketLog self.assertEqual(self.test_ticket.status, self.status_new) self.test_ticket.resolve(resolution='fixed') self.assertEqual(self.test_ticket.resolution, 'fixed') ticket_log = self.test_ticket.reopen() self.assertTrue(isinstance(ticket_log, TicketLog)) self.assertEqual(self.test_ticket.resolution, '') def test_reassign_will_set_the_owner(self): """testing if invoking the reassign method will set the owner """ from stalker import TicketLog self.assertEqual(self.test_ticket.status, self.status_new) self.assertNotEqual(self.test_ticket.owner, self.test_user) ticket_log = self.test_ticket.reassign(assign_to=self.test_user) self.assertTrue(isinstance(ticket_log, TicketLog)) self.assertEqual(self.test_ticket.owner, self.test_user) def test_accept_will_set_the_owner(self): """testing if invoking the accept method will set the owner """ from stalker import TicketLog self.assertEqual(self.test_ticket.status, self.status_new) self.assertNotEqual(self.test_ticket.owner, self.test_user) ticket_log = self.test_ticket.accept(created_by=self.test_user) self.assertTrue(isinstance(ticket_log, TicketLog)) self.assertEqual(self.test_ticket.owner, self.test_user) def test_summary_argument_skipped(self): """testing if the summary argument can be skipped """ from stalker import Ticket try: self.kwargs.pop('summary') except KeyError: pass new_ticket = Ticket(**self.kwargs) self.assertEqual(new_ticket.summary, '') def test_summary_argument_can_be_None(self): """testing if the summary argument can be None """ from stalker import Ticket self.kwargs['summary'] = None new_ticket = Ticket(**self.kwargs) self.assertEqual(new_ticket.summary, '') def test_summary_attribute_can_be_set_to_None(self): """testing if the summary attribute can be set to None """ self.test_ticket.summary = None self.assertEqual(self.test_ticket.summary, '') def test_summary_argument_is_not_a_string(self): """testing if a TypeError will be raised when the summary argument value is not a string """ from stalker import Ticket self.kwargs['summary'] = ['not a string instance'] with self.assertRaises(TypeError) as cm: Ticket(self.kwargs) self.assertEqual( str(cm.exception), 'Ticket.project should be an instance of ' 'stalker.models.project.Project, not dict') def test_summary_attribute_is_set_to_a_value_other_than_a_string(self): """testing if the summary attribute is set to a value other than a string """ with self.assertRaises(TypeError) as cm: self.test_ticket.summary = ['not a string'] self.assertEqual( str(cm.exception), 'Ticket.summary should be an instance of str, not list') def test_summary_argument_is_working_properly(self): """testing if the summary argument value is passed to summary attribute correctly """ from stalker import Ticket test_value = 'test summary' self.kwargs['summary'] = test_value new_ticket = Ticket(**self.kwargs) self.assertEqual(new_ticket.summary, test_value) def test_summary_attribute_is_working_properly(self): """testing if the summary attribute is working properly """ test_value = 'test_summary' self.assertNotEqual(self.test_ticket.summary, test_value) self.test_ticket.summary = test_value self.assertEqual(self.test_ticket.summary, test_value)