def post(self, request): title = request.data.get('title') text = request.data.get('text') link = request.data.get('link', 'No link') user = request.user close_date = request.data.get('closeDate', '2424-2-2') if not close_date: close_date = '2424-2-2' participants = request.data.get('participants', []) selects = request.data.get('selects') meeting = Meeting(title=title, text=text, owner=user) meeting.save() poll = Poll(title=title, text=text, meeting=meeting) if close_date: poll.date_close = datetime.datetime.strptime( close_date, '%Y-%m-%d') poll.save() meetingParticipant = MeetingParticipant(meeting=meeting, participant=user) meetingParticipant.save() link += str(poll.id) self.create_participants(meeting, participants, user) self.createOptions(poll, selects) check_poll_close(poll) poll_json = serializers.serialize('json', [poll]) send_email_create_poll(user, title, link, participants) try: return HttpResponse(poll_json, content_type='application/json') except Exception as e: print(e) return HttpResponse404Error("This poll doesn\'t exist.")
def test_cannot_retrieve_others_meetings_details(self): meeting = Meeting(organiser=get_user_model().objects.exclude( id=self.user.id).first()) meeting.save() self.assertEqual( self.get(url=self.url.format(meeting.id)).status_code, status.HTTP_403_FORBIDDEN)
def create_meeting(organiser): meeting = Meeting(organiser=organiser) meeting.save() Participant(meeting=meeting, user=organiser, accepted=True).save() choices = [True, False, None] for i, user in enumerate( get_user_model().objects.exclude(id=organiser.id).all()): Participant(meeting=meeting, user=user, accepted=choices[i % 3]).save() return meeting
def setUp(self): super().setUp() self.longitude = 0.171 self.latitude = 0.155 meeting = Meeting(organiser=self.user) meeting.save() place = Place(latitude=self.latitude, longitude=self.longitude) place.save() Participant(meeting=meeting, place=place, user=self.user).save()
def test_cannot_accept_meeting_where_i_am_not_invited(self): user = get_user_model().objects.create_user( email="*****@*****.**", password=None, ) meeting = Meeting(organiser=user) meeting.save() self.assertEqual( self.put(dict(), url=self.url.format(meeting.id)).status_code, status.HTTP_404_NOT_FOUND)
def setUp(self): super().setUp() friend = get_user_model().objects.create_user( email="*****@*****.**", password=None, ) friend.save() self.meeting = Meeting(organiser=friend) self.meeting.save() self.participant = Participant(meeting=self.meeting, user=self.user) self.participant.save()
def _create_meeting(self, meeting_time, user_ids): meeting = Meeting(organiser_id=1) meeting.save() meeting.start_time = meeting_time meeting.save() for _id in user_ids: Participant(meeting=meeting, user_id=_id).save() return meeting_time.strftime("%Y-%m-%dT00:00:00Z")
def create_meeting(request): form = CreateMeetingForm(request.POST or None) if (form.is_valid()): subject = form.cleaned_data['meeting_subject'] descripton = form.cleaned_data['meeting_description'] start_time = form.cleaned_data['meeting_starttime'] organizer = request.user meeting = Meeting.create_meeting(subject=subject, descripton=descripton, start_time=start_time, organizer=organizer) meeting.save() # create the organizer in the Relate table organizer_relate = Relate.objects.create(user=organizer, meeting=meeting, role='ORGANIZER', status='PRESENT') # email_list is the raw input from the form email_list = form.cleaned_data['meeting_members'].strip(',').split(',') # member_list is the list of User objects from the DB member_list = [] for member in email_list: try: member_list.append(User.objects.get(email=member)) except models.ObjectDoesNotExist: member_list.append(None) # loop through invited members and create them in the Relate table for member in member_list: if (member): relate = Relate.objects.create(user=member, meeting=meeting, role='MEMBER', status='INVITED') relate.save() return redirect('meeting:meeting-room', meeting.url) else: return render(request, 'index.html', {'create_meeting': form})
class ParticipantsDetailsEndpointTestCase(APIEndpointTestCase): url = API_V1 + "meetings/{}/participants/" def setUp(self): super().setUp() friend = get_user_model().objects.create_user( email="*****@*****.**", password=None, ) friend.save() self.meeting = Meeting(organiser=friend) self.meeting.save() self.participant = Participant(meeting=self.meeting, user=self.user) self.participant.save() def test_cannot_access_participant_unauthenticated(self): self.assertEqual( self.put(dict(), url=self.url.format(self.participant.id)).status_code, status.HTTP_401_UNAUTHORIZED) @authenticated def test_cannot_accept_meeting_where_i_am_not_invited(self): user = get_user_model().objects.create_user( email="*****@*****.**", password=None, ) meeting = Meeting(organiser=user) meeting.save() self.assertEqual( self.put(dict(), url=self.url.format(meeting.id)).status_code, status.HTTP_404_NOT_FOUND) @authenticated def test_can_accept_meeting(self): self.assertEqual( self.put(dict(accepted=True), url=self.url.format(self.meeting.id)).status_code, status.HTTP_200_OK) self.assertTrue( Participant.objects.get(user=self.participant.id).accepted) @authenticated def test_can_refuse_meeting(self): self.assertEqual( self.put(dict(accepted=False), url=self.url.format(self.meeting.id)).status_code, status.HTTP_200_OK) self.assertFalse( Participant.objects.get(user=self.participant.id).accepted) @authenticated def test_can_cancel_meeting(self): self.participant.accepted = True self.participant.save() self.assertEqual( self.put(dict(accepted=False), url=self.url.format(self.meeting.id)).status_code, status.HTTP_200_OK) self.assertFalse( Participant.objects.get(user=self.participant.id).accepted) @authenticated def test_cannot_update_refused_meeting(self): self.participant.accepted = False self.participant.save() self.assertEqual( self.put(dict(), url=self.url.format(self.meeting.id)).status_code, status.HTTP_400_BAD_REQUEST) @authenticated def test_can_be_arrived_to_meeting(self): self.participant.accepted = True self.participant.save() self.assertEqual( self.put(dict(arrived=True), url=self.url.format(self.meeting.id)).status_code, status.HTTP_200_OK) self.assertTrue( Participant.objects.get(user=self.participant.id).arrived) @authenticated def test_cannot_be_arrived_to_meeting_without_accepted(self): self.assertEqual( self.put(dict(arrived=True), url=self.url.format(self.meeting.id)).status_code, status.HTTP_400_BAD_REQUEST) self.assertFalse( Participant.objects.get(user=self.participant.id).arrived) @authenticated def test_cannot_set_not_arrived(self): self.assertEqual( self.put(dict(arrived=False), url=self.url.format(self.meeting.id)).status_code, status.HTTP_400_BAD_REQUEST) @authenticated def test_cannot_update_finished_meeting(self): self.meeting.status = Meeting.STATUS_ENDED self.meeting.save(update_fields=("status", )) self.assertEqual( self.put(dict(), url=self.url.format(self.meeting.id)).status_code, status.HTTP_400_BAD_REQUEST) @authenticated def test_cannot_update_canceled_meeting(self): self.meeting.status = Meeting.STATUS_CANCELED self.meeting.save(update_fields=("status", )) self.assertEqual( self.put(dict(), url=self.url.format(self.meeting.id)).status_code, status.HTTP_400_BAD_REQUEST)
def test_can_get_meeting_in_which_we_participate(self): meeting = Meeting(organiser=get_user_model().objects.last()) meeting.save() Participant(meeting=meeting, user=self.user).save() self.assertEqual(len(self.get().json()), 1)
def test_can_get_own_meetings(self): meeting = Meeting(organiser=self.user) meeting.save() Participant(meeting=meeting, user=self.user).save() self.assertEqual(len(self.get().json()), 1)
def test_cannot_get_others_meetings(self): Meeting(organiser=get_user_model().objects.last()).save() self.assertEqual(len(self.get().json()), 0)