def test_schedule_2_people_to_a_paired_lesson(self): customer1 = create_customer() customer2 = create_customer() paired_lesson = mixer.blend(lessons.PairedLesson, slots=2, host=self.host) customer1_class = Class( customer=customer1, lesson_type=paired_lesson.get_contenttype(), ) customer1_class.save() customer2_class = Class( customer=customer2, lesson_type=paired_lesson.get_contenttype(), ) customer2_class.save() timeline_entry = mixer.blend(TimelineEntry, lesson=paired_lesson, teacher=self.host, start=self.tzdatetime(2032, 12, 1)) customer1_class.assign_entry(timeline_entry) customer1_class.save() customer2_class.assign_entry(timeline_entry) customer2_class.save() self.assertTrue(customer1_class.is_scheduled) self.assertTrue(customer2_class.is_scheduled) self.assertEqual(timeline_entry.taken_slots, 2) customer2_class.cancel() self.assertEqual(timeline_entry.taken_slots, 1)
def setUp(self): self.customer = create_customer() self.subscription = Subscription( customer=self.customer, product=Product1.objects.get(pk=1), buy_price=150, ) self.deactivator = create_customer().user
def test_can_cancel_classes(self): customer = create_customer() self.assertTrue(customer.can_cancel_classes()) customer.cancellation_streak = 5 customer.max_cancellation_count = 5 self.assertFalse(customer.can_cancel_classes())
def test_two_classes_pre_start_notification(self, Owl): self.lesson = mixer.blend('lessons.MasterClass', host=self.host, slots=5) other_customer = create_customer() first_customer = self.customer entry = self._create_entry() entry.slots = 5 entry.save() c = self._buy_a_lesson() self._schedule(c, entry) self.customer = other_customer c1 = self._buy_a_lesson() self._schedule(c1, entry) with freeze_time('2032-09-13 15:46'): # entry will start in 14 minutes for i in range(0, 10): # run this 10 times to check for repietive emails — all notifications should be sent one time notify_15min_to_class() self.assertEqual(len(mail.outbox), 3) # if this test fails, carefully check the timezone you are in out_emails = [outbox.to[0] for outbox in mail.outbox] self.assertIn(self.host.user.email, out_emails) self.assertIn(first_customer.user.email, out_emails) self.assertIn(other_customer.user.email, out_emails)
def test_one_of_multiple_classes(self): """ 1. Buy two classes 2. Schedule both of them for single timeline entry with 5 slots. 3. Move to the future 4. Assure it is not cancellable in the normal way 5. Dangerously_unschedule() on of them 6. Check if timeline entry has only one remaining slot """ self.lesson = mixer.blend(lessons.MasterClass, host=self.host, slots=5) entry = self._create_entry() entry.slots = 5 entry.save() c = self._buy_a_lesson() self._schedule(c, entry) self.customer = create_customer() # create another customer c1 = self._buy_a_lesson() self._schedule(c1, entry) with freeze_time('2032-09-15 15:00'): # now entry is in past c.cancel(src='dangerous-cancellation') entry.refresh_from_db() self.assertEqual(entry.taken_slots, 1)
def test_staff_only(self): someone = create_customer(password='******') self.c.logout() self.c.login(username=someone.user.username, password='******') response = self.c.get('/crm/mailchimp_csv/%d' % self.customers[0].pk) self.assertRedirectsPartial(response, '/accounts/login')
def test_staff_only(self): someone = create_customer(password='******') self.c.logout() self.c.login(username=someone.user.username, password='******') response = self.c.get('/crm/export_last_lessons/%s/start/2016-01-12/end/2033-01-01/' % self.customer.pk) self.assertRedirectsPartial(response, '/accounts/login')
def test_originator_customers_multiple(self): """ Add a second customer to the timeline entry and check if originator_customer will return it. 1) set slot count of a lesson to 5 2) update the timeline entry (calling save()) to set it's slot count 3) schedule a class of another customer 4) ??? 5) check originator_customers """ self.lesson.slots = 5 # set lesson slots to 5, to update timeine entry slot count self.lesson.save() self.entry.save() other_customer = create_customer() self._buy_a_lesson(customer=other_customer) self._schedule(customer=other_customer) ev = AccEvent( teacher=self.host, originator=self.entry, event_type='class', ) ev.save() self.assertEqual(len(ev.originator_customers), 2) self.assertIn(other_customer, ev.originator_customers) self.assertIn(self.customer, ev.originator_customers)
def test_list_of_students_to_add(self): """ Check the student selector for adding to the timeline entry """ c1 = Class( customer=self.customer, lesson_type=self.lesson.get_contenttype(), ) other_customer = create_customer() c2 = Class( customer=other_customer, lesson_type=self.lesson.get_contenttype(), ) c1.assign_entry(self.entry) c1.save() c2.save() response = self.c.get(self.entry.get_absolute_url()) with self.assertHTML(response, 'select.add-a-student__selector>option') as options: self.assertEqual(len(options), 2) # the first one is 'zero-option' self.assertEqual(options[1].attrib.get('value'), reverse('timeline:add_customer', kwargs={ 'username': self.teacher.user.username, 'pk': self.entry.pk, 'customer': other_customer.pk, })) # the second — is the student with c2
def test_api_permissions(self): someone = create_customer(password='******') self.c.logout() self.c.login(username=someone.user.username, password='******') response = self.c.get('/api/timeline/') self.assertEqual(response.status_code, 403)
def setUpTestData(cls): cls.customer = create_customer() cls.host = create_teacher() mixer.blend(WorkingHours, teacher=cls.host, weekday=0, start='13:00', end='15:00') # monday
def setUp(self): self.customer = create_customer(timezone='Africa/Addis_Ababa') self.customer.user.username = '******' self.customer.user.set_password('123') self.customer.user.save() self.c.logout() self.c.login(username='******', password='******')
def test_invalid_timezone(self): """ Assign an invalid timezone to the customer """ c = create_customer() with self.assertRaises(ValidationError): c.timezone = 'Noga/Test' c.save()
def setUpClass(cls): super().setUpClass() cls.product = Product1.objects.get(pk=1) cls.product_type = ContentType.objects.get_for_model(cls.product) cls.customer = create_customer() cls.cost = Money(31.5, RUB) cls.tpl = Template("{% load stripe_form from stripe %} {% stripe_form 'Pay by card' 'btn-primary' product cost customer %}")
def test_add_student_fail_due_to_no_class(self): some_other_customer = create_customer() url = reverse('timeline:add_customer', kwargs={ 'username': self.teacher.user.username, 'pk': self.entry.pk, 'customer': some_other_customer.pk, }) response = self.c.get(url) self.assertEqual(response.status_code, 404) # should throw an error, because customer hasn't any class
def setUp(self): self.product = Product1.objects.get(pk=1) self.product_type = ContentType.objects.get_for_model(self.product) self.customer = create_customer(password='******') self.cost = Money(300, RUB) self.c.logout() self.c.login(username=self.customer.user.username, password="******")
def test_can_schedule_classes(self): customer = create_customer() self.assertFalse(customer.can_schedule_classes()) c = Class( lesson_type=lessons.OrdinaryLesson.get_contenttype(), customer=customer ) c.save() self.assertTrue(customer.can_schedule_classes())
def setUpTestData(cls): cls.customer = create_customer() cls.teacher = create_teacher(works_24x7=True) cls.subscription = Subscription( customer=cls.customer, product=Product1.objects.get(pk=1), buy_price=150, ) cls.subscription.save()
def test_write_admin_log_entry(self): Class = apps.get_model('market.Class') c = Class(customer=self.customer, lesson_type=lessons.OrdinaryLesson.get_contenttype()) user = create_customer().user write_admin_log_entry(user, c, msg='Testing') log_entry = LogEntry.objects.first() self.assertEqual(log_entry.change_message, 'Testing') self.assertEqual(log_entry.user, user)
def test_404_for_others_classes(self): c = self._buy_a_lesson() self._schedule(c) request = self.factory.get('/market/cancel/11/popup') other_customer = create_customer() request.user = other_customer.user with self.assertRaises(Http404): views.cancel_popup(request, c.pk) with self.assertRaises(Http404): views.cancel(request, c.pk)
def test_user_model(self): """ Customer objects with assigned django user should take user data from the django table. """ customer = create_customer() customer.user.first_name = 'Fedor' customer.user.last_name = 'Borshev' customer.user.email = '*****@*****.**' customer.user.save() self.assertEqual(customer.full_name, 'Fedor Borshev') self.assertEqual(customer.first_name, 'Fedor') self.assertEqual(customer.last_name, 'Borshev') self.assertEqual(customer.email, '*****@*****.**')
def test_multiple_customers(self): """ 1. Buy a lesson for customer, schedule it 2. Buy the same lesson for another customer 3. Mark lesson is finished 4. Check completed_lesson report for this customer * Should contain two customers * Should contain only one record because two customers were on the same lesson """ self.lesson = mixer.blend('lessons.MasterClass', host=self.host, slots=5) c = self._buy_a_lesson() entry = self._create_entry() entry.slots = 5 entry.save() self._schedule(c, entry) first_customer = self.customer second_customer = self.customer = create_customer() c1 = self._buy_a_lesson() self._schedule(c1, entry) TimelineEntry.objects.filter(classes__customer=self.customer).update(is_finished=True) # mark as finished response = self.c.get('/crm/export_last_lessons/%s/start/2016-01-12/end/2033-01-01/' % ','.join([str(first_customer.pk), str(second_customer.pk)])) self.assertEqual(response.status_code, 200) content = response.content.decode('utf-8').strip().split('\n') got = list(csv.reader(content, delimiter="\t")) self.assertEqual(len(got), 2) # 3 here meens that two customers that were on a a single lesson are shown in one row completed_class = got[1] self.assertIsNotNone(completed_class[0]) self.assertIn(str(first_customer), completed_class[1]) self.assertIn(str(second_customer), completed_class[1]) self.assertEqual(completed_class[2], self.host.user.crm.full_name) self.assertIsNotNone(completed_class[3])
def test_multiple_classes(self): """ The same as above but with two classes to check how account record deletion works when entry autodeletion is not invoked. """ self.lesson = mixer.blend(lessons.MasterClass, host=self.host, slots=5) entry = self._create_entry() entry.slots = 5 entry.save() c = self._buy_a_lesson() self._schedule(c, entry) self.customer = create_customer() # create another customer c1 = self._buy_a_lesson() self._schedule(c1, entry) entry.refresh_from_db( ) # we have the same entry here because the lesson is hosted with freeze_time('2032-09-15 15:00'): # now entry is in past bill_timeline_entries() ev = AccEvent.objects.by_originator(entry).first() self.assertIsNotNone(ev) entry.delete(src='dangerous-cancellation') with self.assertRaises(ObjectDoesNotExist): ev.refresh_from_db( ) # the accounting event should be dropped while unscheduling the last class c.refresh_from_db() c1.refresh_from_db() self.assertFalse(c.is_scheduled) self.assertFalse(c.is_fully_used) self.assertFalse(c1.is_scheduled) self.assertFalse(c1.is_fully_used)
def setUpTestData(cls): cls.customer = create_customer() cls.product = products.Product1.objects.get(pk=cls.TEST_PRODUCT_ID)
def setUp(self): self.host = create_teacher(works_24x7=True) self.customer = create_customer()
def setUp(self): self.customer = create_customer()
def setUpTestData(cls): cls.customers = [] for i in range(0, 10): cls.customers.append(create_customer())
def setUp(self): self.customer = create_customer() self.trial_lesson = mixer.blend('lessons.TrialLesson') self.ordinary_lesson = mixer.blend('lessons.OrdinaryLesson')
def setUp(self): self.teacher = create_teacher() self.customer = create_customer()
def setUp(self): self.customer = create_customer() self.teacher = create_teacher(works_24x7=True) self.lesson = lessons.OrdinaryLesson.get_default()