Exemplo n.º 1
0
def event_add(request, date=None, hour=12, response_format='html'):
    "Event add form"
    
    if request.POST:
        if not 'cancel' in request.POST:
            event = Event()
            form = EventForm(request.user.get_profile(), date, hour, request.POST, instance=event)
            if form.is_valid():
                event = form.save()
                event.set_user_from_request(request)
                return HttpResponseRedirect(reverse('events_event_view', args=[event.id]))
        else:
            return HttpResponseRedirect(reverse('events'))
    else:
        form = EventForm(request.user.get_profile(), date, hour)
        
    return render_to_response('events/event_add', 
                              {'form': form},
                               context_instance=RequestContext(request), response_format=response_format)
Exemplo n.º 2
0
    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.event = Event(name='TestStatus', end=datetime.now())
            self.event.set_default_user()
            self.event.save()

            self.client = Client()

            self.prepared = True
Exemplo n.º 3
0
def _do_sync(data, user):
    "Run updates"
    
    resource_id = data.info.application.id.raw
    
    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 event in dups:
                try:
                    event.add_nuvius_resource(resource_id, item_id)
                    event.name = item.title.raw
                    if item.date:
                        idate = item.date[0]
                        event.start = datetime(*idate.start.raw[:6])
                        event.end = datetime(*idate.end.raw[:6])
                    event.auto_notify = False
                    event.save()
                except:
                    pass
        else:
            try:
                event = Event()
                event.add_nuvius_resource(resource_id, item_id)
                event.name = item.title.raw
                if item.date:
                    idate = item.date[0]
                    event.start = datetime(*idate.start.raw[:6])
                    event.end = datetime(*idate.end.raw[:6])
                event.auto_notify = False
                event.set_user(user)
                event.save()
            except:
                pass
            
    _clean_missing(resource_id, data.result, user)
Exemplo n.º 4
0
class EventsViewsTest(TestCase):
    "Events 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.event = Event(name='TestStatus', end=datetime.now())
            self.event.set_default_user()
            self.event.save()

            self.client = Client()

            self.prepared = True

    def test_unauthenticated_access(self):
        "Test index page at /api/calendar/events"
        response = self.client.get('/api/calendar/events')
        # Redirects as unauthenticated
        self.assertEquals(response.status_code, 401)

    def test_get_events_list(self):
        """ 
            Test index page api/infrastructure/types 
        """
        response = self.client.get(path=reverse('api_events'), **self.authentication_headers)
        self.assertEquals(response.status_code, 200)

    def test_get_field(self):
        response = self.client.get(path=reverse('api_events', kwargs={'object_ptr': self.event.id}), **self.authentication_headers)
        self.assertEquals(response.status_code, 200)

    def test_update_field(self):
        updates = {"name": "Api_name", "details": "Api details", "start": "2011-03-01 01:12:09", "end": "2011-03-09 13:05:09"}
        response = self.client.put(path=reverse('api_events', kwargs={'object_ptr': self.event.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'])
        self.assertEquals(data['start'], updates['start'])
        self.assertEquals(data['end'], updates['end'])