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 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
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
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
def save(self, *args, **kwargs): "Form processor" profile = None if self.invitation: # Create DjangoUser django_user = django_auth.User(username=self.cleaned_data['username'], password='') django_user.set_password(self.cleaned_data['password']) django_user.save() # Crate profile try: profile = django_user.get_profile() except: profile = User() profile.user = django_user profile.name = django_user.username profile.default_group = self.invitation.default_group profile.save() # Create contact try: contact_type = ContactType.objects.get(Q(name='Person') | Q(slug='person')) except: contact_type = ContactType.objects.all()[0] try: # Check if contact has already been created (e.g. by a signals contact = profile.get_contact() if not contact: contact = Contact() except: contact = Contact() contact.name = self.cleaned_data['name'] contact.contact_type = contact_type contact.related_user = profile contact.save() # Set email try: emailfield = contact_type.fields.filter(field_type='email')[0] email = ContactValue(value=self.invitation.email, field=emailfield, contact=contact) email.save() except: pass # Add quick start widget widget = Widget(user=profile, perspective=profile.get_perspective(), module_name='maker.core', widget_name='widget_welcome') widget.save() return profile
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 messaging_compose(request, response_format='html'): "New message page" user = request.user.get_profile() if request.POST: if not 'cancel' in request.POST: message = Message() message.author = user.get_contact() if not message.author: return user_denied(request, message="You can't send message without a Contact Card assigned to you.", response_format=response_format) form = MessageForm(request.user.get_profile(), None, None, request.POST, instance=message) if form.is_valid(): message = form.save() message.recipients.add(user.get_contact()) message.set_user_from_request(request) message.read_by.add(user) try: # if email entered create contact and add to recipients if 'multicomplete_recipients' in request.POST and request.POST['multicomplete_recipients']: try: conf = ModuleSetting.get_for_module('maker.messaging', 'default_contact_type')[0] default_contact_type = ContactType.objects.get(pk=long(conf.value)) except Exception: default_contact_type = None emails = request.POST['multicomplete_recipients'].split(',') for email in emails: emailstr = unicode(email).strip() if re.match('[a-zA-Z0-9+_\-\.]+@[0-9a-zA-Z][.-0-9a-zA-Z]*.[a-zA-Z]+', emailstr): contact, created = Contact.get_or_create_by_email(emailstr, contact_type=default_contact_type) message.recipients.add(contact) if created: contact.set_user_from_request(request) except: pass # send email to all recipients message.send_email() return HttpResponseRedirect(reverse('messaging')) else: return HttpResponseRedirect(reverse('messaging')) else: form = MessageForm(request.user.get_profile(), None) context = _get_default_context(request) context.update({'form': form}) return render_to_response('messaging/message_compose', context, context_instance=RequestContext(request), response_format=response_format)
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()
def create(self, request, *args, **kwargs): "Send email to some recipients" user = request.user.get_profile() if request.data is None: return rc.BAD_REQUEST if request.data.has_key('stream'): stream = getOrNone(MessageStream, request.data['stream']) if stream and not user.has_permission(stream, mode='x'): return rc.FORBIDDEN message = Message() message.author = user.get_contact() if not message.author: return rc.FORBIDDEN form = MessageForm(user, None, None, request.data, instance=message) if form.is_valid(): message = form.save() message.recipients.add(user.get_contact()) message.set_user_from_request(request) message.read_by.add(user) try: # if email entered create contact and add to recipients if 'multicomplete_recipients' in request.POST and request.POST['multicomplete_recipients']: try: conf = ModuleSetting.get_for_module('maker.messaging', 'default_contact_type')[0] default_contact_type = ContactType.objects.get(pk=long(conf.value)) except Exception: default_contact_type = None emails = request.POST['multicomplete_recipients'].split(',') for email in emails: emailstr = unicode(email).strip() if re.match('[a-zA-Z0-9+_\-\.]+@[0-9a-zA-Z][.-0-9a-zA-Z]*.[a-zA-Z]+', emailstr): contact, created = Contact.get_or_create_by_email(emailstr, contact_type=default_contact_type) message.recipients.add(contact) if created: contact.set_user_from_request(request) except: pass # send email to all recipients message.send_email() return message else: self.status = 400 return form.errors
def parse_contacts(self, contacts): "Break down CSV file into fields" for row in contacts: #Tidy up keys (iterkeys strip()) try: type = row['type'] except Exception: pass #Set type to default type try: name = row['name'] except Exception: try: firstname = row['firstname'] surname = row['surname'] name = firstname + " " + surname except Exception: continue contact_type = ContactType.objects.filter(name=type) if contact_type: contact_type = contact_type[0] # Create a new contact if it doesn't exist contact_exists = Contact.objects.filter(name=name, contact_type__name=type, trash=False) #TODO: If one does exist then append the data on that contact if not contact_exists: contact = Contact() contact.name = name contact.contact_type = contact_type contact.auto_notify = False contact.save() fields = contact_type.fields.filter(trash=False) for field in fields: if field.name in row: x = row[field.name] if field.field_type == 'email': x = self.verify_email(x) if field.field_type == 'url': x = self.verify_url(x) if x: contact_value = ContactValue() contact_value.field = field contact_value.contact = contact contact_value.value = x contact_value.save()
def process_msg(self, msg, attrs, attachments): "Save message, Cap!" from maker.messaging.models import Message try: conf = ModuleSetting.get_for_module('maker.messaging', 'default_contact_type')[0] default_contact_type = ContactType.objects.get(pk=long(conf.value)) except: default_contact_type = None email_author, created = Contact.get_or_create_by_email(attrs.author_email, attrs.author_name, default_contact_type) if created: email_author.copy_permissions(self.stream) # check if the message is already retrieved existing = Message.objects.filter(stream=self.stream, title=attrs.subject, author=email_author, body=attrs.body).exists() if not existing: message = None if attrs.subject[:3] == 'Re:': # process replies if attrs.subject[:4] == 'Re: ': original_subject = attrs.subject[4:] else: original_subject = attrs.subject[3:] try: query = Q(reply_to__isnull=True) & Q(recipients=email_author) & (Q(title=original_subject) | Q(title=attrs.subject)) original = Message.objects.filter(query).order_by('-date_created')[:1][0] message = Message(title=attrs.subject, body=attrs.body, author=email_author, stream=self.stream, reply_to=original) if attrs.email_date: message.date_created = attrs.email_date message.save() message.copy_permissions(original) original.read_by.clear() except IndexError: pass if not message: message = Message(title=attrs.subject, body=attrs.body, author=email_author, stream=self.stream) if attrs.email_date: message.date_created = attrs.email_date message.save() message.copy_permissions(self.stream) message.recipients.add(email_author)
def save(self, request, contact_type=None): "Process form and create DB objects as required" if self.instance: contact = self.instance else: contact = Contact() contact.contact_type = contact_type contact.name = unicode(self.cleaned_data['name']) if 'parent' in self.cleaned_data: contact.parent = self.cleaned_data['parent'] if 'related_user' in self.cleaned_data: contact.related_user = self.cleaned_data['related_user'] contact.save() if self.instance: contact.contactvalue_set.all().delete() for field in contact.contact_type.fields.all(): for form_name in self.cleaned_data: if re.match(str("^"+field.name+"___\d+$"), form_name): if isinstance(self.fields[form_name], forms.FileField): value = ContactValue(field=field, contact=contact, value=self._handle_uploaded_file(form_name)) if isinstance(self.fields[form_name], forms.ImageField): self._image_resize(value.value) else: if field.field_type == 'picture' and isinstance(self.fields[form_name], forms.ChoiceField): if self.cleaned_data[form_name] != 'delete': value = ContactValue(field=field, contact=contact, value=self.cleaned_data[form_name]) else: value = ContactValue(field=field, contact=contact, value=self.cleaned_data[form_name]) value.save() return contact
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'))
def _do_sync(data, user): "Run updates" resource_id = data.info.application.id.raw contact_type = _get_contact_type(user) for item in data.result: item_id = None if 'id' in item.raw: item_id = item.id.raw dups = _find_duplicates(resource_id, item, user) if dups: for contact in dups: transaction.commit() try: fields = contact.contact_type.fields contact.add_nuvius_resource(resource_id, item_id) if item.name.raw: contact.name = item.name.raw if item.email: fs = fields.filter(field_type='email') if fs: for iemail in item.email: values = contact.contactvalue_set.filter(field__in=fs, value=iemail.raw) if not values: value = ContactValue(contact=contact, field=fs[0], value=iemail.raw) value.save() if item.phone: fs = fields.filter(field_type='phone') if fs: for iphone in item.phone: values = contact.contactvalue_set.filter(field__in=fs, value=iphone.raw) if not values: value = ContactValue(contact=contact, field=fs[0], value=iphone.raw) value.save() if item.address: fs = fields.filter(name='address') if fs: for iaddress in item.address: values = contact.contactvalue_set.filter(field__in=fs, value__icontains=iaddress.raw) if not values: value = ContactValue(contact=contact, field=fs[0], value=iaddress.raw) value.save() if item.website: fs = fields.filter(name='website') if fs: for iwebsite in item.website: values = contact.contactvalue_set.filter(field__in=fs, value__icontains=iwebsite.raw) if not values: value = ContactValue(contact=contact, field=fs[0], value=iwebsite.raw) value.save() contact.auto_notify = False contact.save() transaction.commit() except KeyboardInterrupt: transaction.rollback() break except: transaction.rollback() else: if contact_type and item.name.raw: transaction.commit() try: contact = Contact(contact_type=contact_type) contact.add_nuvius_resource(resource_id, item_id) contact.name = item.name.raw contact.auto_notify = False contact.set_user(user) contact.save() fields = contact_type.fields if item.email: fs = fields.filter(field_type='email') if fs: for iemail in item.email: value = ContactValue(contact=contact, field=fs[0], value=iemail.raw) value.save() if item.phone: fs = fields.filter(field_type='phone') if fs: for iphone in item.phone: value = ContactValue(contact=contact, field=fs[0], value=iphone.raw) value.save() if item.address: fs = fields.filter(name='address') if fs: for iaddress in item.address: value = ContactValue(contact=contact, field=fs[0], value=iaddress.raw) value.save() if item.website: fs = fields.filter(name='website') if fs: for iwebsite in item.website: value = ContactValue(contact=contact, field=fs[0], value=iwebsite.raw) value.save() transaction.commit() except KeyboardInterrupt: transaction.rollback() break except: transaction.rollback() _clean_missing(resource_id, data.result, user)
def messaging_view(request, message_id, response_format='html'): "Single message page" message = get_object_or_404(Message, pk=message_id) user = request.user.get_profile() if not user.has_permission(message): return user_denied(request, message="You don't have access to this Message", response_format=response_format) message.read_by.add(user) if request.POST and request.POST.get('body', False): "Unread message" reply = Message() reply.author = user.get_contact() if not reply.author: return user_denied(request, message="You can't send message without a Contact Card assigned to you.", response_format=response_format) reply.reply_to = message form = MessageReplyForm(user, message.stream_id, message, request.POST, instance=reply) if form.is_valid(): reply = form.save() reply.set_user_from_request(request) # Add author to recipients reply.recipients.add(reply.author) message.read_by.clear() try: # if email entered create contact and add to recipients if 'multicomplete_recipients' in request.POST and request.POST['multicomplete_recipients']: try: conf = ModuleSetting.get_for_module('maker.messaging', 'default_contact_type')[0] default_contact_type = ContactType.objects.get(pk=long(conf.value)) except Exception: default_contact_type = None emails = request.POST['multicomplete_recipients'].split(',') for email in emails: emailstr = unicode(email).strip() if re.match('[a-zA-Z0-9+_\-\.]+@[0-9a-zA-Z][.-0-9a-zA-Z]*.[a-zA-Z]+', emailstr): contact, created = Contact.get_or_create_by_email(emailstr, contact_type=default_contact_type) reply.recipients.add(contact) if created: contact.set_user_from_request(request) except: pass # Add each recipient of the reply to the original message for recipient in reply.recipients.all(): message.recipients.add(recipient) # send email to all recipients reply.send_email() return HttpResponseRedirect(reverse('messaging_message_view', args=[message.id])) else: form = MessageReplyForm(request.user.get_profile(), message.stream_id, message) replies = Object.filter_by_request(request, Message.objects.filter(reply_to=message).order_by('date_created')) context = _get_default_context(request) context.update({'message':message, 'messages':replies, 'form':form}) return render_to_response('messaging/message_view', context, context_instance=RequestContext(request), response_format=response_format)
def stream_view(request, stream_id, response_format='html'): "Stream view page" user = request.user.get_profile() stream = get_object_or_404(MessageStream, pk=stream_id) if not request.user.get_profile().has_permission(stream): return user_denied(request, message="You don't have access to this Stream", response_format=response_format) if request.user.get_profile().has_permission(stream, mode='x'): if request.POST: message = Message() message.author = user.get_contact() if not message.author: return user_denied(request, message="You can't send message without a Contact Card assigned to you.", response_format=response_format) form = MessageForm(request.user.get_profile(), None, None, request.POST, instance=message) if form.is_valid(): message = form.save() message.recipients.add(user.get_contact()) message.set_user_from_request(request) message.read_by.add(user) try: # if email entered create contact and add to recipients if 'multicomplete_recipients' in request.POST and request.POST['multicomplete_recipients']: try: conf = ModuleSetting.get_for_module('maker.messaging', 'default_contact_type')[0] default_contact_type = ContactType.objects.get(pk=long(conf.value)) except Exception: default_contact_type = None emails = request.POST['multicomplete_recipients'].split(',') for email in emails: emailstr = unicode(email).strip() if re.match('[a-zA-Z0-9+_\-\.]+@[0-9a-zA-Z][.-0-9a-zA-Z]*.[a-zA-Z]+', emailstr): contact, created = Contact.get_or_create_by_email(emailstr, contact_type=default_contact_type) message.recipients.add(contact) if created: contact.set_user_from_request(request) except: pass # send email to all recipients message.send_email() return HttpResponseRedirect(reverse('messaging_stream_view', args=[stream.id])) else: form = MessageForm(request.user.get_profile(), stream_id) else: form = None messages = Object.filter_by_request(request, Message.objects.filter(reply_to__isnull=True, stream=stream).order_by('-date_created')) context = _get_default_context(request) context.update({'messages':messages, 'form': form, 'stream':stream}) return render_to_response('messaging/stream_view', context, context_instance=RequestContext(request), response_format=response_format)
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'))
def update(self, request, *args, **kwargs): "Reply to message" if request.data is None: return rc.BAD_REQUEST pkfield = kwargs.get(self.model._meta.pk.name) or request.data.get(self.model._meta.pk.name) if not pkfield: return rc.BAD_REQUEST user = request.user.get_profile() try: message = self.model.objects.get(pk=pkfield) except ObjectDoesNotExist: return rc.NOT_FOUND if not user.has_permission(message): return rc.FORBIDDEN reply = Message() reply.author = user.get_contact() if not reply.author: return rc.FORBIDDEN reply.reply_to = message form = MessageReplyForm(user, message.stream_id, message, request.data, instance=reply) if form.is_valid(): reply = form.save() reply.set_user_from_request(request) # Add author to recipients reply.recipients.add(reply.author) message.read_by.clear() try: # if email entered create contact and add to recipients if 'multicomplete_recipients' in request.POST and request.POST['multicomplete_recipients']: try: conf = ModuleSetting.get_for_module('maker.messaging', 'default_contact_type')[0] default_contact_type = ContactType.objects.get(pk=long(conf.value)) except Exception: default_contact_type = None emails = request.POST['multicomplete_recipients'].split(',') for email in emails: emailstr = unicode(email).strip() if re.match('[a-zA-Z0-9+_\-\.]+@[0-9a-zA-Z][.-0-9a-zA-Z]*.[a-zA-Z]+', emailstr): contact, created = Contact.get_or_create_by_email(emailstr, contact_type=default_contact_type) reply.recipients.add(contact) if created: contact.set_user_from_request(request) except: pass # Add each recipient of the reply to the original message for recipient in reply.recipients.all(): message.recipients.add(recipient) # send email to all recipients reply.send_email() return reply else: self.status = 400 return form.errors
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 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'))
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
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'])
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 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
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'))
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
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'))