def test_model_contacttype(self): "Test ContactType model" obj = ContactType(name='Test', slug='test') obj.save() self.assertEquals('Test', obj.name) self.assertNotEquals(obj.id, None) obj.delete()
def test_model_liability(self): "Test liability model" contact_type = ContactType(name='test') contact_type.save() contact = Contact(name='test', contact_type=contact_type) contact.save() currency = Currency(code="GBP", name="Pounds", symbol="L", is_default=True) currency.save() account = Account(name='test', owner=contact, balance_currency=currency) account.save() obj = Liability(name='test', source=contact, target=contact, account=account, value=10, value_currency=currency) obj.save() self.assertEquals('test', obj.name) self.assertNotEquals(obj.id, None) obj.delete()
def test_model_contact(self): "Test Contact model" type = ContactType(name='Test', slug='test') type.save() obj = Contact(name='Test', contact_type=type) obj.save() self.assertEquals('Test', obj.name) self.assertNotEquals(obj.id, None) obj.delete()
def test_model_equity(self): "Test equity model" contact_type = ContactType(name='test') contact_type.save() contact = Contact(name='test', contact_type=contact_type) contact.save() obj = Equity(issue_price=10, sell_price=10, issuer=contact, owner=contact) obj.save() self.assertNotEquals(obj.id, None) obj.delete()
def test_model_asset(self): "Test asset model" contact_type = ContactType(name='test') contact_type.save() contact = Contact(name='test', contact_type=contact_type) contact.save() obj = Asset(name='test', owner=contact) obj.save() self.assertEquals('test', obj.name) self.assertNotEquals(obj.id, None) obj.delete()
def test_model_account(self): "Test account model" contact_type = ContactType(name='test') contact_type.save() contact = Contact(name='test', contact_type=contact_type) contact.save() currency = Currency(code="GBP", name="Pounds", symbol="L", is_default=True) currency.save() obj = Account(name='test', owner=contact, balance_currency=currency) obj.save() self.assertEquals('test', obj.name) self.assertNotEquals(obj.id, None) obj.delete()
def test_model_message(self): "Test message" contact_type = ContactType(name='test') contact_type.save() contact = Contact(name='test', contact_type=contact_type) contact.save() self.user = DjangoUser(username=self.username, password='') self.user.set_password(self.password) self.user.save() user = User(name='test', user=self.user) user.save() stream = MessageStream(name='test') stream.save() obj = Message(title='test', body='test', author=contact, stream=stream) obj.save() self.assertEquals('test', obj.title) self.assertNotEquals(obj.id, None) obj.delete()
class ServicesViewsTest(TestCase): "Services functional tests for views" username = "******" password = "******" prepared = False def setUp(self): "Initial Setup" if not self.prepared: # Clean up first Object.objects.all().delete() User.objects.all().delete() # Create objects self.group, created = Group.objects.get_or_create(name='test') duser, created = DjangoUser.objects.get_or_create(username=self.username) duser.set_password(self.password) duser.save() self.user, created = User.objects.get_or_create(user=duser) self.user.save() perspective, created = Perspective.objects.get_or_create(name='default') perspective.set_default_user() perspective.save() ModuleSetting.set('default_perspective', perspective.id) self.contact_type = ContactType(name='test') self.contact_type.set_default_user() self.contact_type.save() self.contact = Contact(name='test', contact_type=self.contact_type) self.contact.set_default_user() self.contact.save() self.status = TicketStatus(name='TestStatus') self.status.set_default_user() self.status.save() self.queue = TicketQueue(name='TestQueue', default_ticket_status=self.status) self.queue.set_default_user() self.queue.save() self.ticket = Ticket(name='TestTicket', status=self.status, queue=self.queue) self.ticket.set_default_user() self.ticket.save() self.agent = ServiceAgent(related_user=self.user, available_from=datetime.time(9), available_to=datetime.time(17)) self.agent.set_default_user() self.agent.save() self.service = Service(name='test') self.service.set_default_user() self.service.save() self.sla = ServiceLevelAgreement(name='test', service=self.service, client=self.contact, provider=self.contact) self.sla.set_default_user() self.sla.save() self.client = Client() self.prepared = True ###################################### # Testing views when user is logged in ###################################### def test_index_login(self): "Test index page with login at /services/" response = self.client.post('/accounts/login', {'username': self.username, 'password': self.password }) self.assertRedirects(response, '/') response = self.client.get(reverse('services')) self.assertEquals(response.status_code, 200) def test_index_owned(self): "Test index page with login at /services/owned" response = self.client.post('/accounts/login', {'username': self.username, 'password': self.password }) self.assertRedirects(response, '/') response = self.client.get(reverse('services_index_owned')) self.assertEquals(response.status_code, 200) def test_index_assigned(self): "Test index page with login at /services/assigned" response = self.client.post('/accounts/login', {'username': self.username, 'password': self.password }) self.assertRedirects(response, '/') response = self.client.get(reverse('services_index_assigned')) self.assertEquals(response.status_code, 200) # Queues def test_queue_add(self): "Test page with login at /services/queue/add" response = self.client.post('/accounts/login', {'username': self.username, 'password': self.password }) self.assertRedirects(response, '/') response = self.client.get(reverse('services_queue_add')) self.assertEquals(response.status_code, 200) def test_queue_view(self): "Test page with login at /services/queue/view/<queue_id>" response = self.client.post('/accounts/login', {'username': self.username, 'password': self.password }) self.assertRedirects(response, '/') response = self.client.get(reverse('services_queue_view', args=[self.queue.id])) self.assertEquals(response.status_code, 200) def test_queue_edit(self): "Test page with login at /services/queue/edit/<queue_id>" response = self.client.post('/accounts/login', {'username': self.username, 'password': self.password }) self.assertRedirects(response, '/') response = self.client.get(reverse('services_queue_edit', args=[self.queue.id])) self.assertEquals(response.status_code, 200) def test_queue_delete(self): "Test page with login at /services/queue/delete/<queue_id>" response = self.client.post('/accounts/login', {'username': self.username, 'password': self.password }) self.assertRedirects(response, '/') response = self.client.get(reverse('services_queue_delete', args=[self.queue.id])) self.assertEquals(response.status_code, 200) # Statuses def test_status_view(self): "Test index page with login at /services/status/view/<status_id>" response = self.client.post('/accounts/login', {'username': self.username, 'password': self.password }) self.assertRedirects(response, '/') response = self.client.get(reverse('services_status_view', args=[self.status.id])) self.assertEquals(response.status_code, 200) def test_status_edit(self): "Test index page with login at /services/status/edit/<status_id>" response = self.client.post('/accounts/login', {'username': self.username, 'password': self.password }) self.assertRedirects(response, '/') response = self.client.get(reverse('services_status_edit', args=[self.status.id])) self.assertEquals(response.status_code, 200) def test_status_delete(self): "Test index page with login at /services/status/delete/<status_id>" response = self.client.post('/accounts/login', {'username': self.username, 'password': self.password }) self.assertRedirects(response, '/') response = self.client.get(reverse('services_status_delete', args=[self.status.id])) self.assertEquals(response.status_code, 200) def test_status_add(self): "Test index page with login at /services/status/add/" response = self.client.post('/accounts/login', {'username': self.username, 'password': self.password }) self.assertRedirects(response, '/') response = self.client.get(reverse('services_status_add')) self.assertEquals(response.status_code, 200) # Tickets def test_ticket_add(self): "Test page with login at /services/ticket/add" response = self.client.post('/accounts/login', {'username': self.username, 'password': self.password }) self.assertRedirects(response, '/') response = self.client.get(reverse('services_ticket_add')) self.assertEquals(response.status_code, 200) def test_ticket_add_by_queue(self): "Test page with login at /services/ticket/add/queue/(?P<queue_id>\d+)" response = self.client.post('/accounts/login', {'username': self.username, 'password': self.password }) self.assertRedirects(response, '/') response = self.client.get(reverse('services_ticket_add_by_queue', args=[self.queue.id])) self.assertEquals(response.status_code, 200) def test_ticket_view(self): "Test page with login at /services/ticket/view/<ticket_id>" response = self.client.post('/accounts/login', {'username': self.username, 'password': self.password }) self.assertRedirects(response, '/') response = self.client.get(reverse('services_ticket_view', args=[self.ticket.id])) self.assertEquals(response.status_code, 200) def test_ticket_edit(self): "Test page with login at /services/ticket/edit/<ticket_id>" response = self.client.post('/accounts/login', {'username': self.username, 'password': self.password }) self.assertRedirects(response, '/') response = self.client.get(reverse('services_ticket_edit', args=[self.ticket.id])) self.assertEquals(response.status_code, 200) def test_ticket_delete(self): "Test page with login at /services/ticket/delete/<ticket_id>" response = self.client.post('/accounts/login', {'username': self.username, 'password': self.password }) self.assertRedirects(response, '/') response = self.client.get(reverse('services_ticket_delete', args=[self.ticket.id])) self.assertEquals(response.status_code, 200) def test_ticket_set_status(self): "Test page with login at /services/ticket/set/(?P<ticket_id>\d+)/status/(?P<status_id>\d+)" response = self.client.post('/accounts/login', {'username': self.username, 'password': self.password }) self.assertRedirects(response, '/') response = self.client.get(reverse('services_ticket_set_status', args=[self.ticket.id, self.status.id])) self.assertEquals(response.status_code, 200) # Settings def test_settings_view(self): "Test page with login at /services/settings/view" response = self.client.post('/accounts/login', {'username': self.username, 'password': self.password }) self.assertRedirects(response, '/') response = self.client.get(reverse('services_settings_view')) self.assertEquals(response.status_code, 200) def test_settings_edit(self): "Test page with login at /services/settings/edit" response = self.client.post('/accounts/login', {'username': self.username, 'password': self.password }) self.assertRedirects(response, '/') response = self.client.get(reverse('services_settings_view')) self.assertEquals(response.status_code, 200) # Catalogue def test_service_catalogue(self): "Test page with login at /services/catalogue" response = self.client.post('/accounts/login', {'username': self.username, 'password': self.password }) self.assertRedirects(response, '/') response = self.client.get(reverse('services_service_catalogue')) self.assertEquals(response.status_code, 200) # Services def test_service_view(self): "Test page with login at /services/service/view/<service_id>" response = self.client.post('/accounts/login', {'username': self.username, 'password': self.password }) self.assertRedirects(response, '/') response = self.client.get(reverse('services_service_view', args=[self.service.id])) self.assertEquals(response.status_code, 200) def test_service_edit(self): "Test page with login at /services/service/edit/<service_id>" response = self.client.post('/accounts/login', {'username': self.username, 'password': self.password }) self.assertRedirects(response, '/') response = self.client.get(reverse('services_service_edit', args=[self.service.id])) self.assertEquals(response.status_code, 200) def test_service_delete(self): "Test page with login at /services/service/delete/<service_id>" response = self.client.post('/accounts/login', {'username': self.username, 'password': self.password }) self.assertRedirects(response, '/') response = self.client.get(reverse('services_service_delete', args=[self.service.id])) self.assertEquals(response.status_code, 200) def test_service_add(self): "Test page with login at /services/service/add" response = self.client.post('/accounts/login', {'username': self.username, 'password': self.password }) self.assertRedirects(response, '/') response = self.client.get(reverse('services_service_add')) self.assertEquals(response.status_code, 200) # SLAs def test_sla_index(self): "Test page with login at /services/sla" response = self.client.post('/accounts/login', {'username': self.username, 'password': self.password }) self.assertRedirects(response, '/') response = self.client.get(reverse('services_sla_index')) self.assertEquals(response.status_code, 200) def test_sla_view(self): "Test page with login at /services/sla/view/<sla_id>" response = self.client.post('/accounts/login', {'username': self.username, 'password': self.password }) self.assertRedirects(response, '/') response = self.client.get(reverse('services_sla_view', args=[self.sla.id])) self.assertEquals(response.status_code, 200) def test_sla_edit(self): "Test page with login at /services/sla/edit/<sla_id>" response = self.client.post('/accounts/login', {'username': self.username, 'password': self.password }) self.assertRedirects(response, '/') response = self.client.get(reverse('services_sla_edit', args=[self.sla.id])) self.assertEquals(response.status_code, 200) def test_sla_delete(self): "Test page with login at /services/sla/delete/<sla_id>" response = self.client.post('/accounts/login', {'username': self.username, 'password': self.password }) self.assertRedirects(response, '/') response = self.client.get(reverse('services_sla_delete', args=[self.sla.id])) self.assertEquals(response.status_code, 200) def test_sla_add(self): "Test page with login at /services/sla/add" response = self.client.post('/accounts/login', {'username': self.username, 'password': self.password }) self.assertRedirects(response, '/') response = self.client.get(reverse('services_sla_index')) self.assertEquals(response.status_code, 200) # Agents def test_agent_index(self): "Test page with login at /services/agent" response = self.client.post('/accounts/login', {'username': self.username, 'password': self.password }) self.assertRedirects(response, '/') response = self.client.get(reverse('services_agent_index')) self.assertEquals(response.status_code, 200) def test_agent_view(self): "Test page with login at /services/agent/view/<agent_id>" response = self.client.post('/accounts/login', {'username': self.username, 'password': self.password }) self.assertRedirects(response, '/') response = self.client.get(reverse('services_agent_view', args=[self.agent.id])) self.assertEquals(response.status_code, 200) def test_agent_edit(self): "Test page with login at /services/agent/edit/<agent_id>" response = self.client.post('/accounts/login', {'username': self.username, 'password': self.password }) self.assertRedirects(response, '/') response = self.client.get(reverse('services_agent_edit', args=[self.agent.id])) self.assertEquals(response.status_code, 200) def test_agent_delete(self): "Test page with login at /services/agent/delete/<agent_id>" response = self.client.post('/accounts/login', {'username': self.username, 'password': self.password }) self.assertRedirects(response, '/') response = self.client.get(reverse('services_agent_delete', args=[self.agent.id])) self.assertEquals(response.status_code, 200) def test_agent_add(self): "Test page with login at /services/agent/add" response = self.client.post('/accounts/login', {'username': self.username, 'password': self.password }) self.assertRedirects(response, '/') response = self.client.get(reverse('services_agent_add')) self.assertEquals(response.status_code, 200) ###################################### # Testing views when user is not logged in ###################################### def test_index(self): "Test index page at /services/" response = self.client.get(reverse('services')) # Redirects as unauthenticated self.assertRedirects(response, reverse('user_login')) def test_index_owned_out(self): "Testing /services/owned" response = self.client.get(reverse('services_index_owned')) self.assertRedirects(response, reverse('user_login')) def test_index_assigned_out(self): "Testing /services/assigned" response = self.client.get(reverse('services_index_assigned')) self.assertRedirects(response, reverse('user_login')) # Queues def test_queue_add_out(self): "Testing /services/queue/add" response = self.client.get(reverse('services_queue_add')) self.assertRedirects(response, reverse('user_login')) def test_queue_view_out(self): "Testing /services/queue/view/<queue_id>" response = self.client.get(reverse('services_queue_view', args=[self.queue.id])) self.assertRedirects(response, reverse('user_login')) def test_queue_edit_out(self): "Testing /services/queue/edit/<queue_id>" response = self.client.get(reverse('services_queue_edit', args=[self.queue.id])) self.assertRedirects(response, reverse('user_login')) def test_queue_delete_out(self): "Testing /services/queue/delete/<queue_id>" response = self.client.get(reverse('services_queue_delete', args=[self.queue.id])) self.assertRedirects(response, reverse('user_login')) # Statuses def test_status_view_out(self): "Testing /services/status/view/<status_id>" response = self.client.get(reverse('services_status_view', args=[self.status.id])) self.assertRedirects(response, reverse('user_login')) def test_status_edit_out(self): "Testing /services/status/edit/<status_id>" response = self.client.get(reverse('services_status_edit', args=[self.status.id])) self.assertRedirects(response, reverse('user_login')) def test_status_delete_out(self): "Testing /services/status/delete/<status_id>" response = self.client.get(reverse('services_status_delete', args=[self.status.id])) self.assertRedirects(response, reverse('user_login')) def test_status_add_out(self): "Testing /services/status/add/" response = self.client.get(reverse('services_status_add')) self.assertRedirects(response, reverse('user_login')) # Tickets def test_ticket_add_out(self): "Testing /services/ticket/add" response = self.client.get(reverse('services_ticket_add')) self.assertRedirects(response, reverse('user_login')) def test_ticket_add_by_queue_out(self): "Testing /services/ticket/add/queue/(?P<queue_id>\d+)" response = self.client.get(reverse('services_ticket_add_by_queue', args=[self.queue.id])) self.assertRedirects(response, reverse('user_login')) def test_ticket_view_out(self): "Testing /services/ticket/view/<ticket_id>" response = self.client.get(reverse('services_ticket_view', args=[self.ticket.id])) self.assertRedirects(response, reverse('user_login')) def test_ticket_edit_out(self): "Testing /services/ticket/edit/<ticket_id>" response = self.client.get(reverse('services_ticket_edit', args=[self.ticket.id])) self.assertRedirects(response, reverse('user_login')) def test_ticket_delete_out(self): "Testing /services/ticket/delete/<ticket_id>" response = self.client.get(reverse('services_ticket_delete', args=[self.ticket.id])) self.assertRedirects(response, reverse('user_login')) def test_ticket_set_status_out(self): "Testing /services/ticket/set/(?P<ticket_id>\d+)/status/(?P<status_id>\d+)" response = self.client.get(reverse('services_ticket_set_status', args=[self.ticket.id, self.status.id])) self.assertRedirects(response, reverse('user_login')) # Settings def test_settings_view_out(self): "Testing /services/settings/view" response = self.client.get(reverse('services_settings_view')) self.assertRedirects(response, reverse('user_login')) def test_settings_edit_out(self): "Testing /services/settings/edit" response = self.client.get(reverse('services_settings_view')) self.assertRedirects(response, reverse('user_login')) # Catalogue def test_service_catalogue_out(self): "Testing /services/catalogue" response = self.client.get(reverse('services_service_catalogue')) self.assertRedirects(response, reverse('user_login')) # Services def test_service_view_out(self): "Testing /services/service/view/<service_id>" response = self.client.get(reverse('services_service_view', args=[self.service.id])) self.assertRedirects(response, reverse('user_login')) def test_service_edit_out(self): "Testing /services/service/edit/<service_id>" response = self.client.get(reverse('services_service_edit', args=[self.service.id])) self.assertRedirects(response, reverse('user_login')) def test_service_delete_out(self): "Testing /services/service/delete/<service_id>" response = self.client.get(reverse('services_service_delete', args=[self.service.id])) self.assertRedirects(response, reverse('user_login')) def test_service_add_out(self): "Testing /services/service/add" response = self.client.get(reverse('services_service_add')) self.assertRedirects(response, reverse('user_login')) # SLAs def test_sla_index_out(self): "Testing /services/sla" response = self.client.get(reverse('services_sla_index')) self.assertRedirects(response, reverse('user_login')) def test_sla_view_out(self): "Testing /services/sla/view/<sla_id>" response = self.client.get(reverse('services_sla_view', args=[self.sla.id])) self.assertRedirects(response, reverse('user_login')) def test_sla_edit_out(self): "Testing /services/sla/edit/<sla_id>" response = self.client.get(reverse('services_sla_edit', args=[self.sla.id])) self.assertRedirects(response, reverse('user_login')) def test_sla_delete_out(self): "Testing /services/sla/delete/<sla_id>" response = self.client.get(reverse('services_sla_delete', args=[self.sla.id])) self.assertRedirects(response, reverse('user_login')) def test_sla_add_out(self): "Testing /services/sla/add" response = self.client.get(reverse('services_sla_index')) self.assertRedirects(response, reverse('user_login')) # Agents def test_agent_index_out(self): "Testing /services/agent" response = self.client.get(reverse('services_agent_index')) self.assertRedirects(response, reverse('user_login')) def test_agent_view_out(self): "Testing /services/agent/view/<agent_id>" response = self.client.get(reverse('services_agent_view', args=[self.agent.id])) self.assertRedirects(response, reverse('user_login')) def test_agent_edit_out(self): "Testing /services/agent/edit/<agent_id>" response = self.client.get(reverse('services_agent_edit', args=[self.agent.id])) self.assertRedirects(response, reverse('user_login')) def test_agent_delete_out(self): "Test page with login at /services/agent/delete/<agent_id>" response = self.client.get(reverse('services_agent_delete', args=[self.agent.id])) self.assertRedirects(response, reverse('user_login')) def test_agent_add_out(self): "Test page with login at /services/agent/add" response = self.client.get(reverse('services_agent_add')) self.assertRedirects(response, reverse('user_login'))
class ServicesViewsTest(TestCase): "Services functional tests for api" username = "******" password = "******" prepared = False authentication_headers = { "CONTENT_TYPE": "application/json", "HTTP_AUTHORIZATION": "Basic YXBpX3Rlc3Q6YXBpX3Bhc3N3b3Jk", } content_type = "application/json" prepared = False def setUp(self): "Initial Setup" if not self.prepared: # Clean up first Object.objects.all().delete() User.objects.all().delete() # Create objects try: self.group = Group.objects.get(name="test") except Group.DoesNotExist: Group.objects.all().delete() self.group = Group(name="test") self.group.save() try: self.user = DjangoUser.objects.get(username=self.username) self.user.set_password(self.password) try: self.profile = self.user.get_profile() except Exception: User.objects.all().delete() self.user = DjangoUser(username=self.username, password="") self.user.set_password(self.password) self.user.save() except DjangoUser.DoesNotExist: User.objects.all().delete() self.user = DjangoUser(username=self.username, password="") self.user.set_password(self.password) self.user.save() try: perspective = Perspective.objects.get(name="default") except Perspective.DoesNotExist: Perspective.objects.all().delete() perspective = Perspective(name="default") perspective.set_user(self.user.get_profile()) perspective.save() ModuleSetting.set("default_perspective", perspective.id) self.contact_type = ContactType(name="test") self.contact_type.set_default_user() self.contact_type.save() self.contact = Contact(name="test", contact_type=self.contact_type) self.contact.set_default_user() self.contact.save() self.status = TicketStatus(name="TestStatus") self.status.set_default_user() self.status.save() self.queue = TicketQueue(name="TestQueue", default_ticket_status=self.status) self.queue.set_default_user() self.queue.save() self.ticket = Ticket(name="TestTicket", status=self.status, queue=self.queue) self.ticket.set_default_user() self.ticket.save() self.agent = ServiceAgent( related_user=self.user.get_profile(), available_from=datetime.time(9), available_to=datetime.time(17) ) self.agent.set_default_user() self.agent.save() self.service = Service(name="test") self.service.set_default_user() self.service.save() self.sla = ServiceLevelAgreement( name="test", service=self.service, client=self.contact, provider=self.contact ) self.sla.set_default_user() self.sla.save() self.client = Client() self.prepared = True def test_unauthenticated_access(self): "Test index page at /api/services/services" response = self.client.get("/api/services/services") # Redirects as unauthenticated self.assertEquals(response.status_code, 401) def test_get_ticket_statuses_list(self): """ Test index page api/services/status """ response = self.client.get(path=reverse("api_services_status"), **self.authentication_headers) self.assertEquals(response.status_code, 200) def test_get_status(self): response = self.client.get( path=reverse("api_services_status", kwargs={"object_ptr": self.status.id}), **self.authentication_headers ) self.assertEquals(response.status_code, 200) def test_update_status(self): updates = {"name": "Api update", "details": "<p>api details</p>"} response = self.client.put( path=reverse("api_services_status", kwargs={"object_ptr": self.status.id}), content_type=self.content_type, data=json.dumps(updates), **self.authentication_headers ) self.assertEquals(response.status_code, 200) def test_get_services_list(self): """ Test index page api/services """ response = self.client.get(path=reverse("api_services"), **self.authentication_headers) self.assertEquals(response.status_code, 200) def test_get_service(self): response = self.client.get( path=reverse("api_services", kwargs={"object_ptr": self.service.id}), **self.authentication_headers ) self.assertEquals(response.status_code, 200) def test_update_service(self): updates = {"name": "Api update", "details": "<p>api details</p>"} response = self.client.put( path=reverse("api_services", kwargs={"object_ptr": self.service.id}), content_type=self.content_type, data=json.dumps(updates), **self.authentication_headers ) self.assertEquals(response.status_code, 200) def test_get_sla_list(self): """ Test index page api/services/sla """ response = self.client.get(path=reverse("api_services_sla"), **self.authentication_headers) self.assertEquals(response.status_code, 200) def test_get_sla(self): response = self.client.get( path=reverse("api_services_sla", kwargs={"object_ptr": self.sla.id}), **self.authentication_headers ) self.assertEquals(response.status_code, 200) def test_update_sla(self): updates = {"name": "Api update", "service": self.service.id, "provider": self.contact.id} response = self.client.put( path=reverse("api_services_sla", kwargs={"object_ptr": self.sla.id}), content_type=self.content_type, data=json.dumps(updates), **self.authentication_headers ) print "content:" print response.content self.assertEquals(response.status_code, 200) def test_get_agents_list(self): """ Test index page api/services/agents """ response = self.client.get(path=reverse("api_services_agents"), **self.authentication_headers) self.assertEquals(response.status_code, 200) def test_get_agent(self): response = self.client.get( path=reverse("api_services_agents", kwargs={"object_ptr": self.agent.id}), **self.authentication_headers ) self.assertEquals(response.status_code, 200) def test_update_sla(self): updates = {"activate": True, "related_user": User.objects.all()[0].id} response = self.client.put( path=reverse("api_services_agents", kwargs={"object_ptr": self.agent.id}), content_type=self.content_type, data=json.dumps(updates), **self.authentication_headers ) self.assertEquals(response.status_code, 200) def test_get_queues_list(self): """ Test index page api/services/queues """ response = self.client.get(path=reverse("api_services_queues"), **self.authentication_headers) self.assertEquals(response.status_code, 200) def test_get_queue(self): response = self.client.get( path=reverse("api_services_queues", kwargs={"object_ptr": self.queue.id}), **self.authentication_headers ) self.assertEquals(response.status_code, 200) def test_update_queue(self): updates = { "name": "Api test", "default_ticket_priority": 5, "ticket_code": "api", "waiting_time": 300, "default_ticket_status": self.status.id, } response = self.client.put( path=reverse("api_services_queues", kwargs={"object_ptr": self.queue.id}), content_type=self.content_type, data=json.dumps(updates), **self.authentication_headers ) self.assertEquals(response.status_code, 200) def test_get_records(self): """ Test index page api/services/ticket/records/{ticket number} """ response = self.client.get( path=reverse("api_services_ticket_records", kwargs={"ticket_id": self.ticket.id}), **self.authentication_headers ) self.assertEquals(response.status_code, 200) def test_create_record(self): new_record = {"body": "api test message", "notify": False} response = self.client.post( path=reverse("api_services_ticket_records", kwargs={"ticket_id": self.ticket.id}), data=json.dumps(new_record), content_type=self.content_type, **self.authentication_headers ) self.assertEquals(response.status_code, 200) data = json.loads(response.content) self.assertEquals(new_record["body"], data["body"]) def test_get_tasks_list(self): """ Test index page api/services/tasks """ response = self.client.get(path=reverse("api_services_tickets"), **self.authentication_headers) self.assertEquals(response.status_code, 200) def test_get_ticket(self): response = self.client.get( path=reverse("api_services_tickets", kwargs={"object_ptr": self.ticket.id}), **self.authentication_headers ) self.assertEquals(response.status_code, 200) def test_update_ticket(self): updates = {"name": "Api updates", "status": self.status.id, "priority": 3, "urgency": 5} response = self.client.put( path=reverse("api_services_tickets", kwargs={"object_ptr": self.ticket.id}), content_type=self.content_type, data=json.dumps(updates), **self.authentication_headers ) self.assertEquals(response.status_code, 200) def test_create_ticket(self): new_ticket = {"name": "Api creates", "status": self.status.id, "priority": 3, "urgency": 5} response = self.client.post( path=reverse("api_services_tickets") + "?" + urllib.urlencode({"queue_id": self.queue.id}), content_type=self.content_type, data=json.dumps(new_ticket), **self.authentication_headers ) self.assertEquals(response.status_code, 200) data = json.loads(response.content) self.assertEquals(new_ticket["name"], data["name"]) self.assertEquals(new_ticket["urgency"], data["urgency"]) self.assertEquals(new_ticket["priority"], data["priority"]) self.assertEquals(new_ticket["status"], data["status"]["id"])
class MessagingApiTest(TestCase): "Messaging functional tests for api" username = "******" password = "******" prepared = False authentication_headers ={"CONTENT_TYPE": "application/json", "HTTP_AUTHORIZATION" : "Basic YXBpX3Rlc3Q6YXBpX3Bhc3N3b3Jk" } content_type ='application/json' def setUp(self): "Initial Setup" if not self.prepared: # Clean up first Object.objects.all().delete() # Create objects try: self.group = Group.objects.get(name='test') except Group.DoesNotExist: Group.objects.all().delete() self.group = Group(name='test') self.group.save() try: self.user = DjangoUser.objects.get(username=self.username) self.user.set_password(self.password) try: self.profile = self.user.get_profile() except Exception: User.objects.all().delete() self.user = DjangoUser(username=self.username, password='') self.user.set_password(self.password) self.user.save() except DjangoUser.DoesNotExist: User.objects.all().delete() self.user = DjangoUser(username=self.username, password='') self.user.set_password(self.password) self.user.save() try: perspective = Perspective.objects.get(name='default') except Perspective.DoesNotExist: Perspective.objects.all().delete() perspective = Perspective(name='default') perspective.set_default_user() perspective.save() ModuleSetting.set('default_perspective', perspective.id) self.contact_type = ContactType(name='test') self.contact_type.set_default_user() self.contact_type.save() self.contact = Contact(name='test', contact_type=self.contact_type) self.contact.set_default_user() self.contact.save() self.user_contact = Contact(name='test', related_user=self.user.get_profile(), contact_type=self.contact_type) self.user_contact.set_user(self.user) self.user_contact.save() self.stream = MessageStream(name='test') self.stream.set_default_user() self.stream.save() self.mlist = MailingList(name='test', from_contact=self.contact) self.mlist.set_default_user() self.mlist.save() self.message = Message(title='test', body='test', author=self.contact, stream=self.stream) self.message.set_default_user() self.message.save() self.client = Client() self.prepared = True def test_unauthenticated_access(self): "Test index page at /api/messaging/mlist" response = self.client.get('/api/messaging/mlist') # Redirects as unauthenticated self.assertEquals(response.status_code, 401) def test_get_mlist(self): """ Test index page api/messaging/mlist """ response = self.client.get(path=reverse('api_messaging_mlist'), **self.authentication_headers) self.assertEquals(response.status_code, 200) def test_get_one_mlist(self): response = self.client.get(path=reverse('api_messaging_mlist', kwargs={'object_ptr': self.mlist.id}), **self.authentication_headers) self.assertEquals(response.status_code, 200) def test_update_mlist(self): updates = {"name": "API mailing list", "description": "API description update", "from_contact": self.contact.id, "members": [self.contact.id,]} response = self.client.put(path=reverse('api_messaging_mlist', kwargs={'object_ptr': self.mlist.id}), content_type=self.content_type, data=json.dumps(updates), **self.authentication_headers) self.assertEquals(response.status_code, 200) data = json.loads(response.content) self.assertEquals(data['name'], updates['name']) self.assertEquals(data['description'], updates['description']) self.assertEquals(data['from_contact']['id'], updates['from_contact']) for i, member in enumerate(data['members']): self.assertEquals(member['id'], updates['members'][i]) def test_get_streams(self): """ Test index page api/messaging/streams """ response = self.client.get(path=reverse('api_messaging_streams'), **self.authentication_headers) self.assertEquals(response.status_code, 200) def test_get_stream(self): response = self.client.get(path=reverse('api_messaging_streams', kwargs={'object_ptr': self.stream.id}), **self.authentication_headers) self.assertEquals(response.status_code, 200) def test_update_stream(self): updates = {"name": "API stream", } response = self.client.put(path=reverse('api_messaging_streams', kwargs={'object_ptr': self.stream.id}), content_type=self.content_type, data=json.dumps(updates), **self.authentication_headers) self.assertEquals(response.status_code, 200) data = json.loads(response.content) self.assertEquals(data['name'], updates['name']) def test_get_messages(self): """ Test index page api/messaging/messages """ response = self.client.get(path=reverse('api_messaging_messages'), **self.authentication_headers) self.assertEquals(response.status_code, 200) def test_get_message(self): response = self.client.get(path=reverse('api_messaging_messages', kwargs={'object_ptr': self.message.id}), **self.authentication_headers) self.assertEquals(response.status_code, 200) def test_send_message(self): updates = {"title": "API message title", "body": "Test body", "stream": self.stream.id, "multicomplete_recipients": u'*****@*****.**'} response = self.client.post(path=reverse('api_messaging_messages'), content_type=self.content_type, data=json.dumps(updates), **self.authentication_headers) self.assertEquals(response.status_code, 200) data = json.loads(response.content) self.assertEquals(data['title'], updates['title']) self.assertEquals(data['body'], updates['body']) self.assertEquals(data['stream']['id'], updates['stream']) def test_reply_to_message(self): updates = {"title": "API test", "body": "Test body", "stream": self.stream.id, "multicomplete_recipients": u'*****@*****.**'} response = self.client.put(path=reverse('api_messaging_messages', kwargs={'object_ptr': self.message.id}), content_type=self.content_type, data=json.dumps(updates), **self.authentication_headers) self.assertEquals(response.status_code, 200) data = json.loads(response.content) self.assertNotEquals(data['title'], updates['title']) self.assertEquals(data['body'], updates['body']) self.assertEquals(data['stream']['id'], updates['stream'])
class FinanceAPITest(TestCase): "Finance api tests" username = "******" password = "******" prepared = False authentication_headers = { "CONTENT_TYPE": "application/json", "HTTP_AUTHORIZATION": "Basic YXBpX3Rlc3Q6YXBpX3Bhc3N3b3Jk", } content_type = "application/json" def setUp(self): "Initial Setup" if not self.prepared: # Clean up first Object.objects.all().delete() User.objects.all().delete() # Create objects try: self.group = Group.objects.get(name="test") except Group.DoesNotExist: Group.objects.all().delete() self.group = Group(name="test") self.group.save() try: self.user = DjangoUser.objects.get(username=self.username) self.user.set_password(self.password) try: self.profile = self.user.get_profile() except Exception: User.objects.all().delete() self.user = DjangoUser(username=self.username, password="") self.user.set_password(self.password) self.user.save() except DjangoUser.DoesNotExist: User.objects.all().delete() self.user = DjangoUser(username=self.username, password="") self.user.set_password(self.password) self.user.save() try: perspective = Perspective.objects.get(name="default") except Perspective.DoesNotExist: Perspective.objects.all().delete() perspective = Perspective(name="default") perspective.set_default_user() perspective.save() ModuleSetting.set("default_perspective", perspective.id) self.contact_type = ContactType(name="test") self.contact_type.set_default_user() self.contact_type.save() self.contact = Contact(name="test", contact_type=self.contact_type) self.contact.set_default_user() self.contact.save() self.category = Category(name="test") self.category.set_default_user() self.category.save() self.equity = Equity(issue_price=10, sell_price=10, issuer=self.contact, owner=self.contact) self.equity.set_default_user() self.equity.save() self.asset = Asset(name="test", owner=self.contact) self.asset.set_default_user() self.asset.save() self.tax = Tax(name="test", rate=10) self.tax.set_default_user() self.tax.save() self.currency = Currency(code="GBP", name="Pounds", symbol="L", is_default=True) self.currency.set_default_user() self.currency.save() self.account = Account(name="test", owner=self.contact, balance_currency=self.currency) self.account.set_default_user() self.account.save() self.liability = Liability( name="test", source=self.contact, target=self.contact, account=self.account, value=10, value_currency=self.currency, ) self.liability.set_default_user() self.liability.save() self.transaction = Transaction( name="test", account=self.account, source=self.contact, target=self.contact, value=10, value_currency=self.currency, ) self.transaction.set_default_user() self.transaction.save() self.client = Client() self.prepared = True def test_unauthenticated_access(self): "Test index page at /api/finance/currencies" response = self.client.get("/api/finance/currencies") # Redirects as unauthenticated self.assertEquals(response.status_code, 401) def test_get_currencies_list(self): """ Test index page api/finance/currencies """ response = self.client.get(path=reverse("api_finance_currencies"), **self.authentication_headers) self.assertEquals(response.status_code, 200) def test_get_currency(self): response = self.client.get( path=reverse("api_finance_currencies", kwargs={"object_ptr": self.currency.id}), **self.authentication_headers ) self.assertEquals(response.status_code, 200) def test_update_currency(self): updates = {"code": "RUB", "name": "api RUB", "factor": "10.00", "is_active": True} response = self.client.put( path=reverse("api_finance_currencies", kwargs={"object_ptr": self.currency.id}), content_type=self.content_type, data=json.dumps(updates), **self.authentication_headers ) self.assertEquals(response.status_code, 200) data = json.loads(response.content) self.assertEquals(data["code"], updates["code"]) self.assertEquals(data["name"], updates["name"]) self.assertEquals(data["factor"], updates["factor"]) self.assertEquals(data["is_active"], updates["is_active"]) def test_get_taxes_list(self): """ Test index page api/finance/taxes """ response = self.client.get(path=reverse("api_finance_taxes"), **self.authentication_headers) self.assertEquals(response.status_code, 200) def test_get_tax(self): response = self.client.get( path=reverse("api_finance_taxes", kwargs={"object_ptr": self.tax.id}), **self.authentication_headers ) self.assertEquals(response.status_code, 200) def test_update_tax(self): updates = {"name": "API TEST TAX", "rate": "20.00", "compound": False} response = self.client.put( path=reverse("api_finance_taxes", kwargs={"object_ptr": self.tax.id}), content_type=self.content_type, data=json.dumps(updates), **self.authentication_headers ) self.assertEquals(response.status_code, 200) data = json.loads(response.content) self.assertEquals(data["name"], updates["name"]) self.assertEquals(data["rate"], updates["rate"]) self.assertEquals(data["compound"], updates["compound"]) def test_get_categories_list(self): """ Test index page api/finance/categories """ response = self.client.get(path=reverse("api_finance_categories"), **self.authentication_headers) self.assertEquals(response.status_code, 200) def test_get_category(self): response = self.client.get( path=reverse("api_finance_categories", kwargs={"object_ptr": self.category.id}), **self.authentication_headers ) self.assertEquals(response.status_code, 200) def test_update_category(self): updates = {"name": "Api category", "details": "api details"} response = self.client.put( path=reverse("api_finance_categories", kwargs={"object_ptr": self.category.id}), content_type=self.content_type, data=json.dumps(updates), **self.authentication_headers ) self.assertEquals(response.status_code, 200) data = json.loads(response.content) self.assertEquals(data["name"], updates["name"]) self.assertEquals(data["details"], updates["details"]) def test_get_assets_list(self): """ Test index page api/finance/assets """ response = self.client.get(path=reverse("api_finance_assets"), **self.authentication_headers) self.assertEquals(response.status_code, 200) def test_get_asset(self): response = self.client.get( path=reverse("api_finance_assets", kwargs={"object_ptr": self.asset.id}), **self.authentication_headers ) self.assertEquals(response.status_code, 200) def test_update_asset(self): updates = { "current_value": "20.0", "owner": self.contact.id, "asset_type": "fixed", "name": "Api name", "initial_value": "40.0", } response = self.client.put( path=reverse("api_finance_assets", kwargs={"object_ptr": self.asset.id}), content_type=self.content_type, data=json.dumps(updates), **self.authentication_headers ) print response.content self.assertEquals(response.status_code, 200) data = json.loads(response.content) self.assertEquals(data["name"], updates["name"]) self.assertEquals(data["owner"]["id"], updates["owner"]) self.assertEquals(data["asset_type"], updates["asset_type"]) self.assertEquals(data["initial_value"], updates["initial_value"]) self.assertEquals(data["current_value"], updates["current_value"]) def test_get_accounts_list(self): """ Test index page api/finance/accounts """ response = self.client.get(path=reverse("api_finance_accounts"), **self.authentication_headers) self.assertEquals(response.status_code, 200) def test_get_account(self): response = self.client.get( path=reverse("api_finance_accounts", kwargs={"object_ptr": self.account.id}), **self.authentication_headers ) self.assertEquals(response.status_code, 200) def test_update_account(self): updates = { "owner": self.user.id, "balance_display": 40.0, "name": "api test name", "balance_currency": self.currency.id, } response = self.client.put( path=reverse("api_finance_accounts", kwargs={"object_ptr": self.account.id}), content_type=self.content_type, data=json.dumps(updates), **self.authentication_headers ) self.assertEquals(response.status_code, 200) data = json.loads(response.content) self.assertEquals(data["name"], updates["name"]) self.assertEquals(data["owner"]["id"], updates["owner"]) self.assertEquals(data["balance_display"], updates["balance_display"]) self.assertEquals(data["balance_currency"]["id"], updates["balance_currency"]) def test_get_equities_list(self): """ Test index page api/finance/equities""" response = self.client.get(path=reverse("api_finance_equities"), **self.authentication_headers) self.assertEquals(response.status_code, 200) def test_get_equity(self): response = self.client.get( path=reverse("api_finance_equities", kwargs={"object_ptr": self.equity.id}), **self.authentication_headers ) self.assertEquals(response.status_code, 200) def test_update_account(self): updates = { "issue_price": "100.0", "equity_type": "warrant", "sell_price": "50.0", "amount": 100, "purchase_date": "2011-06-06", "owner": self.contact.id, "issuer": self.contact.id, } response = self.client.put( path=reverse("api_finance_equities", kwargs={"object_ptr": self.equity.id}), content_type=self.content_type, data=json.dumps(updates), **self.authentication_headers ) self.assertEquals(response.status_code, 200) data = json.loads(response.content) self.assertEquals(data["issue_price"], updates["issue_price"]) self.assertEquals(data["equity_type"], updates["equity_type"]) self.assertEquals(data["sell_price"], updates["sell_price"]) self.assertEquals(data["amount"], updates["amount"]) self.assertEquals(data["purchase_date"], updates["purchase_date"]) self.assertEquals(data["owner"]["id"], updates["owner"]) self.assertEquals(data["issuer"]["id"], updates["issuer"]) self.assertEquals(data["issuer"]["id"], updates["issuer"]) def test_get_liabilities_list(self): """ Test index page api/finance/liabilities""" response = self.client.get(path=reverse("api_finance_liabilities"), **self.authentication_headers) self.assertEquals(response.status_code, 200) def test_get_liability(self): response = self.client.get( path=reverse("api_finance_liabilities", kwargs={"object_ptr": self.liability.id}), **self.authentication_headers ) self.assertEquals(response.status_code, 200) def test_update_liability(self): updates = { "account": self.account.id, "target": self.contact.id, "value_display": "20.0", "name": "api test name", "value_currency": self.currency.id, } response = self.client.put( path=reverse("api_finance_liabilities", kwargs={"object_ptr": self.liability.id}), content_type=self.content_type, data=json.dumps(updates), **self.authentication_headers ) self.assertEquals(response.status_code, 200) data = json.loads(response.content) self.assertEquals(data["name"], updates["name"]) self.assertEquals(data["target"]["id"], updates["target"]) self.assertEquals(data["account"]["id"], updates["account"]) self.assertEquals(data["value_display"], updates["value_display"]) self.assertEquals(data["value_currency"]["id"], updates["value_currency"]) def test_get_transactions_list(self): """ Test index page api/finance/transactions""" response = self.client.get(path=reverse("api_finance_transactions"), **self.authentication_headers) self.assertEquals(response.status_code, 200) def test_get_transaction(self): response = self.client.get( path=reverse("api_finance_transactions", kwargs={"object_ptr": self.transaction.id}), **self.authentication_headers ) self.assertEquals(response.status_code, 200) def test_update_transaction(self): updates = { "value_display": "1000.0", "account": self.account.id, "name": "api test name", "value_currency": self.currency.id, "datetime": "2011-03-21 11:04:42", "target": self.contact.id, "account": self.account.id, "source": self.contact.id, } response = self.client.put( path=reverse("api_finance_transactions", kwargs={"object_ptr": self.transaction.id}), content_type=self.content_type, data=json.dumps(updates), **self.authentication_headers ) print response.content self.assertEquals(response.status_code, 200) data = json.loads(response.content) self.assertEquals(data["name"], updates["name"]) self.assertEquals(data["value_display"], updates["value_display"]) self.assertEquals(data["account"]["id"], updates["account"]) self.assertEquals(data["value_currency"]["id"], updates["value_currency"]) self.assertEquals(data["datetime"], updates["datetime"]) self.assertEquals(data["target"]["id"], updates["target"]) self.assertEquals(data["account"]["id"], updates["account"]) self.assertEquals(data["source"]["id"], updates["source"])
class IdentitiesViewsTest(TestCase): "Identities View tests" username = "******" password = "******" prepared = False def setUp(self): "Initial Setup" if not self.prepared: # Clean up first Object.objects.all().delete() # Create objects self.group, created = Group.objects.get_or_create(name='test') duser, created = DjangoUser.objects.get_or_create(username=self.username) duser.set_password(self.password) duser.save() self.user, created = User.objects.get_or_create(user=duser) self.user.save() perspective, created = Perspective.objects.get_or_create(name='default') perspective.set_default_user() perspective.save() ModuleSetting.set('default_perspective', perspective.id) self.contact_type = ContactType(name='Person') self.contact_type.set_default_user() self.contact_type.save() self.contact = Contact(name='Test', contact_type=self.contact_type) self.contact.set_default_user() self.contact.save() self.field = ContactField(name='Test', label='test', field_type='text') self.field.set_default_user() self.field.save() self.client = Client() self.prepared = True ###################################### # Testing views when user is logged in ###################################### def test_index_login(self): "Test index page with login at /contacts/" response = self.client.post('/accounts/login', {'username': self.username, 'password': self.password }) self.assertRedirects(response, '/') response = self.client.get(reverse('identities_index')) self.assertEquals(response.status_code, 200) def test_contact_users_login(self): "Test page with login at /contacts/users/" response = self.client.post('/accounts/login', {'username': self.username, 'password': self.password }) self.assertRedirects(response, '/') response = self.client.get(reverse('identities_index_users')) self.assertEquals(response.status_code, 200) def test_contact_groups_login(self): "Test page with login at /contacts/groups/" response = self.client.post('/accounts/login', {'username': self.username, 'password': self.password }) self.assertRedirects(response, '/') response = self.client.get(reverse('identities_index_groups')) self.assertEquals(response.status_code, 200) # Contact types def test_contact_type_add(self): "Test page with login at /contacts/types/add/" response = self.client.post('/accounts/login', {'username': self.username, 'password': self.password }) self.assertRedirects(response, '/') response = self.client.get(reverse('identities_type_add')) self.assertEquals(response.status_code, 200) def test_contact_type_view(self): "Test page with login at /contacts/type/view/(?P<type_id>\d+)" response = self.client.post('/accounts/login', {'username': self.username, 'password': self.password }) self.assertRedirects(response, '/') response = self.client.get(reverse('identities_type_view', args=[self.contact_type.id])) self.assertEquals(response.status_code, 200) def test_contact_type_edit(self): "Test page with login at /contacts/type/edit/(?P<type_id>\d+)" response = self.client.post('/accounts/login', {'username': self.username, 'password': self.password }) self.assertRedirects(response, '/') response = self.client.get(reverse('identities_type_edit', args=[self.contact_type.id])) self.assertEquals(response.status_code, 200) def test_contact_type_delete(self): "Test page with login at /contacts/type/delete/(?P<type_id>\d+)" response = self.client.post('/accounts/login', {'username': self.username, 'password': self.password }) self.assertRedirects(response, '/') response = self.client.get(reverse('identities_type_delete', args=[self.contact_type.id])) self.assertEquals(response.status_code, 200) # Contact fields def test_contact_field_add(self): "Test page with login at /contacts/field/add" response = self.client.post('/accounts/login', {'username': self.username, 'password': self.password }) self.assertRedirects(response, '/') response = self.client.get(reverse('identities_field_add')) self.assertEquals(response.status_code, 200) def test_contact_field_view(self): "Test page with login at /contacts/field/view/(?P<field_id>\d+)" response = self.client.post('/accounts/login', {'username': self.username, 'password': self.password }) self.assertRedirects(response, '/') response = self.client.get(reverse('identities_field_view', args=[self.field.id])) self.assertEquals(response.status_code, 200) def test_contact_field_edit(self): "Test page with login at /contacts/field/edit/(?P<field_id>\d+)" response = self.client.post('/accounts/login', {'username': self.username, 'password': self.password }) self.assertRedirects(response, '/') response = self.client.get(reverse('identities_field_edit', args=[self.field.id])) self.assertEquals(response.status_code, 200) def test_contact_field_delete(self): "Test page with login at /contacts/field/delete/(?P<field_id>\d+)" response = self.client.post('/accounts/login', {'username': self.username, 'password': self.password }) self.assertRedirects(response, '/') response = self.client.get(reverse('identities_field_delete', args=[self.field.id])) self.assertEquals(response.status_code, 200) # Contacts def test_contact_add(self): "Test page with login at /contacts/contact/add/" response = self.client.post('/accounts/login', {'username': self.username, 'password': self.password }) self.assertRedirects(response, '/') response = self.client.get(reverse('identities_contact_add')) self.assertEquals(response.status_code, 200) def test_contact_add_by_type(self): "Test page with login at /contacts/contact/add/<type_id>/" response = self.client.post('/accounts/login', {'username': self.username, 'password': self.password }) self.assertRedirects(response, '/') response = self.client.get(reverse('identities_contact_add_typed', args=[self.contact_type.id])) self.assertEquals(response.status_code, 200) def test_contact_me(self): "Test page with login at /contacts/me/" response = self.client.post('/accounts/login', {'username': self.username, 'password': self.password }) self.assertRedirects(response, '/') response = self.client.get(reverse('identities_contact_me')) self.assertEquals(response.status_code, 200) def test_contact_view(self): "Test page with login at /contacts/contact/view/<contact_id>/" response = self.client.post('/accounts/login', {'username': self.username, 'password': self.password }) self.assertRedirects(response, '/') response = self.client.get(reverse('identities_contact_view', args=[self.contact.id])) self.assertEquals(response.status_code, 200) def test_contact_edit(self): "Test page with login at /contacts/contact/edit/<contact_id>/" response = self.client.post('/accounts/login', {'username': self.username, 'password': self.password }) self.assertRedirects(response, '/') response = self.client.get(reverse('identities_contact_edit', args=[self.contact.id])) self.assertEquals(response.status_code, 200) def test_contact_delete(self): "Test page with login at /contacts/contact/delete/<contact_id>/" response = self.client.post('/accounts/login', {'username': self.username, 'password': self.password }) self.assertRedirects(response, '/') response = self.client.get(reverse('identities_contact_delete', args=[self.contact.id])) self.assertEquals(response.status_code, 200) # Settings def test_contact_settings_view(self): "Test index page with login at /contacts/settings/view/" response = self.client.post('/accounts/login', {'username': self.username, 'password': self.password }) self.assertRedirects(response, '/') response = self.client.get(reverse('identities_settings_view')) self.assertEquals(response.status_code, 200) # Integration def test_contact_integration_index(self): "Test index page with login at /contacts/integration/" response = self.client.post('/accounts/login', {'username': self.username, 'password': self.password }) self.assertRedirects(response, '/') response = self.client.get(reverse('identities_integration_index')) self.assertEquals(response.status_code, 200) ###################################### # Testing views when user is not logged in ###################################### def test_index(self): "Test index page at /contacts/" response = self.client.get('/contacts/') # Redirects as unauthenticated self.assertRedirects(response, reverse('user_login')) def test_contact_users_out(self): "Testing /contacts/users/" response = self.client.get(reverse('identities_index_users')) self.assertRedirects(response, reverse('user_login')) def test_contact_groups_out(self): "Testing /contacts/groups/" response = self.client.get(reverse('identities_index_groups')) self.assertRedirects(response, reverse('user_login')) # Contact types def test_contact_type_add_out(self): "Testing /contacts/types/add/" response = self.client.get(reverse('identities_type_add')) self.assertRedirects(response, reverse('user_login')) def test_contact_type_view_out(self): "Testing /contacts/type/view/(?P<type_id>\d+)" response = self.client.get(reverse('identities_type_view', args=[self.contact_type.id])) self.assertRedirects(response, reverse('user_login')) def test_contact_type_edit_out(self): "Testing /contacts/type/edit/(?P<type_id>\d+)" response = self.client.get(reverse('identities_type_edit', args=[self.contact_type.id])) self.assertRedirects(response, reverse('user_login')) def test_contact_type_delete_out(self): "Testing /contacts/type/delete/(?P<type_id>\d+)" response = self.client.get(reverse('identities_type_delete', args=[self.contact_type.id])) self.assertRedirects(response, reverse('user_login')) # Contact fields def test_contact_field_add_out(self): "Testing /contacts/field/add" response = self.client.get(reverse('identities_field_add')) self.assertRedirects(response, reverse('user_login')) def test_contact_field_view_out(self): "Testing /contacts/field/view/(?P<field_id>\d+)" response = self.client.get(reverse('identities_field_view', args=[self.field.id])) self.assertRedirects(response, reverse('user_login')) def test_contact_field_edit_out(self): "Testing /contacts/field/edit/(?P<field_id>\d+)" response = self.client.get(reverse('identities_field_edit', args=[self.field.id])) self.assertRedirects(response, reverse('user_login')) def test_contact_field_delete_out(self): "Testing /contacts/field/delete/(?P<field_id>\d+)" response = self.client.get(reverse('identities_field_delete', args=[self.field.id])) self.assertRedirects(response, reverse('user_login')) # Contacts def test_contact_add_out(self): "Testing /contacts/contact/add/" response = self.client.get(reverse('identities_contact_add')) self.assertRedirects(response, reverse('user_login')) def test_contact_add_by_type_out(self): "Testing /contacts/contact/add/<type_id>/" response = self.client.get(reverse('identities_contact_add_typed', args=[self.contact_type.id])) self.assertRedirects(response, reverse('user_login')) def test_contact_me_out(self): "Testing /contacts/me/" response = self.client.get(reverse('identities_contact_me')) self.assertRedirects(response, reverse('user_login')) def test_contact_view_out(self): "Testing /contacts/contact/view/<contact_id>/" response = self.client.get(reverse('identities_contact_view', args=[self.contact.id])) self.assertRedirects(response, reverse('user_login')) def test_contact_edit_out(self): "Testing /contacts/contact/edit/<contact_id>/" response = self.client.get(reverse('identities_contact_edit', args=[self.contact.id])) self.assertRedirects(response, reverse('user_login')) def test_contact_delete_out(self): "Testing /contacts/contact/delete/<contact_id>/" response = self.client.get(reverse('identities_contact_delete', args=[self.contact.id])) self.assertRedirects(response, reverse('user_login')) # Settings def test_contact_settings_view_out(self): "Testing /contacts/settings/view/" response = self.client.get(reverse('identities_settings_view')) self.assertRedirects(response, reverse('user_login')) # Integration def test_contact_integration_index_out(self): "Testing /contacts/integration/" response = self.client.get(reverse('identities_integration_index')) self.assertRedirects(response, reverse('user_login'))
class ProjectsViewsTest(TestCase): "Projects functional tests for views" username = "******" password = "******" prepared = False def setUp(self): "Initial Setup" if not self.prepared: # Clean up first Object.objects.all().delete() User.objects.all().delete() # Create objects self.group, created = Group.objects.get_or_create(name='test') duser, created = DjangoUser.objects.get_or_create(username=self.username) duser.set_password(self.password) duser.save() self.user, created = User.objects.get_or_create(user=duser) self.user.save() perspective, created = Perspective.objects.get_or_create(name='default') perspective.set_default_user() perspective.save() ModuleSetting.set('default_perspective', perspective.id) self.contact_type = ContactType(name='test') self.contact_type.set_default_user() self.contact_type.save() self.contact = Contact(name='test', contact_type=self.contact_type) self.contact.set_default_user() self.contact.save() self.project = Project(name='test', manager=self.contact, client=self.contact) self.project.set_default_user() self.project.save() self.status = TaskStatus(name='test') self.status.set_default_user() self.status.save() self.milestone = Milestone(name='test', project=self.project, status=self.status) self.milestone.set_default_user() self.milestone.save() self.task = Task(name='test', project=self.project, status=self.status, priority=3) self.task.set_default_user() self.task.save() self.time_slot = TaskTimeSlot(task=self.task, details='test', time_from=datetime.now(), user=self.user) self.time_slot.set_default_user() self.time_slot.save() self.parent = Project(name='test') self.parent.set_default_user() self.parent.save() self.parent_task = Task(name='test', project=self.project, status=self.status, priority=3) self.parent_task.set_default_user() self.parent_task.save() self.client = Client() self.prepared = True ###################################### # Testing views when user is logged in ###################################### def test_index_login(self): "Test index page with login at /projects/" response = self.client.post('/accounts/login', {'username': self.username, 'password': self.password }) self.assertRedirects(response, '/') response = self.client.get(reverse('projects')) self.assertEquals(response.status_code, 200) # Projects def test_project_add(self): "Test index page with login at /projects/add/" response = self.client.post('/accounts/login', {'username': self.username, 'password': self.password }) self.assertRedirects(response, '/') response = self.client.get(reverse('project_add')) self.assertEquals(response.status_code, 200) def test_project_add_typed(self): "Test index page with login at /projects/add/<project_id>/" response = self.client.post('/accounts/login', {'username': self.username, 'password': self.password }) self.assertRedirects(response, '/') response = self.client.get(reverse('projects_project_add_typed', args=[self.parent.id])) self.assertEquals(response.status_code, 200) def test_project_view_login(self): "Test index page with login at /projects/view/<project_id>" response = self.client.post('/accounts/login', {'username': self.username, 'password': self.password }) self.assertRedirects(response, '/') response = self.client.get(reverse('projects_project_view', args=[self.project.id])) self.assertEquals(response.status_code, 200) def test_project_edit_login(self): "Test index page with login at /projects/edit//<project_id>" response = self.client.post('/accounts/login', {'username': self.username, 'password': self.password }) self.assertRedirects(response, '/') response = self.client.get(reverse('projects_project_edit', args=[self.project.id])) self.assertEquals(response.status_code, 200) def test_project_delete_login(self): "Test index page with login at /projects/delete//<project_id>" response = self.client.post('/accounts/login', {'username': self.username, 'password': self.password }) self.assertRedirects(response, '/') response = self.client.get(reverse('projects_project_delete', args=[self.project.id])) self.assertEquals(response.status_code, 200) # Milestones def test_milestone_add(self): "Test index page with login at /projects/milestone/add" response = self.client.post('/accounts/login', {'username': self.username, 'password': self.password }) self.assertRedirects(response, '/') response = self.client.get(reverse('projects_milestone_add')) self.assertEquals(response.status_code, 200) def test_milestone_add_typed(self): "Test index page with login at /projects/milestone/add/<project_id>" response = self.client.post('/accounts/login', {'username': self.username, 'password': self.password }) self.assertRedirects(response, '/') response = self.client.get(reverse('projects_milestone_add_typed', args=[self.parent.id])) self.assertEquals(response.status_code, 200) def test_milestone_view_login(self): "Test index page with login at /projects/milestone/view/<milestone_id>" response = self.client.post('/accounts/login', {'username': self.username, 'password': self.password }) self.assertRedirects(response, '/') response = self.client.get(reverse('projects_milestone_view', args=[self.milestone.id])) self.assertEquals(response.status_code, 200) def test_milestone_edit_login(self): "Test index page with login at /projects/milestone/edit/<milestone_id>" response = self.client.post('/accounts/login', {'username': self.username, 'password': self.password }) self.assertRedirects(response, '/') response = self.client.get(reverse('projects_milestone_edit', args=[self.milestone.id])) self.assertEquals(response.status_code, 200) def test_milestone_delete_login(self): "Test index page with login at /projects/milestone/delete/<milestone_id>" response = self.client.post('/accounts/login', {'username': self.username, 'password': self.password }) self.assertRedirects(response, '/') response = self.client.get(reverse('projects_milestone_delete', args=[self.milestone.id])) self.assertEquals(response.status_code, 200) # Tasks def test_task_add(self): "Test index page with login at /projects/task/add/" response = self.client.post('/accounts/login', {'username': self.username, 'password': self.password }) self.assertRedirects(response, '/') response = self.client.get(reverse('projects_task_add')) self.assertEquals(response.status_code, 200) def test_task_add_typed(self): "Test index page with login at /projects/task/add/<project_id>" response = self.client.post('/accounts/login', {'username': self.username, 'password': self.password }) self.assertRedirects(response, '/') response = self.client.get(reverse('projects_task_add_typed', args=[self.project.id])) self.assertEquals(response.status_code, 200) def test_task_add_to_milestone(self): "Test index page with login at /projects/task/add/<milestone_id>" response = self.client.post('/accounts/login', {'username': self.username, 'password': self.password }) self.assertRedirects(response, '/') response = self.client.get(reverse('projects_task_add_to_milestone', args=[self.milestone.id])) self.assertEquals(response.status_code, 200) def test_task_add_subtask(self): "Test index page with login at /projects/task/add/<task_id>/" response = self.client.post('/accounts/login', {'username': self.username, 'password': self.password }) self.assertRedirects(response, '/') response = self.client.get(reverse('projects_task_add_subtask', args=[self.parent_task.id])) self.assertEquals(response.status_code, 200) def test_task_set_status(self): "Test index page with login at /projects/task/add/<task_id>/status/<status_id>" response = self.client.post('/accounts/login', {'username': self.username, 'password': self.password }) self.assertRedirects(response, '/') response = self.client.get(reverse('projects_task_set_status', args=[self.task.id, self.status.id])) self.assertEquals(response.status_code, 200) def test_task_view_login(self): "Test index page with login at /projects/task/view/<task_id>" response = self.client.post('/accounts/login', {'username': self.username, 'password': self.password }) self.assertRedirects(response, '/') response = self.client.get(reverse('projects_task_view', args=[self.task.id])) self.assertEquals(response.status_code, 200) def test_task_edit_login(self): "Test index page with login at /projects/task/edit/<task_id>" response = self.client.post('/accounts/login', {'username': self.username, 'password': self.password }) self.assertRedirects(response, '/') response = self.client.get(reverse('projects_task_edit', args=[self.task.id])) self.assertEquals(response.status_code, 200) def test_task_delete_login(self): "Test index page with login at /projects/task/delete/<task_id>" response = self.client.post('/accounts/login', {'username': self.username, 'password': self.password }) self.assertRedirects(response, '/') response = self.client.get(reverse('projects_task_delete', args=[self.task.id])) self.assertEquals(response.status_code, 200) # Task Time Slots def test_time_slot_add(self): "Test index page with login at /projects/task/view/time/<task_id>add/" response = self.client.post('/accounts/login', {'username': self.username, 'password': self.password }) self.assertRedirects(response, '/') response = self.client.get(reverse('projects_task_time_slot_add', args=[self.task.id])) self.assertEquals(response.status_code, 200) def test_time_slot_view_login(self): "Test index page with login at /projects/task/view/time/<time_slot_id>" response = self.client.post('/accounts/login', {'username': self.username, 'password': self.password }) self.assertRedirects(response, '/') response = self.client.get(reverse('projects_task_view', args=[self.task.id])) self.assertEquals(response.status_code, 200) def test_time_slot_edit_login(self): "Test index page with login at /projects/task/edit/time/<time_slot_id>" response = self.client.post('/accounts/login', {'username': self.username, 'password': self.password }) self.assertRedirects(response, '/') response = self.client.get(reverse('projects_task_edit', args=[self.task.id])) self.assertEquals(response.status_code, 200) def test_time_slot_delete_login(self): "Test index page with login at /projects/task/delete/time/<time_slot_id>" response = self.client.post('/accounts/login', {'username': self.username, 'password': self.password }) self.assertRedirects(response, '/') response = self.client.get(reverse('projects_task_delete', args=[self.task.id])) self.assertEquals(response.status_code, 200) # Task Statuses def test_task_status_add(self): "Test index page with login at /projects/task/status/add/" response = self.client.post('/accounts/login', {'username': self.username, 'password': self.password }) self.assertRedirects(response, '/') response = self.client.get(reverse('projects_task_status_add')) self.assertEquals(response.status_code, 200) def test_task_status_view_login(self): "Test index page with login at /projects/task/status/view/<status_id>/" response = self.client.post('/accounts/login', {'username': self.username, 'password': self.password }) self.assertRedirects(response, '/') response = self.client.get(reverse('projects_index_by_status', args=[self.status.id])) self.assertEquals(response.status_code, 200) def test_task_status_edit_login(self): "Test index page with login at /projects/task/status/edit/<status_id>/" response = self.client.post('/accounts/login', {'username': self.username, 'password': self.password }) self.assertRedirects(response, '/') response = self.client.get(reverse('projects_task_status_edit', args=[self.status.id])) self.assertEquals(response.status_code, 200) def test_task_status_delete_login(self): "Test index page with login at /projects/task/status/delete/<status_id>/" response = self.client.post('/accounts/login', {'username': self.username, 'password': self.password }) self.assertRedirects(response, '/') response = self.client.get(reverse('projects_task_status_delete', args=[self.status.id])) self.assertEquals(response.status_code, 200) # Settings def test_project_settings_view(self): "Test index page with login at /projects/settings/view/" response = self.client.post('/accounts/login', {'username': self.username, 'password': self.password }) self.assertRedirects(response, '/') response = self.client.get(reverse('projects_settings_view')) self.assertEquals(response.status_code, 200) def test_project_settings_edit(self): "Test index page with login at /projects/settings/edit/" response = self.client.post('/accounts/login', {'username': self.username, 'password': self.password }) self.assertRedirects(response, '/') response = self.client.get(reverse('projects_settings_edit')) self.assertEquals(response.status_code, 200) ###################################### # Testing views when user is not logged in ###################################### def test_index(self): "Test index page at /projects/" response = self.client.get('/projects/') # Redirects as unauthenticated self.assertRedirects(response, reverse('user_login')) # Projects def test_project_add_out(self): "Testing /projects/add/" response = self.client.get(reverse('project_add')) self.assertRedirects(response, reverse('user_login')) def test_project_add_typed_out(self): "Testing /projects/add/<project_id>/" response = self.client.get(reverse('projects_project_add_typed', args=[self.parent.id])) self.assertRedirects(response, reverse('user_login')) def test_project_view_out(self): "Testing /projects/view/<project_id>" response = self.client.get(reverse('projects_project_view', args=[self.project.id])) self.assertRedirects(response, reverse('user_login')) def test_project_edit_out(self): "Testing /projects/edit//<project_id>" response = self.client.get(reverse('projects_project_edit', args=[self.project.id])) self.assertRedirects(response, reverse('user_login')) def test_project_delete_out(self): "Testing /projects/delete//<project_id>" response = self.client.get(reverse('projects_project_delete', args=[self.project.id])) self.assertRedirects(response, reverse('user_login')) # Milestones def test_milestone_add_out(self): "Testing /projects/milestone/add" response = self.client.get(reverse('projects_milestone_add')) self.assertRedirects(response, reverse('user_login')) def test_milestone_add_typed_out(self): "Testing /projects/milestone/add/<project_id>" response = self.client.get(reverse('projects_milestone_add_typed', args=[self.parent.id])) self.assertRedirects(response, reverse('user_login')) def test_milestone_view_out(self): "Testing /projects/milestone/view/<milestone_id>" response = self.client.get(reverse('projects_milestone_view', args=[self.milestone.id])) self.assertRedirects(response, reverse('user_login')) def test_milestone_edit_out(self): "Testing /projects/milestone/edit/<milestone_id>" response = self.client.get(reverse('projects_milestone_edit', args=[self.milestone.id])) self.assertRedirects(response, reverse('user_login')) def test_milestone_delete_out(self): "Testing /projects/milestone/delete/<milestone_id>" response = self.client.get(reverse('projects_milestone_delete', args=[self.milestone.id])) self.assertRedirects(response, reverse('user_login')) # Tasks def test_task_add_out(self): "Testing /projects/task/add/" response = self.client.get(reverse('projects_task_add')) self.assertRedirects(response, reverse('user_login')) def test_task_add_typed_out(self): "Testing /projects/task/add/<project_id>" response = self.client.get(reverse('projects_task_add_typed', args=[self.project.id])) self.assertRedirects(response, reverse('user_login')) def test_task_add_to_milestone_out(self): "Testing /projects/task/add/<milestone_id>" response = self.client.get(reverse('projects_task_add_to_milestone', args=[self.milestone.id])) self.assertRedirects(response, reverse('user_login')) def test_task_add_subtask_out(self): "Testing /projects/task/add/<task_id>/" response = self.client.get(reverse('projects_task_add_subtask', args=[self.parent_task.id])) self.assertRedirects(response, reverse('user_login')) def test_task_set_status_out(self): "Testing /projects/task/add/<task_id>/status/<status_id>" response = self.client.get(reverse('projects_task_set_status', args=[self.task.id, self.status.id])) self.assertRedirects(response, reverse('user_login')) def test_task_view_out(self): "Testing /projects/task/view/<task_id>" response = self.client.get(reverse('projects_task_view', args=[self.task.id])) self.assertRedirects(response, reverse('user_login')) def test_task_edit_out(self): "Testing /projects/task/edit/<task_id>" response = self.client.get(reverse('projects_task_edit', args=[self.task.id])) self.assertRedirects(response, reverse('user_login')) def test_task_delete_out(self): "Testing /projects/task/delete/<task_id>" response = self.client.get(reverse('projects_task_delete', args=[self.task.id])) self.assertRedirects(response, reverse('user_login')) # Task Time Slots def test_time_slot_add_out(self): "Testing /projects/task/view/time/<task_id>add/" response = self.client.get(reverse('projects_task_time_slot_add', args=[self.task.id])) self.assertRedirects(response, reverse('user_login')) def test_time_slot_view_out(self): "Testing /projects/task/view/time/<time_slot_id>" response = self.client.get(reverse('projects_task_view', args=[self.task.id])) self.assertRedirects(response, reverse('user_login')) def test_time_slot_edit_out(self): "Testing /projects/task/edit/time/<time_slot_id>" response = self.client.get(reverse('projects_task_edit', args=[self.task.id])) self.assertRedirects(response, reverse('user_login')) def test_time_slot_delete_out(self): "Testing /projects/task/delete/time/<time_slot_id>" response = self.client.get(reverse('projects_task_delete', args=[self.task.id])) self.assertRedirects(response, reverse('user_login')) # Task Statuses def test_task_status_add_out(self): "Testing /projects/task/status/add/" response = self.client.get(reverse('projects_task_status_add')) self.assertRedirects(response, reverse('user_login')) def test_task_status_view_out(self): "Testing /projects/task/status/view/<status_id>/" response = self.client.get(reverse('projects_index_by_status', args=[self.status.id])) self.assertRedirects(response, reverse('user_login')) def test_task_status_edit_out(self): "Testing /projects/task/status/edit/<status_id>/" response = self.client.get(reverse('projects_task_status_edit', args=[self.status.id])) self.assertRedirects(response, reverse('user_login')) def test_task_status_delete_out(self): "Testing /projects/task/status/delete/<status_id>/" response = self.client.get(reverse('projects_task_status_delete', args=[self.status.id])) self.assertRedirects(response, reverse('user_login')) # Settings def test_project_settings_view_out(self): "Testing /projects/settings/view/" response = self.client.get(reverse('projects_settings_view')) self.assertRedirects(response, reverse('user_login')) def test_project_settings_edit_out(self): "Testing /projects/settings/edit/" response = self.client.get(reverse('projects_settings_edit')) self.assertRedirects(response, reverse('user_login'))
class ProjectsAPITest(TestCase): "Projects functional tests for api" username = "******" password = "******" prepared = False authentication_headers = { "CONTENT_TYPE": "application/json", "HTTP_AUTHORIZATION": "Basic YXBpX3Rlc3Q6YXBpX3Bhc3N3b3Jk", } content_type = "application/json" def setUp(self): "Initial Setup" if not self.prepared: # Clean up first Object.objects.all().delete() User.objects.all().delete() # Create objects try: self.group = Group.objects.get(name="api_test") except Group.DoesNotExist: Group.objects.all().delete() self.group = Group(name="api_test") self.group.save() try: self.user = DjangoUser.objects.get(username=self.username) self.user.set_password(self.password) try: self.profile = self.user.get_profile() except Exception: User.objects.all().delete() self.user = DjangoUser(username=self.username, password="") self.user.set_password(self.password) self.user.save() except DjangoUser.DoesNotExist: User.objects.all().delete() self.user = DjangoUser(username=self.username, password="") self.user.set_password(self.password) self.user.save() try: perspective = Perspective.objects.get(name="default") except Perspective.DoesNotExist: Perspective.objects.all().delete() perspective = Perspective(name="default") perspective.set_default_user() perspective.save() ModuleSetting.set("default_perspective", perspective.id) self.contact_type = ContactType(name="api_test") self.contact_type.set_default_user() self.contact_type.save() self.contact = Contact(name="api_test", contact_type=self.contact_type) self.contact.set_default_user() self.contact.save() self.project = Project(name="api_test", manager=self.contact, client=self.contact) self.project.set_default_user() self.project.save() self.status = TaskStatus(name="api_test") self.status.set_default_user() self.status.save() self.milestone = Milestone(name="api_test", project=self.project, status=self.status) self.milestone.set_default_user() self.milestone.save() self.task = Task(name="api_test", project=self.project, status=self.status, priority=3) self.task.set_default_user() self.task.save() self.time_slot = TaskTimeSlot( task=self.task, details="api_test", time_from=datetime.now(), user=self.user.get_profile() ) self.time_slot.set_default_user() self.time_slot.save() self.parent = Project(name="api_test") self.parent.set_default_user() self.parent.save() self.parent_task = Task(name="api_test", project=self.project, status=self.status, priority=3) self.parent_task.set_default_user() self.parent_task.save() self.client = Client() self.prepared = True def test_unauthenticated_access(self): "Test index page at /projects" response = self.client.get("/api/projects/projects") # Redirects as unauthenticated self.assertEquals(response.status_code, 401) # Get info about projects, milestones, status, tasks, tasktimes. def test_get_project_list(self): """ Test index page api/projects """ response = self.client.get(path=reverse("api_projects"), **self.authentication_headers) self.assertEquals(response.status_code, 200) def test_get_status_list(self): """ Test index page api/status """ response = self.client.get(path=reverse("api_projects_status"), **self.authentication_headers) self.assertEquals(response.status_code, 200) def test_get_milestones_list(self): """ Test index page api/milestones """ response = self.client.get(path=reverse("api_projects_milestones"), **self.authentication_headers) self.assertEquals(response.status_code, 200) def test_get_task_list(self): """ Test index page api/tasks """ response = self.client.get(path=reverse("api_projects_tasks"), **self.authentication_headers) self.assertEquals(response.status_code, 200) def test_get_tasktimes_list(self): """ Test index page api/tasktimes """ response = self.client.get(path=reverse("api_projects_tasktimes"), **self.authentication_headers) self.assertEquals(response.status_code, 200) def test_get_project(self): response = self.client.get( reverse("api_projects", kwargs={"object_ptr": self.project.id}), **self.authentication_headers ) self.assertEquals(response.status_code, 200) data = json.loads(response.content) self.assertEquals(data["id"], self.project.id) self.assertEquals(data["name"], self.project.name) self.assertEquals(data["details"], self.project.details) def test_get_status(self): response = self.client.get( reverse("api_projects_status", kwargs={"object_ptr": self.status.id}), **self.authentication_headers ) self.assertEquals(response.status_code, 200) data = json.loads(response.content) self.assertEquals(data["id"], self.status.id) self.assertEquals(data["name"], self.status.name) def test_get_milestone(self): response = self.client.get( reverse("api_projects_milestones", kwargs={"object_ptr": self.milestone.id}), **self.authentication_headers ) self.assertEquals(response.status_code, 200) data = json.loads(response.content) self.assertEquals(data["id"], self.milestone.id) self.assertEquals(data["name"], self.milestone.name) self.assertEquals(data["project"]["id"], self.milestone.project.id) self.assertEquals(data["status"]["id"], self.milestone.status.id) def test_get_task(self): response = self.client.get( reverse("api_projects_tasks", kwargs={"object_ptr": self.task.id}), **self.authentication_headers ) self.assertEquals(response.status_code, 200) data = json.loads(response.content) self.assertEquals(data["id"], self.task.id) self.assertEquals(data["name"], self.task.name) self.assertEquals(data["priority"], self.task.priority) self.assertEquals(data["project"]["id"], self.task.project.id) self.assertEquals(data["status"]["id"], self.task.status.id) def test_get_timeslot(self): response = self.client.get( reverse("api_projects_tasktimes", kwargs={"object_ptr": self.time_slot.id}), **self.authentication_headers ) self.assertEquals(response.status_code, 200) data = json.loads(response.content) self.assertEquals(data["id"], self.time_slot.id) self.assertEquals(data["task"]["id"], self.time_slot.task.id) # Common test def test_common_project(self): # create new project new_project = {"name": "api test", "details": "<p>test details</p>"} response = self.client.post( reverse("api_projects"), data=json.dumps(new_project), content_type=self.content_type, **self.authentication_headers ) # print response.request self.assertEquals(response.status_code, 200) # check data in response data = json.loads(response.content) self.assertEquals(data["name"], new_project["name"]) self.assertEquals(data["details"], new_project["details"]) project_id = data["id"] # get info about new project response = self.client.get( path=reverse("api_projects", kwargs={"object_ptr": project_id}), **self.authentication_headers ) self.assertEquals(response.status_code, 200) # get statuses list response = self.client.get(path=reverse("api_projects_status"), **self.authentication_headers) self.assertEquals(response.status_code, 200) statuses = json.loads(response.content) fstatus = statuses[0]["id"] # create new task status new_status = {"name": "Open api test", "active": True, "hidden": False, "details": "<p>test details</p>"} response = self.client.post( reverse("api_projects_status"), data=json.dumps(new_status), content_type=self.content_type, **self.authentication_headers ) self.assertEquals(response.status_code, 200) data = json.loads(response.content) self.assertEquals(data["name"], new_status["name"]) self.assertEquals(data["active"], new_status["active"]) self.assertEquals(data["hidden"], new_status["hidden"]) self.assertEquals(data["details"], new_status["details"]) sstatus = data["id"] # create new milestone new_milestone = { "name": "api test milestone", "status": fstatus, "project": project_id, "start_date": "2011-06-09 12:00:00", "details": "<p>test details</p>", } response = self.client.post( reverse("api_projects_milestones"), data=json.dumps(new_milestone), content_type=self.content_type, **self.authentication_headers ) self.assertEquals(response.status_code, 200) data = json.loads(response.content) self.assertEquals(data["name"], new_milestone["name"]) self.assertEquals(data["status"]["id"], new_milestone["status"]) self.assertEquals(data["project"]["id"], new_milestone["project"]) self.assertEquals(data["details"], new_milestone["details"]) milestone_id = data["id"] # create new task new_task = { "name": "api test task", "status": sstatus, "project": project_id, "milestone": milestone_id, "priority": 5, "start_date": "2011-06-02 12:00:00", "estimated_time": 5000, "details": "<p>test details</p>", } response = self.client.post( reverse("api_projects_tasks"), data=json.dumps(new_task), content_type=self.content_type, **self.authentication_headers ) self.assertEquals(response.status_code, 200) data = json.loads(response.content) self.assertEquals(data["name"], new_task["name"]) self.assertEquals(data["priority"], new_task["priority"]) self.assertEquals(data["status"]["id"], new_task["status"]) self.assertEquals(data["project"]["id"], new_task["project"]) self.assertEquals(data["milestone"]["id"], new_task["milestone"]) self.assertEquals(data["estimated_time"], new_task["estimated_time"]) self.assertEquals(data["details"], new_task["details"]) task_id = data["id"] # create new subtask new_sub_task = { "name": "api test task", "status": sstatus, "parent": task_id, "project": project_id, "priority": 5, "start_date": "2011-06-02 13:00:00", "estimated_time": 2500, "details": "<p>test details</p>", } response = self.client.post( reverse("api_projects_tasks"), data=json.dumps(new_sub_task), content_type=self.content_type, **self.authentication_headers ) self.assertEquals(response.status_code, 200) data = json.loads(response.content) self.assertEquals(data["name"], new_sub_task["name"]) self.assertEquals(data["priority"], new_sub_task["priority"]) self.assertEquals(data["status"]["id"], new_sub_task["status"]) self.assertEquals(data["parent"]["id"], new_sub_task["parent"]) self.assertEquals(data["project"]["id"], new_sub_task["project"]) self.assertEquals(data["estimated_time"], new_sub_task["estimated_time"]) self.assertEquals(data["details"], new_sub_task["details"]) sub_task_id = data["id"] # create task time new_tasktime = {"task": task_id, "minutes": 400, "details": "<p>test details</p>"} response = self.client.post( reverse("api_projects_tasktimes"), data=json.dumps(new_tasktime), content_type=self.content_type, **self.authentication_headers ) self.assertEquals(response.status_code, 200) data = json.loads(response.content) self.assertEquals(data["task"]["id"], new_tasktime["task"]) self.assertEquals(data["details"], new_tasktime["details"]) tasktime_id = data["id"] # start task time response = self.client.get( path=reverse("api_projects_tasktime_start", kwargs={"task_id": sub_task_id}), **self.authentication_headers ) self.assertEquals(response.status_code, 200) data = json.loads(response.content) slot_id = data["id"] sleep(60) # stop task time response = self.client.post( reverse("api_projects_tasktime_stop", kwargs={"slot_id": slot_id}), data=json.dumps({"details": "<p>test details</p>"}), content_type=self.content_type, **self.authentication_headers ) self.assertEquals(response.status_code, 200) # delete task time response = self.client.delete( reverse("api_projects_tasktimes", kwargs={"object_ptr": tasktime_id}), **self.authentication_headers ) self.assertEquals(response.status_code, 204) # delete task response = self.client.delete( reverse("api_projects_tasks", kwargs={"object_ptr": task_id}), **self.authentication_headers ) self.assertEquals(response.status_code, 204) # check subtask response = self.client.get( path=reverse("api_projects_tasks", kwargs={"object_ptr": sub_task_id}), **self.authentication_headers ) self.assertEquals(response.status_code, 404) # delete milestone response = self.client.delete( reverse("api_projects_milestones", kwargs={"object_ptr": milestone_id}), **self.authentication_headers ) self.assertEquals(response.status_code, 204) # delete status response = self.client.delete( reverse("api_projects_status", kwargs={"object_ptr": sstatus}), **self.authentication_headers ) self.assertEquals(response.status_code, 204) # delete project response = self.client.delete( reverse("api_projects", kwargs={"object_ptr": project_id}), **self.authentication_headers ) self.assertEquals(response.status_code, 204)
class MessagingViewsTest(TestCase): "Messaging functional tests for views" username = "******" password = "******" prepared = False def setUp(self): "Initial Setup" if not self.prepared: self.group, created = Group.objects.get_or_create(name='test') duser, created = DjangoUser.objects.get_or_create(username=self.username) duser.set_password(self.password) duser.save() self.user, created = User.objects.get_or_create(user=duser) self.user.save() perspective, created = Perspective.objects.get_or_create(name='default') perspective.set_default_user() perspective.save() ModuleSetting.set('default_perspective', perspective.id) self.contact_type = ContactType(name='test') self.contact_type.set_default_user() self.contact_type.save() self.contact = Contact(name='test', contact_type=self.contact_type) self.contact.set_default_user() self.contact.save() self.stream = MessageStream(name='test') self.stream.set_default_user() self.stream.save() self.message = Message(title='test', body='test', author=self.contact, stream=self.stream) self.message.set_default_user() self.message.save() self.client = Client() self.prepared = True ###################################### # Testing views when user is logged in ###################################### def test_message_index_login(self): "Test index page with login at /messaging/" response = self.client.post('/accounts/login', {'username': self.username, 'password': self.password }) self.assertRedirects(response, '/') response = self.client.get(reverse('messaging')) self.assertEquals(response.status_code, 200) def test_message_index_sent(self): "Test index page with login at /messaging/sent/" response = self.client.post('/accounts/login', {'username': self.username, 'password': self.password }) self.assertRedirects(response, '/') response = self.client.get(reverse('messaging_sent')) self.assertEquals(response.status_code, 200) def test_message_index_inbox(self): "Test index page with login at /messaging/inbox/" response = self.client.post('/accounts/login', {'username': self.username, 'password': self.password }) self.assertRedirects(response, '/') response = self.client.get(reverse('messaging_inbox')) self.assertEquals(response.status_code, 200) def test_message_index_unread(self): "Test index page with login at /messaging/unread/" response = self.client.post('/accounts/login', {'username': self.username, 'password': self.password }) self.assertRedirects(response, '/') response = self.client.get(reverse('messaging_unread')) self.assertEquals(response.status_code, 200) # Messages def test_message_compose_login(self): "Test index page with login at /message/compose/" response = self.client.post('/accounts/login', {'username': self.username, 'password': self.password }) self.assertRedirects(response, '/') response = self.client.get(reverse('messaging_message_compose')) self.assertEquals(response.status_code, 200) def test_message_view_login(self): "Test index page with login at /message/view/<message_id>" response = self.client.post('/accounts/login', {'username': self.username, 'password': self.password }) self.assertRedirects(response, '/') response = self.client.get(reverse('messaging_message_view', args=[self.message.id])) self.assertEquals(response.status_code, 200) def test_message_delete_login(self): "Test index page with login at /message/edit/<message_id>" response = self.client.post('/accounts/login', {'username': self.username, 'password': self.password }) self.assertRedirects(response, '/') response = self.client.get(reverse('messaging_message_delete', args=[self.message.id])) self.assertEquals(response.status_code, 200) # Streams def test_stream_add(self): "Test index page with login at /stream/add/" response = self.client.post('/accounts/login', {'username': self.username, 'password': self.password }) self.assertRedirects(response, '/') response = self.client.get(reverse('messaging_stream_edit', args=[self.stream.id])) self.assertEquals(response.status_code, 200) def test_stream_view(self): "Test index page with login at /stream/view/<stream_id>" response = self.client.post('/accounts/login', {'username': self.username, 'password': self.password }) self.assertRedirects(response, '/') response = self.client.get(reverse('messaging_stream_view', args=[self.stream.id])) self.assertEquals(response.status_code, 200) def test_stream_edit(self): "Test index page with login at /stream/edit/<stream_id>" response = self.client.post('/accounts/login', {'username': self.username, 'password': self.password }) self.assertRedirects(response, '/') response = self.client.get(reverse('messaging_stream_edit', args=[self.stream.id])) self.assertEquals(response.status_code, 200) def test_stream_delete(self): "Test index page with login at /stream/delete/<stream_id>" response = self.client.post('/accounts/login', {'username': self.username, 'password': self.password }) self.assertRedirects(response, '/') response = self.client.get(reverse('messaging_stream_delete', args=[self.stream.id])) self.assertEquals(response.status_code, 200) # Settings def test_messaging_settings_view(self): "Test index page with login at /messaging/settings/view/" response = self.client.post('/accounts/login', {'username': self.username, 'password': self.password }) self.assertRedirects(response, '/') response = self.client.get(reverse('messaging_settings_view')) self.assertEquals(response.status_code, 200) def test_finance_settings_edit(self): "Test index page with login at /messaging/settings/edit/" response = self.client.post('/accounts/login', {'username': self.username, 'password': self.password }) self.assertRedirects(response, '/') response = self.client.get(reverse('messaging_settings_edit')) self.assertEquals(response.status_code, 200) ###################################### # Testing views when user is not logged in ###################################### def test_message_index_out(self): "Test index page at /messaging/" response = self.client.get(reverse('messaging')) # Redirects as unauthenticated self.assertRedirects(response, reverse('user_login')) def test_message_sent_out(self): "Testing /messaging/sent/" response = self.client.get(reverse('messaging_sent')) # Redirects as unauthenticated self.assertRedirects(response, reverse('user_login')) def test_message_inbox_out(self): "Testing /messaging/inbox/" response = self.client.get(reverse('messaging_inbox')) # Redirects as unauthenticated self.assertRedirects(response, reverse('user_login')) def test_message_unread_out(self): "Testing /messaging/unread/" response = self.client.get(reverse('messaging_unread')) # Redirects as unauthenticated self.assertRedirects(response, reverse('user_login')) # Messages def test_message_compose_out(self): "Testing /message/compose/" response = self.client.get(reverse('messaging_message_compose')) self.assertRedirects(response, reverse('user_login')) def test_message_view_out(self): "Test index page with login at /message/view/<message_id>" response = self.client.get(reverse('messaging_message_view', args=[self.message.id])) self.assertRedirects(response, reverse('user_login')) def test_message_delete_out(self): "Test index page with login at /message/edit/<message_id>" response = self.client.get(reverse('messaging_message_delete', args=[self.message.id])) self.assertRedirects(response, reverse('user_login')) # Streams def test_stream_add_out(self): "Testing /stream/add/" response = self.client.get(reverse('messaging_stream_edit', args=[self.stream.id])) self.assertRedirects(response, reverse('user_login')) def test_stream_view_out(self): "Testing /stream/view/<stream_id>" response = self.client.get(reverse('messaging_stream_view', args=[self.stream.id])) self.assertRedirects(response, reverse('user_login')) def test_stream_edit_out(self): "Testing /stream/edit/<stream_id>" response = self.client.get(reverse('messaging_stream_edit', args=[self.stream.id])) self.assertRedirects(response, reverse('user_login')) def test_stream_delete_out(self): "Testing /stream/delete/<stream_id>" response = self.client.get(reverse('messaging_stream_delete', args=[self.stream.id])) self.assertRedirects(response, reverse('user_login')) # Settings def test_messaging_settings_view_out(self): "Testing /messaging/settings/view/" response = self.client.get(reverse('messaging_settings_view')) self.assertRedirects(response, reverse('user_login')) def test_finance_settings_edit_out(self): "Testing /messaging/settings/edit/" response = self.client.get(reverse('messaging_settings_edit')) self.assertRedirects(response, reverse('user_login'))
class FinanceViewsTest(TestCase): "Finance functional tests for views" username = "******" password = "******" prepared = False def setUp(self): "Initial Setup" if not self.prepared: # Clean up first Object.objects.all().delete() User.objects.all().delete() # Create objects self.group, created = Group.objects.get_or_create(name='test') duser, created = DjangoUser.objects.get_or_create(username=self.username) duser.set_password(self.password) duser.save() self.user, created = User.objects.get_or_create(user=duser) self.user.save() perspective, created = Perspective.objects.get_or_create(name='default') perspective.set_default_user() perspective.save() ModuleSetting.set('default_perspective', perspective.id) self.contact_type = ContactType(name='test') self.contact_type.set_default_user() self.contact_type.save() self.contact = Contact(name='test', contact_type=self.contact_type) self.contact.set_default_user() self.contact.save() self.category = Category(name='test') self.category.set_default_user() self.category.save() self.equity = Equity(issue_price=10, sell_price=10, issuer=self.contact, owner=self.contact) self.equity.set_default_user() self.equity.save() self.asset = Asset(name='test', owner=self.contact) self.asset.set_default_user() self.asset.save() self.tax = Tax(name='test', rate=10) self.tax.set_default_user() self.tax.save() self.currency = Currency(code="GBP", name="Pounds", symbol="L", is_default=True) self.currency.set_default_user() self.currency.save() self.account = Account(name='test', owner=self.contact, balance_currency=self.currency) self.account.set_default_user() self.account.save() self.liability = Liability(name='test', source=self.contact, target=self.contact, account=self.account, value=10, value_currency=self.currency) self.liability.set_default_user() self.liability.save() self.transaction = Transaction(name='test', account=self.account, source=self.contact, target=self.contact, value=10, value_currency=self.currency) self.transaction.set_default_user() self.transaction.save() self.client = Client() self.prepared = True ###################################### # Testing views when user is logged in ###################################### def test_finance_login(self): "Test index page with login at /finance/" response = self.client.post('/accounts/login', {'username': self.username, 'password': self.password }) self.assertRedirects(response, '/') response = self.client.get(reverse('finance')) self.assertEquals(response.status_code, 200) def test_finance_index_login(self): "Test index page with login at /finance/index/" response = self.client.post('/accounts/login', {'username': self.username, 'password': self.password }) self.assertRedirects(response, '/') response = self.client.get(reverse('finance_index_transactions')) self.assertEquals(response.status_code, 200) def test_finance_income(self): "Test index page with login at /finance/income/" response = self.client.post('/accounts/login', {'username': self.username, 'password': self.password }) self.assertRedirects(response, '/') response = self.client.get(reverse('finance_income_view')) self.assertEquals(response.status_code, 200) def test_finance_balance(self): "Test index page with login at /finance/balance/" response = self.client.post('/accounts/login', {'username': self.username, 'password': self.password }) self.assertRedirects(response, '/') response = self.client.get(reverse('finance_balance_sheet')) self.assertEquals(response.status_code, 200) # Account def test_finance_accounts_index(self): "Test index page with login at /finance/accounts/" response = self.client.post('/accounts/login', {'username': self.username, 'password': self.password }) self.assertRedirects(response, '/') response = self.client.get(reverse('finance_index_accounts')) self.assertEquals(response.status_code, 200) def test_finance_account_add(self): "Test index page with login at /finance/account/add/" response = self.client.post('/accounts/login', {'username': self.username, 'password': self.password }) self.assertRedirects(response, '/') response = self.client.get(reverse('finance_account_add')) self.assertEquals(response.status_code, 200) def test_finance_account_edit(self): "Test index page with login at /finance/account/edit/<account_id>" response = self.client.post('/accounts/login', {'username': self.username, 'password': self.password }) self.assertRedirects(response, '/') response = self.client.get(reverse('finance_account_edit', args=[self.account.id])) self.assertEquals(response.status_code, 200) def test_finance_account_view(self): "Test index page with login at /finance/account/view/<account_id>" response = self.client.post('/accounts/login', {'username': self.username, 'password': self.password }) self.assertRedirects(response, '/') response = self.client.get(reverse('finance_account_view', args=[self.account.id])) self.assertEquals(response.status_code, 200) def test_finance_account_delete(self): "Test index page with login at /finance/account/delete/<account_id>" response = self.client.post('/accounts/login', {'username': self.username, 'password': self.password }) self.assertRedirects(response, '/') response = self.client.get(reverse('finance_account_delete', args=[self.account.id])) self.assertEquals(response.status_code, 200) # Asset def test_finance_assets_index(self): "Test index page with login at /finance/assets/" response = self.client.post('/accounts/login', {'username': self.username, 'password': self.password }) self.assertRedirects(response, '/') response = self.client.get(reverse('finance_index_assets')) self.assertEquals(response.status_code, 200) def test_finance_asset_add(self): "Test index page with login at /finance/asset/add/" response = self.client.post('/accounts/login', {'username': self.username, 'password': self.password }) self.assertRedirects(response, '/') response = self.client.get(reverse('finance_asset_add')) self.assertEquals(response.status_code, 200) def test_finance_asset_edit(self): "Test index page with login at /finance/asset/edit/<asset_id>" response = self.client.post('/accounts/login', {'username': self.username, 'password': self.password }) self.assertRedirects(response, '/') response = self.client.get(reverse('finance_asset_edit', args=[self.asset.id])) self.assertEquals(response.status_code, 200) def test_finance_asset_view(self): "Test index page with login at /finance/asset/view/<asset_id>" response = self.client.post('/accounts/login', {'username': self.username, 'password': self.password }) self.assertRedirects(response, '/') response = self.client.get(reverse('finance_asset_view', args=[self.asset.id])) self.assertEquals(response.status_code, 200) def test_finance_asset_delete(self): "Test index page with login at /finance/asset/delete/<asset_id>" response = self.client.post('/accounts/login', {'username': self.username, 'password': self.password }) self.assertRedirects(response, '/') response = self.client.get(reverse('finance_asset_delete', args=[self.asset.id])) self.assertEquals(response.status_code, 200) # Equity def test_finance_equity_index(self): "Test index page with login at /finance/equity/" response = self.client.post('/accounts/login', {'username': self.username, 'password': self.password }) self.assertRedirects(response, '/') response = self.client.get(reverse('finance_index_equities')) self.assertEquals(response.status_code, 200) def test_finance_equity_add(self): "Test index page with login at /finance/equity/add/" response = self.client.post('/accounts/login', {'username': self.username, 'password': self.password }) self.assertRedirects(response, '/') response = self.client.get(reverse('finance_equity_add')) self.assertEquals(response.status_code, 200) def test_finance_equity_edit(self): "Test index page with login at /finance/equity/edit/<equity_id>" response = self.client.post('/accounts/login', {'username': self.username, 'password': self.password }) self.assertRedirects(response, '/') response = self.client.get(reverse('finance_equity_edit', args=[self.equity.id])) self.assertEquals(response.status_code, 200) def test_finance_equity_view(self): "Test index page with login at /finance/equity/view/<equity_id>" response = self.client.post('/accounts/login', {'username': self.username, 'password': self.password }) self.assertRedirects(response, '/') response = self.client.get(reverse('finance_equity_view', args=[self.equity.id])) self.assertEquals(response.status_code, 200) def test_finance_equity_delete(self): "Test index page with login at /finance/equity/delete/<equity_id>" response = self.client.post('/accounts/login', {'username': self.username, 'password': self.password }) self.assertRedirects(response, '/') response = self.client.get(reverse('finance_equity_delete', args=[self.equity.id])) self.assertEquals(response.status_code, 200) # Transaction def test_finance_transactions_index(self): "Test index page with login at /finance/transaction/" response = self.client.post('/accounts/login', {'username': self.username, 'password': self.password }) self.assertRedirects(response, '/') response = self.client.get(reverse('finance_index_transactions')) self.assertEquals(response.status_code, 200) def test_finance_transaction_add(self): "Test index page with login at /finance/transaction/add/" response = self.client.post('/accounts/login', {'username': self.username, 'password': self.password }) self.assertRedirects(response, '/') response = self.client.get(reverse('finance_transaction_add')) self.assertEquals(response.status_code, 200) def test_finance_transaction_add_liability(self): "Test index page with login at /finance/transaction/add/liability/(?P<liability_id>\d+)" response = self.client.post('/accounts/login', {'username': self.username, 'password': self.password }) self.assertRedirects(response, '/') response = self.client.get(reverse('finance_transaction_add', args=[self.liability.id])) self.assertEquals(response.status_code, 200) def test_finance_transaction_edit(self): "Test index page with login at /finance/transaction/edit/<transaction_id>" response = self.client.post('/accounts/login', {'username': self.username, 'password': self.password }) self.assertRedirects(response, '/') response = self.client.get(reverse('finance_transaction_edit', args=[self.transaction.id])) self.assertEquals(response.status_code, 200) def test_finance_transaction_view(self): "Test index page with login at /finance/transaction/view/<transaction_id>" response = self.client.post('/accounts/login', {'username': self.username, 'password': self.password }) self.assertRedirects(response, '/') response = self.client.get(reverse('finance_transaction_view', args=[self.transaction.id])) self.assertEquals(response.status_code, 200) def test_finance_transaction_delete(self): "Test index page with login at /finance/transaction/delete/<transaction_id>" response = self.client.post('/accounts/login', {'username': self.username, 'password': self.password }) self.assertRedirects(response, '/') response = self.client.get(reverse('finance_transaction_delete', args=[self.transaction.id])) self.assertEquals(response.status_code, 200) # Liability def test_finance_liability_index(self): "Test index page with login at /finance/liability/" response = self.client.post('/accounts/login', {'username': self.username, 'password': self.password }) self.assertRedirects(response, '/') response = self.client.get(reverse('finance_index_liabilities')) self.assertEquals(response.status_code, 200) def test_finance_liability_add(self): "Test index page with login at /finance/liability/add/" response = self.client.post('/accounts/login', {'username': self.username, 'password': self.password }) self.assertRedirects(response, '/') response = self.client.get(reverse('finance_liability_add')) self.assertEquals(response.status_code, 200) def test_finance_liability_edit(self): "Test index page with login at /finance/liability/edit/<liability_id>" response = self.client.post('/accounts/login', {'username': self.username, 'password': self.password }) self.assertRedirects(response, '/') response = self.client.get(reverse('finance_liability_edit', args=[self.liability.id])) self.assertEquals(response.status_code, 200) def test_finance_liability_view(self): "Test index page with login at /finance/liability/view/<liability_id>" response = self.client.post('/accounts/login', {'username': self.username, 'password': self.password }) self.assertRedirects(response, '/') response = self.client.get(reverse('finance_liability_view', args=[self.liability.id])) self.assertEquals(response.status_code, 200) def test_finance_liability_delete(self): "Test index page with login at /finance/liability/delete/<liability_id>" response = self.client.post('/accounts/login', {'username': self.username, 'password': self.password }) self.assertRedirects(response, '/') response = self.client.get(reverse('finance_liability_delete', args=[self.liability.id])) self.assertEquals(response.status_code, 200) # Receivables def test_finance_receivables_index(self): "Test index page with login at /finance/receivables/" response = self.client.post('/accounts/login', {'username': self.username, 'password': self.password }) self.assertRedirects(response, '/') response = self.client.get(reverse('finance_index_receivables')) self.assertEquals(response.status_code, 200) def test_finance_receivable_add(self): "Test index page with login at /finance/receivable/add/" response = self.client.post('/accounts/login', {'username': self.username, 'password': self.password }) self.assertRedirects(response, '/') response = self.client.get(reverse('finance_receivable_add')) self.assertEquals(response.status_code, 200) def test_finance_receivable_edit(self): "Test index page with login at /finance/receivable/edit/<receivable_id>" response = self.client.post('/accounts/login', {'username': self.username, 'password': self.password }) self.assertRedirects(response, '/') response = self.client.get(reverse('finance_receivable_edit', args=[self.liability.id])) self.assertEquals(response.status_code, 200) def test_finance_receivable_view(self): "Test index page with login at /finance/receivable/view/<receivable_id>" response = self.client.post('/accounts/login', {'username': self.username, 'password': self.password }) self.assertRedirects(response, '/') response = self.client.get(reverse('finance_receivable_view', args=[self.liability.id])) self.assertEquals(response.status_code, 200) def test_finance_receivable_delete(self): "Test index page with login at /finance/liability/delete/<receivable_id>" response = self.client.post('/accounts/login', {'username': self.username, 'password': self.password }) self.assertRedirects(response, '/') response = self.client.get(reverse('finance_receivable_delete', args=[self.liability.id])) self.assertEquals(response.status_code, 200) # Category def test_finance_category_add(self): "Test index page with login at /finance/category/add/" response = self.client.post('/accounts/login', {'username': self.username, 'password': self.password }) self.assertRedirects(response, '/') response = self.client.get(reverse('finance_category_add')) self.assertEquals(response.status_code, 200) def test_finance_category_edit(self): "Test index page with login at /finance/category/edit/<category_id>" response = self.client.post('/accounts/login', {'username': self.username, 'password': self.password }) self.assertRedirects(response, '/') response = self.client.get(reverse('finance_category_edit', args=[self.category.id])) self.assertEquals(response.status_code, 200) def test_finance_category_view(self): "Test index page with login at /finance/category/view/<category_id>" response = self.client.post('/accounts/login', {'username': self.username, 'password': self.password }) self.assertRedirects(response, '/') response = self.client.get(reverse('finance_category_view', args=[self.category.id])) self.assertEquals(response.status_code, 200) def test_finance_category_delete(self): "Test index page with login at /finance/category/delete/<category_id>" response = self.client.post('/accounts/login', {'username': self.username, 'password': self.password }) self.assertRedirects(response, '/') response = self.client.get(reverse('finance_category_delete', args=[self.category.id])) self.assertEquals(response.status_code, 200) # Currency def test_finance_currency_add(self): "Test index page with login at /finance/currency/add/" response = self.client.post('/accounts/login', {'username': self.username, 'password': self.password }) self.assertRedirects(response, '/') response = self.client.get(reverse('finance_currency_add')) self.assertEquals(response.status_code, 200) def test_finance_currency_edit(self): "Test index page with login at /finance/currency/edit/<currency_id>" response = self.client.post('/accounts/login', {'username': self.username, 'password': self.password }) self.assertRedirects(response, '/') response = self.client.get(reverse('finance_currency_edit', args=[self.currency.id])) self.assertEquals(response.status_code, 200) def test_finance_currency_view(self): "Test index page with login at /finance/currency/view/<currency_id>" response = self.client.post('/accounts/login', {'username': self.username, 'password': self.password }) self.assertRedirects(response, '/') response = self.client.get(reverse('finance_currency_view', args=[self.currency.id])) self.assertEquals(response.status_code, 200) def test_finance_currency_delete(self): "Test index page with login at /finance/currency/delete/<currency_id>" response = self.client.post('/accounts/login', {'username': self.username, 'password': self.password }) self.assertRedirects(response, '/') response = self.client.get(reverse('finance_currency_delete', args=[self.currency.id])) self.assertEquals(response.status_code, 200) # Taxes def test_finance_tax_add(self): "Test index page with login at /finance/tax/add/" response = self.client.post('/accounts/login', {'username': self.username, 'password': self.password }) self.assertRedirects(response, '/') response = self.client.get(reverse('finance_tax_add')) self.assertEquals(response.status_code, 200) def test_finance_tax_edit(self): "Test index page with login at /finance/tax/edit/<tax_id>" response = self.client.post('/accounts/login', {'username': self.username, 'password': self.password }) self.assertRedirects(response, '/') response = self.client.get(reverse('finance_tax_edit', args=[self.tax.id])) self.assertEquals(response.status_code, 200) def test_finance_tax_view(self): "Test index page with login at /finance/tax/view/<tax_id>" response = self.client.post('/accounts/login', {'username': self.username, 'password': self.password }) self.assertRedirects(response, '/') response = self.client.get(reverse('finance_tax_view', args=[self.tax.id])) self.assertEquals(response.status_code, 200) def test_finance_tax_delete(self): "Test index page with login at /finance/tax/delete/<tax_id>" response = self.client.post('/accounts/login', {'username': self.username, 'password': self.password }) self.assertRedirects(response, '/') response = self.client.get(reverse('finance_tax_delete', args=[self.tax.id])) self.assertEquals(response.status_code, 200) # Settings def test_finance_settings_view(self): "Test index page with login at /finance/settings/view/" response = self.client.post('/accounts/login', {'username': self.username, 'password': self.password }) self.assertRedirects(response, '/') response = self.client.get(reverse('finance_settings_view')) self.assertEquals(response.status_code, 200) def test_finance_settings_edit(self): "Test index page with login at /finance/settings/edit/" response = self.client.post('/accounts/login', {'username': self.username, 'password': self.password }) self.assertRedirects(response, '/') response = self.client.get(reverse('finance_settings_edit')) self.assertEquals(response.status_code, 200) ###################################### # Testing views when user is not logged in ###################################### def test_index(self): "Test index page at /finance/" response = self.client.get('/finance/') # Redirects as unauthenticated self.assertRedirects(response, reverse('user_login')) def test_finance_index_out(self): "Testing /finance/index/" response = self.client.get(reverse('finance_index_transactions')) self.assertRedirects(response, reverse('user_login')) def test_finance_income_out(self): "Testing /finance/income/" response = self.client.get(reverse('finance_income_view')) self.assertRedirects(response, reverse('user_login')) def test_finance_balance_out(self): "Testing /finance/balance/" response = self.client.get(reverse('finance_balance_sheet')) self.assertRedirects(response, reverse('user_login')) # Account def test_finance_accounts_index_out(self): "Testing /finance/accounts/" response = self.client.get(reverse('finance_index_accounts')) self.assertRedirects(response, reverse('user_login')) def test_finance_account_add_out(self): "Testing /finance/account/add/" response = self.client.get(reverse('finance_account_add')) self.assertRedirects(response, reverse('user_login')) def test_finance_account_edit_out(self): "Testing /finance/account/edit/<account_id>" response = self.client.get(reverse('finance_account_edit', args=[self.account.id])) self.assertRedirects(response, reverse('user_login')) def test_finance_account_view_out(self): "Testing /finance/account/view/<account_id>" response = self.client.get(reverse('finance_account_view', args=[self.account.id])) self.assertRedirects(response, reverse('user_login')) def test_finance_account_delete_out(self): "Testing /finance/account/delete/<account_id>" response = self.client.get(reverse('finance_account_delete', args=[self.account.id])) self.assertRedirects(response, reverse('user_login')) # Asset def test_finance_assets_index_out(self): "Testing /finance/assets/" response = self.client.get(reverse('finance_index_assets')) self.assertRedirects(response, reverse('user_login')) def test_finance_asset_add_out(self): "Testing /finance/asset/add/" response = self.client.get(reverse('finance_asset_add')) self.assertRedirects(response, reverse('user_login')) def test_finance_asset_edit_out(self): "Testing /finance/asset/edit/<asset_id>" response = self.client.get(reverse('finance_asset_edit', args=[self.asset.id])) self.assertRedirects(response, reverse('user_login')) def test_finance_asset_view_out(self): "Testing /finance/asset/view/<asset_id>" response = self.client.get(reverse('finance_asset_view', args=[self.asset.id])) self.assertRedirects(response, reverse('user_login')) def test_finance_asset_delete_out(self): "Testing /finance/asset/delete/<asset_id>" response = self.client.get(reverse('finance_asset_delete', args=[self.asset.id])) self.assertRedirects(response, reverse('user_login')) # Equity def test_finance_equity_index_out(self): "Testing /finance/equity/" response = self.client.get(reverse('finance_index_equities')) self.assertRedirects(response, reverse('user_login')) def test_finance_equity_add_out(self): "Testing /finance/equity/add/" response = self.client.get(reverse('finance_equity_add')) self.assertRedirects(response, reverse('user_login')) def test_finance_equity_edit_out(self): "Tesing /finance/equity/edit/<equity_id>" response = self.client.get(reverse('finance_equity_edit', args=[self.equity.id])) self.assertRedirects(response, reverse('user_login')) def test_finance_equity_view_out(self): "Testing /finance/equity/view/<equity_id>" response = self.client.get(reverse('finance_equity_view', args=[self.equity.id])) self.assertRedirects(response, reverse('user_login')) def test_finance_equity_delete_out(self): "Testing /finance/equity/delete/<equity_id>" response = self.client.get(reverse('finance_equity_delete', args=[self.equity.id])) self.assertRedirects(response, reverse('user_login')) # Transaction def test_finance_transactions_index_out(self): "Testing /finance/transaction/" response = self.client.get(reverse('finance_index_transactions')) self.assertRedirects(response, reverse('user_login')) def test_finance_transaction_add_out(self): "Testing /finance/transaction/add/" response = self.client.get(reverse('finance_transaction_add')) self.assertRedirects(response, reverse('user_login')) def test_finance_transaction_add_liability_out(self): "Testing /finance/transaction/add/liability/(?P<liability_id>\d+)" response = self.client.get(reverse('finance_transaction_add', args=[self.liability.id])) self.assertRedirects(response, reverse('user_login')) def test_finance_transaction_edit_out(self): "Testing /finance/transaction/edit/<transaction_id>" response = self.client.get(reverse('finance_transaction_edit', args=[self.transaction.id])) self.assertRedirects(response, reverse('user_login')) def test_finance_transaction_view_out(self): "Testing /finance/transaction/view/<transaction_id>" response = self.client.get(reverse('finance_transaction_view', args=[self.transaction.id])) self.assertRedirects(response, reverse('user_login')) def test_finance_transaction_delete_out(self): "Testing /finance/transaction/delete/<transaction_id>" response = self.client.get(reverse('finance_transaction_delete', args=[self.transaction.id])) self.assertRedirects(response, reverse('user_login')) # Liability def test_finance_liability_index_out(self): "Testing /finance/liability/" response = self.client.get(reverse('finance_index_liabilities')) self.assertRedirects(response, reverse('user_login')) def test_finance_liability_add_out(self): "Testing /finance/liability/add/" response = self.client.get(reverse('finance_liability_add')) self.assertRedirects(response, reverse('user_login')) def test_finance_liability_edit_out(self): "Testing /finance/liability/edit/<liability_id>" response = self.client.get(reverse('finance_liability_edit', args=[self.liability.id])) self.assertRedirects(response, reverse('user_login')) def test_finance_liability_view_out(self): "Testing /finance/liability/view/<liability_id>" response = self.client.get(reverse('finance_liability_view', args=[self.liability.id])) self.assertRedirects(response, reverse('user_login')) def test_finance_liability_delete_out(self): "Testing /finance/liability/delete/<liability_id>" response = self.client.get(reverse('finance_liability_delete', args=[self.liability.id])) self.assertRedirects(response, reverse('user_login')) # Receivables def test_finance_receivables_index_out(self): "Testing /finance/receivables/" response = self.client.get(reverse('finance_index_receivables')) self.assertRedirects(response, reverse('user_login')) def test_finance_receivable_add_out(self): "Testing /finance/receivable/add/" response = self.client.get(reverse('finance_receivable_add')) self.assertRedirects(response, reverse('user_login')) def test_finance_receivable_edit_out(self): "Testing /finance/receivable/edit/<receivable_id>" response = self.client.get(reverse('finance_receivable_edit', args=[self.liability.id])) self.assertRedirects(response, reverse('user_login')) def test_finance_receivable_view_out(self): "Testing /finance/receivable/view/<receivable_id>" response = self.client.get(reverse('finance_receivable_view', args=[self.liability.id])) self.assertRedirects(response, reverse('user_login')) def test_finance_receivable_delete_out(self): "Testing /finance/liability/delete/<receivable_id>" response = self.client.get(reverse('finance_receivable_delete', args=[self.liability.id])) self.assertRedirects(response, reverse('user_login')) # Category def test_finance_category_add_out(self): "Testing /finance/category/add/" response = self.client.get(reverse('finance_category_add')) self.assertRedirects(response, reverse('user_login')) def test_finance_category_edit_out(self): "Testing /finance/category/edit/<category_id>" response = self.client.get(reverse('finance_category_edit', args=[self.category.id])) self.assertRedirects(response, reverse('user_login')) def test_finance_category_view_out(self): "Testing /finance/category/view/<category_id>" response = self.client.get(reverse('finance_category_view', args=[self.category.id])) self.assertRedirects(response, reverse('user_login')) def test_finance_category_delete_out(self): "Testing /finance/category/delete/<category_id>" response = self.client.get(reverse('finance_category_delete', args=[self.category.id])) self.assertRedirects(response, reverse('user_login')) # Currency def test_finance_currency_add_out(self): "Testing /finance/currency/add/" response = self.client.get(reverse('finance_currency_add')) self.assertRedirects(response, reverse('user_login')) def test_finance_currency_edit_out(self): "Testing /finance/currency/edit/<currency_id>" response = self.client.get(reverse('finance_currency_edit', args=[self.currency.id])) self.assertRedirects(response, reverse('user_login')) def test_finance_currency_view_out(self): "Testing /finance/currency/view/<currency_id>" response = self.client.get(reverse('finance_currency_view', args=[self.currency.id])) self.assertRedirects(response, reverse('user_login')) def test_finance_currency_delete_out(self): "Testing /finance/currency/delete/<currency_id>" response = self.client.get(reverse('finance_currency_delete', args=[self.currency.id])) self.assertRedirects(response, reverse('user_login')) # Taxes def test_finance_tax_add_out(self): "Testing /finance/tax/add/" response = self.client.get(reverse('finance_tax_add')) self.assertRedirects(response, reverse('user_login')) def test_finance_tax_edit_out(self): "Testing /finance/tax/edit/<tax_id>" response = self.client.get(reverse('finance_tax_edit', args=[self.tax.id])) self.assertRedirects(response, reverse('user_login')) def test_finance_tax_view_out(self): "Testing /finance/tax/view/<tax_id>" response = self.client.get(reverse('finance_tax_view', args=[self.tax.id])) self.assertRedirects(response, reverse('user_login')) def test_finance_tax_delete_out(self): "Testing /finance/tax/delete/<tax_id>" response = self.client.get(reverse('finance_tax_delete', args=[self.tax.id])) self.assertRedirects(response, reverse('user_login')) # Settings def test_finance_settings_view_out(self): "Testing /finance/settings/view/" response = self.client.get(reverse('finance_settings_view')) self.assertRedirects(response, reverse('user_login')) def test_finance_settings_edit_out(self): "Testing /finance/settings/edit/" response = self.client.get(reverse('finance_settings_edit')) self.assertRedirects(response, reverse('user_login'))
class SalesViewsTest(TestCase): "Sales functional tests for views" username = "******" password = "******" prepared = False def setUp(self): "Initial Setup" if not self.prepared: self.group, created = Group.objects.get_or_create(name='test') duser, created = DjangoUser.objects.get_or_create(username=self.username) duser.set_password(self.password) duser.save() self.user, created = User.objects.get_or_create(user=duser) self.user.save() perspective, created = Perspective.objects.get_or_create(name='default') perspective.set_default_user() perspective.save() ModuleSetting.set('default_perspective', perspective.id) self.contact_type = ContactType() self.contact_type.slug = 'machine' self.contact_type.name = 'machine' self.contact_type.save() self.contact = Contact() self.contact.contact_type = self.contact_type self.contact.set_default_user() self.contact.save() self.assertNotEquals(self.contact.id, None) self.status = SaleStatus() self.status.set_default_user() self.status.save() self.assertNotEquals(self.status.id, None) self.currency = Currency(code="GBP", name="Pounds", symbol="L", is_default=True) self.currency.save() self.source = SaleSource() self.source.set_default_user() self.source.save() self.assertNotEquals(self.source.id, None) self.product = Product(name="Test") self.product.product_type = 'service' self.product.active = True self.product.sell_price = 10 self.product.buy_price = 100 self.product.set_default_user() self.product.save() self.assertNotEquals(self.product.id, None) self.subscription = Subscription() self.subscription.client = self.contact self.subscription.set_default_user() self.subscription.save() self.assertNotEquals(self.subscription.id, None) self.lead = Lead() self.lead.contact_method = 'email' self.lead.status = self.status self.lead.contact = self.contact self.lead.set_default_user() self.lead.save() self.assertNotEquals(self.lead.id, None) self.opportunity = Opportunity() self.opportunity.lead = self.lead self.opportunity.contact = self.contact self.opportunity.status = self.status self.opportunity.amount = 100 self.opportunity.amount_currency = self.currency self.opportunity.amount_display = 120 self.opportunity.set_default_user() self.opportunity.save() self.assertNotEquals(self.opportunity.id, None) self.order = SaleOrder(reference="Test") self.order.opportunity = self.opportunity self.order.status = self.status self.order.source = self.source self.order.currency = self.currency self.order.total = 0 self.order.total_display = 0 self.order.set_default_user() self.order.save() self.assertNotEquals(self.order.id, None) self.ordered_product = OrderedProduct() self.ordered_product.product = self.product self.ordered_product.order = self.order self.ordered_product.rate = 0 self.ordered_product.subscription = self.subscription self.ordered_product.set_default_user() self.ordered_product.save() self.assertNotEquals(self.ordered_product.id, None) self.client = Client() self.prepared = True ###################################### # Testing views when user is logged in ###################################### def test_index(self): "Test page with login at /sales/index" response = self.client.post('/accounts/login', {'username': self.username, 'password': self.password }) self.assertRedirects(response, '/') response = self.client.get(reverse('sales_index')) self.assertEquals(response.status_code, 200) def test_index_open(self): "Test page with login at /sales/open" response = self.client.post('/accounts/login', {'username': self.username, 'password': self.password }) self.assertRedirects(response, '/') response = self.client.get(reverse('sales_index_open')) self.assertEquals(response.status_code, 200) def test_index_assigned(self): "Test page with login at /sales/index/assigned" response = self.client.post('/accounts/login', {'username': self.username, 'password': self.password }) self.assertRedirects(response, '/') response = self.client.get(reverse('sales_index_assigned')) self.assertEquals(response.status_code, 200) # Orders def test_order_add(self): "Test page with login at /sales/order/add" response = self.client.post('/accounts/login', {'username': self.username, 'password': self.password }) self.assertRedirects(response, '/') response = self.client.get(reverse('sales_order_add')) self.assertEquals(response.status_code, 200) def test_order_add_lead(self): "Test page with login at /sales/order/add/lead/" response = self.client.post('/accounts/login', {'username': self.username, 'password': self.password }) self.assertRedirects(response, '/') response = self.client.get(reverse('sales_order_add_with_lead', args=[self.lead.id])) self.assertEquals(response.status_code, 200) def test_order_add_opportunity(self): "Test page with login at /sales/order/add/opportunity/" response = self.client.post('/accounts/login', {'username': self.username, 'password': self.password }) self.assertRedirects(response, '/') response = self.client.get(reverse('sales_order_add_with_opportunity', args=[self.opportunity.id])) self.assertEquals(response.status_code, 200) def test_order_edit(self): "Test page with login at /sales/order/edit/" response = self.client.post('/accounts/login', {'username': self.username, 'password': self.password }) self.assertRedirects(response, '/') response = self.client.get(reverse('sales_order_edit', args=[self.order.id])) self.assertEquals(response.status_code, 200) def test_order_view(self): "Test page with login at /sales/order/view/" response = self.client.post('/accounts/login', {'username': self.username, 'password': self.password }) self.assertRedirects(response, '/') response = self.client.get(reverse('sales_order_view', args=[self.order.id])) self.assertEquals(response.status_code, 200) def test_order_delete(self): "Test page with login at /sales/order/delete/" response = self.client.post('/accounts/login', {'username': self.username, 'password': self.password }) self.assertRedirects(response, '/') response = self.client.get(reverse('sales_order_delete', args=[self.order.id])) self.assertEquals(response.status_code, 200) def test_order_invoice_view(self): "Test page with login at /sales/order/invoice/" response = self.client.post('/accounts/login', {'username': self.username, 'password': self.password }) self.assertRedirects(response, '/') response = self.client.get(reverse('sales_order_invoice_view', args=[self.order.id])) self.assertEquals(response.status_code, 200) # Products def test_product_index(self): "Test page with login at /sales/product/index" response = self.client.post('/accounts/login', {'username': self.username, 'password': self.password }) self.assertRedirects(response, '/') response = self.client.get(reverse('sales_product_index')) self.assertEquals(response.status_code, 200) def test_product_add(self): "Test page with login at /sales/product/add/" response = self.client.post('/accounts/login', {'username': self.username, 'password': self.password }) self.assertRedirects(response, '/') response = self.client.get(reverse('sales_product_add')) self.assertEquals(response.status_code, 200) def test_product_add_parent(self): "Test page with login at /sales/product/add" response = self.client.post('/accounts/login', {'username': self.username, 'password': self.password }) self.assertRedirects(response, '/') response = self.client.get(reverse('sales_product_add', args=[self.product.id])) self.assertEquals(response.status_code, 200) def test_product_edit(self): "Test page with login at /sales/product/edit/" response = self.client.post('/accounts/login', {'username': self.username, 'password': self.password }) self.assertRedirects(response, '/') response = self.client.get(reverse('sales_product_edit', args=[self.product.id])) self.assertEquals(response.status_code, 200) def test_product_view(self): "Test page with login at /sales/product/view/" response = self.client.post('/accounts/login', {'username': self.username, 'password': self.password }) self.assertRedirects(response, '/') response = self.client.get(reverse('sales_product_view', args=[self.product.id])) self.assertEquals(response.status_code, 200) def test_product_delete(self): "Test page with login at /sales/product/delete/" response = self.client.post('/accounts/login', {'username': self.username, 'password': self.password }) self.assertRedirects(response, '/') response = self.client.get(reverse('sales_product_delete', args=[self.product.id])) self.assertEquals(response.status_code, 200) # Settings def test_settings_view(self): "Test page with login at /sales/settings/view" response = self.client.post('/accounts/login', {'username': self.username, 'password': self.password }) self.assertRedirects(response, '/') response = self.client.get(reverse('sales_settings_view')) self.assertEquals(response.status_code, 200) def test_settings_edit(self): "Test page with login at /sales/settings/edit" response = self.client.post('/accounts/login', {'username': self.username, 'password': self.password }) self.assertRedirects(response, '/') response = self.client.get(reverse('sales_settings_edit')) self.assertEquals(response.status_code, 200) # Statuses def test_status_add(self): "Test page with login at /sales/status/add" response = self.client.post('/accounts/login', {'username': self.username, 'password': self.password }) self.assertRedirects(response, '/') response = self.client.get(reverse('sales_status_add')) self.assertEquals(response.status_code, 200) def test_status_edit(self): "Test page with login at /sales/status/edit/" response = self.client.post('/accounts/login', {'username': self.username, 'password': self.password }) self.assertRedirects(response, '/') response = self.client.get(reverse('sales_status_edit', args=[self.status.id])) self.assertEquals(response.status_code, 200) def test_status_view(self): "Test page with login at /sales/status/view/" response = self.client.post('/accounts/login', {'username': self.username, 'password': self.password }) self.assertRedirects(response, '/') response = self.client.get(reverse('sales_status_view', args=[self.status.id])) self.assertEquals(response.status_code, 200) def test_status_delete(self): "Test page with login at /sales/status/delete/" response = self.client.post('/accounts/login', {'username': self.username, 'password': self.password }) self.assertRedirects(response, '/') response = self.client.get(reverse('sales_status_delete', args=[self.status.id])) self.assertEquals(response.status_code, 200) # Subscriptions def test_subscription_add(self): "Test page with login at /sales/subscription/add" response = self.client.post('/accounts/login', {'username': self.username, 'password': self.password }) self.assertRedirects(response, '/') response = self.client.get(reverse('sales_subscription_add')) self.assertEquals(response.status_code, 200) def test_subscription_add_product(self): "Test page with login at /sales/subscription/add/" response = self.client.post('/accounts/login', {'username': self.username, 'password': self.password }) self.assertRedirects(response, '/') response = self.client.get(reverse('sales_subscription_add_with_product', args=[self.product.id])) self.assertEquals(response.status_code, 200) def test_subscription_edit(self): "Test page with login at /sales/subscription/edit/" response = self.client.post('/accounts/login', {'username': self.username, 'password': self.password }) self.assertRedirects(response, '/') response = self.client.get(reverse('sales_subscription_edit', args=[self.subscription.id])) self.assertEquals(response.status_code, 200) def test_subscription_view(self): "Test page with login at /sales/subscription/view/" response = self.client.post('/accounts/login', {'username': self.username, 'password': self.password }) self.assertRedirects(response, '/') response = self.client.get(reverse('sales_subscription_view', args=[self.subscription.id])) self.assertEquals(response.status_code, 200) def test_subscription_delete(self): "Test page with login at /sales/subscription/delete/" response = self.client.post('/accounts/login', {'username': self.username, 'password': self.password }) self.assertRedirects(response, '/') response = self.client.get(reverse('sales_subscription_delete', args=[self.subscription.id])) self.assertEquals(response.status_code, 200) # Ordered Products def test_ordered_product_add(self): "Test page with login at /sales/ordered_product/add/" response = self.client.post('/accounts/login', {'username': self.username, 'password': self.password }) self.assertRedirects(response, '/') response = self.client.get(reverse('sales_ordered_product_add', args=[self.order.id])) self.assertEquals(response.status_code, 200) def test_ordered_product_edit(self): "Test page with login at /sales/ordered_product/edit/" response = self.client.post('/accounts/login', {'username': self.username, 'password': self.password }) self.assertRedirects(response, '/') response = self.client.get(reverse('sales_ordered_product_edit', args=[self.ordered_product.id])) self.assertEquals(response.status_code, 200) def test_ordered_product_view(self): "Test page with login at /sales/ordered_product/view/" response = self.client.post('/accounts/login', {'username': self.username, 'password': self.password }) self.assertRedirects(response, '/') response = self.client.get(reverse('sales_ordered_product_view', args=[self.ordered_product.id])) self.assertEquals(response.status_code, 200) def test_ordered_product_delete(self): "Test page with login at /sales/ordered_product/delete/" response = self.client.post('/accounts/login', {'username': self.username, 'password': self.password }) self.assertRedirects(response, '/') response = self.client.get(reverse('sales_ordered_product_delete', args=[self.ordered_product.id])) self.assertEquals(response.status_code, 200) # Sources def test_source_add(self): "Test page with login at /sales/source/add" response = self.client.post('/accounts/login', {'username': self.username, 'password': self.password }) self.assertRedirects(response, '/') response = self.client.get(reverse('sales_source_add')) self.assertEquals(response.status_code, 200) def test_source_edit(self): "Test page with login at /sales/source/edit/" response = self.client.post('/accounts/login', {'username': self.username, 'password': self.password }) self.assertRedirects(response, '/') response = self.client.get(reverse('sales_source_edit', args=[self.source.id])) self.assertEquals(response.status_code, 200) def test_source_view(self): "Test page with login at /sales/source/view/" response = self.client.post('/accounts/login', {'username': self.username, 'password': self.password }) self.assertRedirects(response, '/') response = self.client.get(reverse('sales_source_view', args=[self.source.id])) self.assertEquals(response.status_code, 200) def test_source_delete(self): "Test page with login at /sales/source/delete/" response = self.client.post('/accounts/login', {'username': self.username, 'password': self.password }) self.assertRedirects(response, '/') response = self.client.get(reverse('sales_source_delete', args=[self.source.id])) self.assertEquals(response.status_code, 200) # Leads def test_lead_index(self): "Test page with login at /sales/lead/index" response = self.client.post('/accounts/login', {'username': self.username, 'password': self.password }) self.assertRedirects(response, '/') response = self.client.get(reverse('sales_lead_index')) self.assertEquals(response.status_code, 200) def test_lead_index_assigned(self): "Test page with login at /sales/lead/index/assigned" response = self.client.post('/accounts/login', {'username': self.username, 'password': self.password }) self.assertRedirects(response, '/') response = self.client.get(reverse('sales_lead_index_assigned')) self.assertEquals(response.status_code, 200) def test_lead_add(self): "Test page with login at /sales/lead/add" response = self.client.post('/accounts/login', {'username': self.username, 'password': self.password }) self.assertRedirects(response, '/') response = self.client.get(reverse('sales_lead_add')) self.assertEquals(response.status_code, 200) def test_lead_edit(self): "Test page with login at /sales/lead/edit/" response = self.client.post('/accounts/login', {'username': self.username, 'password': self.password }) self.assertRedirects(response, '/') response = self.client.get(reverse('sales_lead_edit', args=[self.lead.id])) self.assertEquals(response.status_code, 200) def test_lead_view(self): "Test page with login at /sales/lead/view/" response = self.client.post('/accounts/login', {'username': self.username, 'password': self.password }) self.assertRedirects(response, '/') response = self.client.get(reverse('sales_lead_view', args=[self.lead.id])) self.assertEquals(response.status_code, 200) def test_lead_delete(self): "Test page with login at /sales/lead/delete/" response = self.client.post('/accounts/login', {'username': self.username, 'password': self.password }) self.assertRedirects(response, '/') response = self.client.get(reverse('sales_lead_delete', args=[self.lead.id])) self.assertEquals(response.status_code, 200) # Opportunities def test_opportunity_index(self): "Test page with login at /sales/opportunity/index" response = self.client.post('/accounts/login', {'username': self.username, 'password': self.password }) self.assertRedirects(response, '/') response = self.client.get(reverse('sales_opportunity_index')) self.assertEquals(response.status_code, 200) def test_opportunity_index_assigned(self): "Test page with login at /sales/opportunity/index/assigned" response = self.client.post('/accounts/login', {'username': self.username, 'password': self.password }) self.assertRedirects(response, '/') response = self.client.get(reverse('sales_opportunity_index_assigned')) self.assertEquals(response.status_code, 200) def test_opportunity_add(self): "Test page with login at /sales/opportunity/add" response = self.client.post('/accounts/login', {'username': self.username, 'password': self.password }) self.assertRedirects(response, '/') response = self.client.get(reverse('sales_opportunity_add')) self.assertEquals(response.status_code, 200) def test_opportunity_add_lead(self): "Test page with login at /sales/opportunity/add/lead/" response = self.client.post('/accounts/login', {'username': self.username, 'password': self.password }) self.assertRedirects(response, '/') response = self.client.get(reverse('sales_opportunity_add_with_lead', args=[self.lead.id])) self.assertEquals(response.status_code, 200) def test_opportunity_edit(self): "Test page with login at /sales/opportunity/edit/" response = self.client.post('/accounts/login', {'username': self.username, 'password': self.password }) self.assertRedirects(response, '/') response = self.client.get(reverse('sales_opportunity_edit', args=[self.opportunity.id])) self.assertEquals(response.status_code, 200) def test_opportunity_view(self): "Test page with login at /sales/opportunity/view/" response = self.client.post('/accounts/login', {'username': self.username, 'password': self.password }) self.assertRedirects(response, '/') response = self.client.get(reverse('sales_opportunity_view', args=[self.opportunity.id])) self.assertEquals(response.status_code, 200) def test_opportunity_delete(self): "Test page with login at /sales/opportunity/delete/" response = self.client.post('/accounts/login', {'username': self.username, 'password': self.password }) self.assertRedirects(response, '/') response = self.client.get(reverse('sales_opportunity_delete', args=[self.opportunity.id])) self.assertEquals(response.status_code, 200) ###################################### # Testing views when user is not logged in ###################################### def test_index_anonymous(self): "Test index page at /sales/" response = self.client.get('/sales/') # Redirects as unauthenticated self.assertRedirects(response, reverse('user_login')) def test_index_open_out(self): "Testing /sales/open" response = self.client.get(reverse('sales_index_open')) self.assertRedirects(response, reverse('user_login')) def test_index_assigned_out(self): "Testing /sales/index/assigned" response = self.client.get(reverse('sales_index_assigned')) self.assertRedirects(response, reverse('user_login')) # Orders def test_order_add_out(self): "Testing /sales/order/add" response = self.client.get(reverse('sales_order_add')) self.assertRedirects(response, reverse('user_login')) def test_order_add_lead_out(self): "Testing /sales/order/add/lead/" response = self.client.get(reverse('sales_order_add_with_lead', args=[self.lead.id])) self.assertRedirects(response, reverse('user_login')) def test_order_add_opportunity_out(self): "Testing /sales/order/add/opportunity/" response = self.client.get(reverse('sales_order_add_with_opportunity', args=[self.opportunity.id])) self.assertRedirects(response, reverse('user_login')) def test_order_edit_out(self): "Testing /sales/order/edit/" response = self.client.get(reverse('sales_order_edit', args=[self.order.id])) self.assertRedirects(response, reverse('user_login')) def test_order_view_out(self): "Testing /sales/order/view/" response = self.client.get(reverse('sales_order_view', args=[self.order.id])) self.assertRedirects(response, reverse('user_login')) def test_order_delete_out(self): "Testing /sales/order/delete/" response = self.client.get(reverse('sales_order_delete', args=[self.order.id])) self.assertRedirects(response, reverse('user_login')) def test_order_invoice_view_out(self): "Testing /sales/order/invoice/" response = self.client.get(reverse('sales_order_invoice_view', args=[self.order.id])) self.assertRedirects(response, reverse('user_login')) # Products def test_product_index_out(self): "Testing /sales/product/index" response = self.client.get(reverse('sales_product_index')) self.assertRedirects(response, reverse('user_login')) def test_product_add_out(self): "Testing /sales/product/add/" response = self.client.get(reverse('sales_product_add')) self.assertRedirects(response, reverse('user_login')) def test_product_add_parent_out(self): "Testing /sales/product/add" response = self.client.get(reverse('sales_product_add', args=[self.product.id])) self.assertRedirects(response, reverse('user_login')) def test_product_edit_out(self): "Testing /sales/product/edit/" response = self.client.get(reverse('sales_product_edit', args=[self.product.id])) self.assertRedirects(response, reverse('user_login')) def test_product_view_out(self): "Testing /sales/product/view/" response = self.client.get(reverse('sales_product_view', args=[self.product.id])) self.assertRedirects(response, reverse('user_login')) def test_product_delete_out(self): "Testing /sales/product/delete/" response = self.client.get(reverse('sales_product_delete', args=[self.product.id])) self.assertRedirects(response, reverse('user_login')) # Settings def test_settings_view_out(self): "Testing /sales/settings/view" response = self.client.get(reverse('sales_settings_view')) self.assertRedirects(response, reverse('user_login')) def test_settings_edit_out(self): "Testing /sales/settings/edit" response = self.client.get(reverse('sales_settings_edit')) self.assertRedirects(response, reverse('user_login')) # Statuses def test_status_add_out(self): "Testing /sales/status/add" response = self.client.get(reverse('sales_status_add')) self.assertRedirects(response, reverse('user_login')) def test_status_edit_out(self): "Testing /sales/status/edit/" response = self.client.get(reverse('sales_status_edit', args=[self.status.id])) self.assertRedirects(response, reverse('user_login')) def test_status_view_out(self): "Testing /sales/status/view/" response = self.client.get(reverse('sales_status_view', args=[self.status.id])) self.assertRedirects(response, reverse('user_login')) def test_status_delete_out(self): "Testing /sales/status/delete/" response = self.client.get(reverse('sales_status_delete', args=[self.status.id])) self.assertRedirects(response, reverse('user_login')) # Subscriptions def test_subscription_add_out(self): "Testing /sales/subscription/add" response = self.client.get(reverse('sales_subscription_add')) self.assertRedirects(response, reverse('user_login')) def test_subscription_add_product_out(self): "Testing /sales/subscription/add/" response = self.client.get(reverse('sales_subscription_add_with_product', args=[self.product.id])) self.assertRedirects(response, reverse('user_login')) def test_subscription_edit_out(self): "Testing /sales/subscription/edit/" response = self.client.get(reverse('sales_subscription_edit', args=[self.subscription.id])) self.assertRedirects(response, reverse('user_login')) def test_subscription_view_out(self): "Testing /sales/subscription/view/" response = self.client.get(reverse('sales_subscription_view', args=[self.subscription.id])) self.assertRedirects(response, reverse('user_login')) def test_subscription_delete_out(self): "Testing /sales/subscription/delete/" response = self.client.get(reverse('sales_subscription_delete', args=[self.subscription.id])) self.assertRedirects(response, reverse('user_login')) # Ordered Products def test_ordered_product_add_out(self): "Testing /sales/ordered_product/add/" response = self.client.get(reverse('sales_ordered_product_add', args=[self.order.id])) self.assertRedirects(response, reverse('user_login')) def test_ordered_product_edit_out(self): "Testing /sales/ordered_product/edit/" response = self.client.get(reverse('sales_ordered_product_edit', args=[self.ordered_product.id])) self.assertRedirects(response, reverse('user_login')) def test_ordered_product_view_out(self): "Testing /sales/ordered_product/view/" response = self.client.get(reverse('sales_ordered_product_view', args=[self.ordered_product.id])) self.assertRedirects(response, reverse('user_login')) def test_ordered_product_delete_out(self): "Testing /sales/ordered_product/delete/" response = self.client.get(reverse('sales_ordered_product_delete', args=[self.ordered_product.id])) self.assertRedirects(response, reverse('user_login')) # Sources def test_source_add_out(self): "Testing /sales/source/add" response = self.client.get(reverse('sales_source_add')) self.assertRedirects(response, reverse('user_login')) def test_source_edit_out(self): "Testing /sales/source/edit/" response = self.client.get(reverse('sales_source_edit', args=[self.source.id])) self.assertRedirects(response, reverse('user_login')) def test_source_view_out(self): "Testing /sales/source/view/" response = self.client.get(reverse('sales_source_view', args=[self.source.id])) self.assertRedirects(response, reverse('user_login')) def test_source_delete_out(self): "Testing /sales/source/delete/" response = self.client.get(reverse('sales_source_delete', args=[self.source.id])) self.assertRedirects(response, reverse('user_login')) # Leads def test_lead_index_out(self): "Testing /sales/lead/index" response = self.client.get(reverse('sales_lead_index')) self.assertRedirects(response, reverse('user_login')) def test_lead_index_assigned_out(self): "Testing /sales/lead/index/assigned" response = self.client.get(reverse('sales_lead_index_assigned')) self.assertRedirects(response, reverse('user_login')) def test_lead_add_out(self): "Testing /sales/lead/add" response = self.client.get(reverse('sales_lead_add')) self.assertRedirects(response, reverse('user_login')) def test_lead_edit_out(self): "Testing /sales/lead/edit/" response = self.client.get(reverse('sales_lead_edit', args=[self.lead.id])) self.assertRedirects(response, reverse('user_login')) def test_lead_view_out(self): "Testing /sales/lead/view/" response = self.client.get(reverse('sales_lead_view', args=[self.lead.id])) self.assertRedirects(response, reverse('user_login')) def test_lead_delete_out(self): "Testing /sales/lead/delete/" response = self.client.get(reverse('sales_lead_delete', args=[self.lead.id])) self.assertRedirects(response, reverse('user_login')) # Opportunities def test_opportunity_index_out(self): "Testing /sales/opportunity/index/" response = self.client.get(reverse('sales_opportunity_index')) self.assertRedirects(response, reverse('user_login')) def test_opportunity_index_assigned_out(self): "Testing /sales/opportunity/index/assigned/" response = self.client.get(reverse('sales_opportunity_index_assigned')) self.assertRedirects(response, reverse('user_login')) def test_opportunity_add_out(self): "Testing /sales/opportunity/add/" response = self.client.get(reverse('sales_opportunity_add')) self.assertRedirects(response, reverse('user_login')) def test_opportunity_add_lead_out(self): "Testing /sales/opportunity/add/lead/" response = self.client.get(reverse('sales_opportunity_add_with_lead', args=[self.lead.id])) self.assertRedirects(response, reverse('user_login')) def test_opportunity_edit_out(self): "Testing /sales/opportunity/edit/" response = self.client.get(reverse('sales_opportunity_edit', args=[self.opportunity.id])) self.assertRedirects(response, reverse('user_login')) def test_opportunity_view_out(self): "Testing /sales/opportunity/view/" response = self.client.get(reverse('sales_opportunity_view', args=[self.opportunity.id])) self.assertRedirects(response, reverse('user_login')) def test_opportunity_delete_out(self): "Testing /sales/opportunity/delete/" response = self.client.get(reverse('sales_opportunity_delete', args=[self.opportunity.id])) self.assertRedirects(response, reverse('user_login'))
class SalesAPITest(TestCase): "Sales functional tests for views" username = "******" password = "******" prepared = False authentication_headers ={"CONTENT_TYPE": "application/json", "HTTP_AUTHORIZATION" : "Basic YXBpX3Rlc3Q6YXBpX3Bhc3N3b3Jk" } content_type ='application/json' def setUp(self): "Initial Setup" if not self.prepared: # Clean up first Object.objects.all().delete() User.objects.all().delete() # Create objects try: self.group = Group.objects.get(name='test') except Group.DoesNotExist: Group.objects.all().delete() self.group = Group(name='test') self.group.save() try: self.user = DjangoUser.objects.get(username=self.username) self.user.set_password(self.password) try: self.profile = self.user.get_profile() except Exception: User.objects.all().delete() self.user = DjangoUser(username=self.username, password='') self.user.set_password(self.password) self.user.save() except DjangoUser.DoesNotExist: User.objects.all().delete() self.user = DjangoUser(username=self.username, password='') self.user.set_password(self.password) self.user.save() try: perspective = Perspective.objects.get(name='default') except Perspective.DoesNotExist: Perspective.objects.all().delete() perspective = Perspective(name='default') perspective.set_default_user() perspective.save() ModuleSetting.set('default_perspective', perspective.id) self.contact_type = ContactType() self.contact_type.slug = 'machine' self.contact_type.name = 'machine' self.contact_type.save() self.contact = Contact() self.contact.contact_type = self.contact_type self.contact.set_default_user() self.contact.save() self.assertNotEquals(self.contact.id, None) self.status = SaleStatus() self.status.active = True self.status.use_sales = True self.status.use_leads = True self.status.use_opportunities = True self.status.set_default_user() self.status.save() self.assertNotEquals(self.status.id, None) self.currency = Currency(code="GBP", name="Pounds", symbol="L", is_default=True) self.currency.save() self.source = SaleSource() self.source.active = True self.source.save() self.source.set_user(self.user) self.assertNotEquals(self.source.id, None) self.product = Product(name="Test") self.product.product_type = 'service' self.product.active = True self.product.sell_price = 10 self.product.buy_price = 100 self.product.set_default_user() self.product.save() self.assertNotEquals(self.product.id, None) self.subscription = Subscription() self.subscription.client = self.contact self.subscription.set_default_user() self.subscription.save() self.assertNotEquals(self.subscription.id, None) self.lead = Lead() self.lead.contact_method = 'email' self.lead.status = self.status self.lead.contact = self.contact self.lead.set_default_user() self.lead.save() self.assertNotEquals(self.lead.id, None) self.opportunity = Opportunity() self.opportunity.lead = self.lead self.opportunity.contact = self.contact self.opportunity.status = self.status self.opportunity.amount = 100 self.opportunity.amount_currency = self.currency self.opportunity.amount_display = 120 self.opportunity.set_default_user() self.opportunity.save() self.assertNotEquals(self.opportunity.id, None) self.order = SaleOrder(reference="Test") self.order.opportunity = self.opportunity self.order.status = self.status self.order.source = self.source self.order.currency = self.currency self.order.total = 0 self.order.total_display = 0 self.order.set_default_user() self.order.save() self.assertNotEquals(self.order.id, None) self.ordered_product = OrderedProduct() self.ordered_product.product = self.product self.ordered_product.order = self.order self.ordered_product.rate = 0 self.ordered_product.subscription = self.subscription self.ordered_product.set_default_user() self.ordered_product.save() self.assertNotEquals(self.ordered_product.id, None) self.client = Client() self.prepared = True def test_unauthenticated_access(self): "Test index page at /sales/statuses" response = self.client.get('/api/sales/statuses') # Redirects as unauthenticated self.assertEquals(response.status_code, 401) def test_get_statuses_list(self): """ Test index page api/sales/status """ response = self.client.get(path=reverse('api_sales_status'), **self.authentication_headers) self.assertEquals(response.status_code, 200) def test_get_status(self): response = self.client.get(path=reverse('api_sales_status', kwargs={'object_ptr': self.status.id}), **self.authentication_headers) self.assertEquals(response.status_code, 200) def test_update_status(self): updates = {"name": "Close_API", "active": True, "details": "api test details", "use_leads": True, "use_opportunities": True, "hidden": False} response = self.client.put(path=reverse('api_sales_status', kwargs={'object_ptr': self.status.id}), content_type=self.content_type, data=json.dumps(updates), **self.authentication_headers) self.assertEquals(response.status_code, 200) data = json.loads(response.content) self.assertEquals(data['name'], updates['name']) self.assertEquals(data['active'], updates['active']) self.assertEquals(data['details'], updates['details']) self.assertEquals(data['use_leads'], updates['use_leads']) self.assertEquals(data['use_opportunities'], updates['use_opportunities']) self.assertEquals(data['hidden'], updates['hidden']) def test_get_products_list(self): """ Test index page api/sales/products """ response = self.client.get(path=reverse('api_sales_products'), **self.authentication_headers) self.assertEquals(response.status_code, 200) def test_get_product(self): response = self.client.get(path=reverse('api_sales_products', kwargs={'object_ptr': self.product.id}), **self.authentication_headers) self.assertEquals(response.status_code, 200) def test_update_product(self): updates = {"name": "API product", "parent": None, "product_type": "service", "code": "api_test_code", "buy_price": '100.05', "sell_price":'10.5', "active": True, "runout_action": "ignore", "details": "api details"} response = self.client.put(path=reverse('api_sales_products', kwargs={'object_ptr': self.product.id}), content_type=self.content_type, data=json.dumps(updates), **self.authentication_headers) self.assertEquals(response.status_code, 200) data = json.loads(response.content) self.assertEquals(data['name'], updates['name']) self.assertEquals(data['product_type'], updates['product_type']) self.assertEquals(data['code'], updates['code']) self.assertEquals(data['buy_price'], updates['buy_price']) self.assertEquals(data['sell_price'], updates['sell_price']) self.assertEquals(data['active'], updates['active']) self.assertEquals(data['runout_action'], updates['runout_action']) self.assertEquals(data['details'], updates['details']) def test_get_sources_list(self): """ Test index page api/sales/sources """ response = self.client.get(path=reverse('api_sales_sources'), **self.authentication_headers) self.assertEquals(response.status_code, 200) def test_get_source(self): response = self.client.get(path=reverse('api_sales_sources', kwargs={'object_ptr': self.source.id}), **self.authentication_headers) self.assertEquals(response.status_code, 200) def test_update_source(self): updates = {"name":"Api source", "active": True, "details": "api details"} response = self.client.put(path=reverse('api_sales_sources', kwargs={'object_ptr': self.source.id}), content_type=self.content_type, data=json.dumps(updates), **self.authentication_headers) self.assertEquals(response.status_code, 200) data = json.loads(response.content) self.assertEquals(data['name'], updates['name']) self.assertEquals(data['active'], updates['active']) self.assertEquals(data['details'], updates['details']) # def test_get_leads_list(self): """ Test index page api/sales/leads """ response = self.client.get(path=reverse('api_sales_leads'), **self.authentication_headers) self.assertEquals(response.status_code, 200) def test_get_lead(self): response = self.client.get(path=reverse('api_sales_leads', kwargs={'object_ptr': self.lead.id}), **self.authentication_headers) self.assertEquals(response.status_code, 200) def test_update_lead(self): updates = {"status": self.status.id, "contact_method": "email", "contact": self.contact.id, "products_interested": [self.product.id], "source": self.source.id, 'details': 'Api details'} response = self.client.put(path=reverse('api_sales_leads', kwargs={'object_ptr': self.lead.id}), content_type=self.content_type, data=json.dumps(updates), **self.authentication_headers) self.assertEquals(response.status_code, 200) data = json.loads(response.content) self.assertEquals(data['status']['id'], updates['status']) self.assertEquals(data['contact_method'], updates['contact_method']) self.assertEquals(data['contact']['id'], updates['contact']) for i, product in enumerate(data['products_interested']): self.assertEquals(product['id'], updates['products_interested'][i]) self.assertEquals(data['source']['id'], updates['source']) self.assertEquals(data['details'], updates['details']) def test_get_opportunities_list(self): """ Test index page api/sales/opportunities """ response = self.client.get(path=reverse('api_sales_opportunities'), **self.authentication_headers) self.assertEquals(response.status_code, 200) def test_get_opportunity(self): response = self.client.get(path=reverse('api_sales_opportunities', kwargs={'object_ptr': self.opportunity.id}), **self.authentication_headers) self.assertEquals(response.status_code, 200) def test_update_opportunity(self): updates = {"status": self.status.id, "products_interested": [self.product.id], "contact": self.contact.id, "amount_display": 3000.56, "amount_currency": self.currency.id, "details": "API DETAILS"} response = self.client.put(path=reverse('api_sales_opportunities', kwargs={'object_ptr': self.opportunity.id}), content_type=self.content_type, data=json.dumps(updates), **self.authentication_headers) self.assertEquals(response.status_code, 200) data = json.loads(response.content) self.assertEquals(data['status']['id'], updates['status']) self.assertEquals(data['contact']['id'], updates['contact']) for i, product in enumerate(data['products_interested']): self.assertEquals(product['id'], updates['products_interested'][i]) self.assertEquals(data['amount_currency']['id'], updates['amount_currency']) self.assertEquals(data['details'], updates['details']) def test_get_orders_list(self): """ Test index page api/sales/orders """ response = self.client.get(path=reverse('api_sales_orders'), **self.authentication_headers) self.assertEquals(response.status_code, 200) def test_get_order(self): response = self.client.get(path=reverse('api_sales_orders', kwargs={'object_ptr': self.order.id}), **self.authentication_headers) self.assertEquals(response.status_code, 200) def test_update_order(self): updates = {"datetime": "2011-04-11 12:01:15", "status": self.status.id, "source": self.source.id, "details": "api details"} response = self.client.put(path=reverse('api_sales_orders', kwargs={'object_ptr': self.order.id}), content_type=self.content_type, data=json.dumps(updates), **self.authentication_headers) self.assertEquals(response.status_code, 200) data = json.loads(response.content) self.assertEquals(data['status']['id'], updates['status']) self.assertEquals(data['source']['id'], updates['source']) self.assertEquals(data['details'], updates['details']) def test_get_subscriptions_list(self): """ Test index page api/sales/subscriptions""" response = self.client.get(path=reverse('api_sales_subscriptions'), **self.authentication_headers) self.assertEquals(response.status_code, 200) def test_get_subscription(self): response = self.client.get(path=reverse('api_sales_subscriptions', kwargs={'object_ptr': self.subscription.id}), **self.authentication_headers) self.assertEquals(response.status_code, 200) def test_update_subscription(self): updates = {"product": self.product.id, "start": "2011-06-30", "cycle_period": "daily", "active": True, "details": "api details"} response = self.client.put(path=reverse('api_sales_subscriptions', kwargs={'object_ptr': self.subscription.id}), content_type=self.content_type, data=json.dumps(updates), **self.authentication_headers) self.assertEquals(response.status_code, 200) data = json.loads(response.content) self.assertEquals(data['product']['id'], updates['product']) self.assertEquals(data['cycle_period'], updates['cycle_period']) self.assertEquals(data['active'], updates['active']) self.assertEquals(data['details'], updates['details']) def test_get_ordered_product(self): response = self.client.get(path=reverse('api_sales_ordered_products', kwargs={'object_ptr': self.ordered_product.id}), **self.authentication_headers) self.assertEquals(response.status_code, 200) def test_update_ordered_product(self): updates = {"discount": '10.0', "product": self.product.id, "quantity": '10'} response = self.client.put(path=reverse('api_sales_ordered_products', kwargs={'object_ptr': self.ordered_product.id}), content_type=self.content_type, data=json.dumps(updates), **self.authentication_headers) self.assertEquals(response.status_code, 200) data = json.loads(response.content) self.assertEquals(data['product']['id'], updates['product']) self.assertEquals(data['discount'], updates['discount']) self.assertEquals(data['quantity'], updates['quantity'])