コード例 #1
0
    def test_create_client_existing_master(self):
        make_master('mas', 10, user=self.user)
        client = make_client(user=self.user, activated=False)
        token, _ = Token.objects.get_or_create(client=client)
        self.client = APIClient()
        self.client.credentials(HTTP_AUTHORIZATION=f'Token {token.key}')

        resp = self.client.post(reverse(ClientCreateView.view_name),
                                data={
                                    'first_name': 'VASYA',
                                    'gender': Gender.MALE,
                                    'date_of_birth': utils.get_date(-100),
                                    'tip': 10,
                                    'address': {
                                        'location': {
                                            'lat': 100,
                                            'lon': 100,
                                        },
                                        'city': 'kazan',
                                        'street_name': 'latstr',
                                        'building': '4',
                                        'floor': 2,
                                        'apt_number': 79,
                                        'entrance': 6,
                                        'has_intercom': True
                                    }
                                },
                                format='json')
        self.assertEqual(resp.status_code, status.HTTP_201_CREATED)
        # dat user
        self.user = PhoneAuthUser.objects.get(phone='777')
        self.assertIsNotNone(self.user.client)
        self.assertEqual(self.user.client.first_name, 'VASYA')
        self.assertIsNotNone(self.user.master)
        self.assertEqual(self.user.master.first_name, 'mas')
コード例 #2
0
    def setUp(self):
        # making an auth token
        vasya = make_master("VASYA", 11.0, about='a terrible master')
        petya = make_master("PETYA", 12.0)

        hands = make_category("Маникюр")

        for service in hands.services.all():
            vasya.services.add(service)
        vasya.save()

        for service in hands.services.all():
            petya.services.add(service)
        petya.save()

        # VASYA works on 0,+1, does manicure, got three slots
        schedule = Schedule.objects.create(master=vasya, date=timezone.now())
        schedule.save()

        TimeSlot.objects.create(time=Time.objects.create(hour=10, minute=30),
                                taken=False,
                                schedule=schedule)
        TimeSlot.objects.create(time=Time.objects.create(hour=11, minute=00),
                                taken=False,
                                schedule=schedule)
        TimeSlot.objects.create(time=Time.objects.create(hour=11, minute=30),
                                taken=False,
                                schedule=schedule)
        TimeSlot.objects.create(time=Time.objects.create(hour=12, minute=00),
                                taken=False,
                                schedule=schedule)

        # PETYA works on 0th
        schedule = Schedule.objects.create(master=petya, date=timezone.now())
        schedule.save()

        TimeSlot.objects.create(time=Time.objects.create(hour=10, minute=30),
                                taken=False,
                                schedule=schedule)
        TimeSlot.objects.create(time=Time.objects.create(hour=11, minute=00),
                                taken=False,
                                schedule=schedule)
        TimeSlot.objects.create(time=Time.objects.create(hour=11, minute=30),
                                taken=False,
                                schedule=schedule)
        TimeSlot.objects.create(time=Time.objects.create(hour=12, minute=30),
                                taken=False,
                                schedule=schedule)

        self.user = PhoneAuthUser.objects.create(phone='777')
        self.client_object = make_client(self.user)
        self.master_object = vasya

        token, _ = Token.objects.get_or_create(master=self.master_object)
        self.client = APIClient()
        self.client.credentials(HTTP_AUTHORIZATION=f'Token {token.key}')
コード例 #3
0
 def setUp(self):
     # make_everything()
     self.master_object = make_master('VASYA', 10)
     self.user = self.master_object.user
     token, _ = Token.objects.get_or_create(master=self.master_object)
     self.client = APIClient()
     self.client.credentials(HTTP_AUTHORIZATION=f'Token {token.key}')
コード例 #4
0
    def test_schedule_assign_time_end_of_day(self):
        master = make_master('master', 100)
        schedule = Schedule.objects.create(master=master, date=timezone.now())
        TimeSlot.objects.create(time=Time.objects.create(hour=10, minute=30),
                                taken=False,
                                schedule=schedule),
        TimeSlot.objects.create(time=Time.objects.create(hour=11, minute=00),
                                taken=False,
                                schedule=schedule),
        TimeSlot.objects.create(time=Time.objects.create(hour=11, minute=30),
                                taken=False,
                                schedule=schedule),
        TimeSlot.objects.create(time=Time.objects.create(hour=12, minute=00),
                                taken=False,
                                schedule=schedule),
        TimeSlot.objects.create(time=Time.objects.create(hour=12, minute=30),
                                taken=False,
                                schedule=schedule),

        next_time = schedule.assign_time(start_time=datetime.time(hour=12,
                                                                  minute=00),
                                         end_time=datetime.time(hour=13,
                                                                minute=00))

        self.assertIsNone(next_time)
        slots = schedule.time_slots.filter(time__value__in=['12:00', '12:30'],
                                           taken=True)
        self.assertEqual(len(slots), 2)
コード例 #5
0
 def setUp(self):
     make_category('Сервис')
     self.user = PhoneAuthUser.objects.create(phone='777')
     token, _ = Token.objects.get_or_create(
         master=make_master('mas', 10, user=self.user, activated=False,
                            make_balance=False))
     self.client = APIClient()
     self.client.credentials(HTTP_AUTHORIZATION=f'Token {token.key}')
コード例 #6
0
    def setUp(self):
        self.vasya = make_master('VASYA', 120)
        self.category = make_category('CATEGORY')
        for service in self.category.services.all():
            self.vasya.services.add(service)
        self.vasya.save()

        self.schedule = Schedule.objects.create(master=self.vasya,
                                                date=timezone.now())
        self.schedule.save()
コード例 #7
0
    def test_upload_not_client(self):
        master_user = make_master('123', 22)
        token, _ = Token.objects.get_or_create(master=master_user)

        self.client.credentials(HTTP_AUTHORIZATION=f'Token {token.key}')

        resp = self.client.patch(reverse(ClientAvatarUpdateView.view_name,
                                         args=[self.client_object.id]),
                                 data={'image': utils.make_in_memory_image(
                                     'avatar')})
        self.assertEqual(resp.status_code, status.HTTP_403_FORBIDDEN)
コード例 #8
0
    def test_schedule_assign_time_time_not_found(self):
        master = make_master('master', 100)
        schedule = Schedule.objects.create(master=master, date=timezone.now())
        TimeSlot.objects.create(time=Time.objects.create(hour=10, minute=30),
                                taken=False,
                                schedule=schedule),
        TimeSlot.objects.create(time=Time.objects.create(hour=11, minute=00),
                                taken=False,
                                schedule=schedule),
        TimeSlot.objects.create(time=Time.objects.create(hour=11, minute=30),
                                taken=False,
                                schedule=schedule),
        TimeSlot.objects.create(time=Time.objects.create(hour=12, minute=00),
                                taken=False,
                                schedule=schedule),
        TimeSlot.objects.create(time=Time.objects.create(hour=12, minute=30),
                                taken=False,
                                schedule=schedule),

        with self.assertRaises(ValueError):
            schedule.assign_time(start_time=datetime.time(hour=21, minute=10),
                                 end_time=datetime.time(hour=22, minute=00))
コード例 #9
0
def _make_everything():
    # making an auth token
    vasya = make_master("VASYA", 11.0, about='a terrible master')
    petya = make_master("PETYA", 12.0)

    hands = make_category("Маникюр")
    feet = make_category("Педикюр")

    make_display_item(hands)
    make_display_item(feet)
    make_display_item(hands, feet, name='4hands', special=True)

    for service in hands.services.all():
        vasya.services.add(service)
    vasya.save()

    token, _ = AppToken.objects.get_or_create(master=vasya,
                                              key='master_token')

    for service in feet.services.all():
        petya.services.add(service)
    petya.save()

    # VASYA works on +1,+2,+3 does manicure, got three slots
    schedule = Schedule.objects.create(master=vasya, date=utils.get_date(1))
    schedule.save()

    TimeSlot.objects.create(time=Time.objects.create(hour=11, minute=00),
                            taken=False, schedule=schedule)
    TimeSlot.objects.create(time=Time.objects.create(hour=11, minute=30),
                            taken=False, schedule=schedule)

    schedule = Schedule.objects.create(master=vasya, date=utils.get_date(2))
    schedule.save()

    TimeSlot.objects.create(time=Time.objects.create(hour=10, minute=30),
                            taken=False, schedule=schedule)
    TimeSlot.objects.create(time=Time.objects.create(hour=11, minute=00),
                            taken=False, schedule=schedule)
    TimeSlot.objects.create(time=Time.objects.create(hour=11, minute=30),
                            taken=False, schedule=schedule)
    TimeSlot.objects.create(time=Time.objects.create(hour=12, minute=00),
                            taken=False, schedule=schedule)

    schedule = Schedule.objects.create(master=vasya,
                                       date=utils.get_date(3))
    schedule.save()

    TimeSlot.objects.create(time=Time.objects.create(hour=12, minute=30),
                            taken=False, schedule=schedule)
    TimeSlot.objects.create(time=Time.objects.create(hour=13, minute=00),
                            taken=False, schedule=schedule)
    TimeSlot.objects.create(time=Time.objects.create(hour=13, minute=30),
                            taken=False, schedule=schedule)

    # PETYA works on +2th, +3th does pedicure, got all slots on +2, none on +3
    schedule = Schedule.objects.create(master=petya,
                                       date=utils.get_date(2))
    schedule.save()

    TimeSlot.objects.create(time=Time.objects.create(hour=10, minute=30),
                            taken=False, schedule=schedule)
    TimeSlot.objects.create(time=Time.objects.create(hour=11, minute=00),
                            taken=False, schedule=schedule)
    TimeSlot.objects.create(time=Time.objects.create(hour=11, minute=30),
                            taken=False, schedule=schedule)
    TimeSlot.objects.create(time=Time.objects.create(hour=12, minute=30),
                            taken=False, schedule=schedule)

    schedule = Schedule.objects.create(master=petya,
                                       date=utils.get_date(3))
    schedule.save()

    client = make_client(first_name='client')
    client2 = make_client(first_name='client2')
    client3 = make_client(first_name='john doe')
    token, _ = AppToken.objects.get_or_create(client=client,
                                              key='client_token')

    order, _ = make_order(client=client, service=hands.services.all()[0],
                          order_date=utils.get_date(2),
                          master=vasya, order_time='10:30')
    order, _ = make_order(client=client2, service=hands.services.all()[1],
                          order_date=utils.get_date(2),
                          master=vasya, order_time='11:30')

    # still got 2 slots on the first day
    order, _ = make_order(client=client3, service=hands.services.all()[0],
                          master=vasya, order_time='11:00',
                          order_date=utils.get_date(1),
                          status=OrderStatus.DONE)
    order.start()
    order.complete()
    order.save()
コード例 #10
0
 def setUp(self):
     self.master_object = make_master('123', 3)
     token = make_token(master=self.master_object)
     self.client = APIClient()
     self.client.credentials(HTTP_AUTHORIZATION=f'Token {token.key}')
コード例 #11
0
    def test_create_order__composite_4hands(self):
        vasya = Master.objects.get(first_name='VASYA')
        sanya = make_master("SANYA", 12.0)

        feet = ServiceCategory.objects.get(name="Педикюр")

        for service in feet.services.all():
            sanya.services.add(service)
        sanya.save()

        target_date = utils.get_date(1)
        schedule = Schedule.objects.create(master=sanya, date=target_date)
        schedule.save()

        TimeSlot.objects.create(time=Time.objects.create(hour=10, minute=30),
                                taken=True,
                                schedule=schedule)
        TimeSlot.objects.create(time=Time.objects.create(hour=11, minute=00),
                                taken=False,
                                schedule=schedule)
        TimeSlot.objects.create(time=Time.objects.create(hour=11, minute=30),
                                taken=False,
                                schedule=schedule)

        # two services, 2+1 for vasya, 2 for sanya
        resp = self.client.post(reverse(OrderListCreateView.view_name),
                                data={
                                    'date':
                                    target_date,
                                    'payment_type':
                                    'CARD',
                                    'time':
                                    '11:00',
                                    'order_items': [{
                                        'locked':
                                        False,
                                        'master_id':
                                        vasya.id,
                                        'service_ids':
                                        [vasya.services.first().id]
                                    }, {
                                        'locked':
                                        False,
                                        'master_id':
                                        sanya.id,
                                        'service_ids':
                                        [sanya.services.first().id]
                                    }],
                                    'special': {
                                        'type': 'composite'
                                    }
                                },
                                format='json')
        self.assertEqual(resp.status_code, status.HTTP_201_CREATED)

        vasya = Master.objects.get(first_name='VASYA')
        schedule = vasya.schedule.get(date=target_date)
        # assert timeslots are correctly set
        slots = schedule.time_slots.filter(
            time__value__in=['11:00', '11:30', '12:00'], taken=True)
        self.assertEqual(len(slots), 3)

        sanya = Master.objects.get(first_name='SANYA')
        schedule = sanya.schedule.get(date=target_date)
        # assert timeslots are correctly set
        slots = schedule.time_slots.filter(time__value__in=['11:00', '11:30'],
                                           taken=True)
        self.assertEqual(len(slots), 2)

        # assert order is created
        orders = Order.objects.all()
        self.assertTrue(len(orders), 1)

        order = orders[0]
        self.assertEqual(order.client, self.client_object)
        self.assertEqual(order.date.strftime('%Y-%m-%d'), target_date)
        self.assertEqual(order.time, datetime.time(hour=11, minute=0))
        self.assertEqual(len(order.order_items.all()), 2)
        order_item = order.order_items.all()[0]
        order_item_1 = order.order_items.all()[1]

        # assert order_items are created
        self.assertEqual(order_item.master, vasya)
        self.assertEqual(order_item.service, vasya.services.first())
        self.assertEqual(order_item_1.master, sanya)
        self.assertEqual(order_item_1.service, sanya.services.first())

        # assert future balance is correct
        self.assertEqual(
            vasya.balance.future,
            vasya.services.first().masters_share(
                self.client_object.tip_multiplier()))
        self.assertEqual(
            sanya.balance.future,
            sanya.services.first().masters_share(
                self.client_object.tip_multiplier()))
コード例 #12
0
 def setUp(self):
     self.master_object = make_master('VASYA', 10, make_portfolio=False)
     token, _ = Token.objects.get_or_create(master=self.master_object)
     self.client = APIClient()
     self.client.credentials(HTTP_AUTHORIZATION=f'Token {token.key}')
コード例 #13
0
    def test_complete_order_4hands(self):
        # creating a new master
        sanya = make_master('SANYA', 100)
        feet = make_category("Педикюр")

        for service in feet.services.all():
            sanya.services.add(service)
        sanya.save()
        # VASYA works on +1,+2 does manicure, got three slots
        date = utils.get_date(1)
        schedule = Schedule.objects.create(master=sanya, date=date)
        schedule.save()

        TimeSlot.objects.create(time=Time.objects.create(hour=10, minute=30),
                                taken=True,
                                schedule=schedule)
        TimeSlot.objects.create(time=Time.objects.create(hour=11, minute=00),
                                taken=False,
                                schedule=schedule)
        TimeSlot.objects.create(time=Time.objects.create(hour=11, minute=30),
                                taken=False,
                                schedule=schedule)

        vasya = Master.objects.get(first_name='VASYA')
        # manually creating an order with two masters and two services
        order_1, _ = make_order(client=self.client_object,
                                order_date=date,
                                master=vasya,
                                service=vasya.services.all()[0],
                                order_time=datetime.time(hour=11, minute=00))

        schedule = sanya.get_schedule(date)
        slot = schedule.get_slot(datetime.time(hour=11, minute=00))

        order_item = OrderItem.objects.create(service=sanya.services.all()[0],
                                              master=sanya,
                                              order=order_1,
                                              locked=False)
        slot.order_item = order_item
        slot.taken = True
        slot.save()

        order_1.time_started = timezone.now()
        order_1.status = OrderStatus.STARTED
        order_1.transaction = CloudPaymentsTransaction.objects.create(
            transaction_id=1, transaction_info={'info': 'yeah'})
        order_1.save()
        resp = self.client.patch(
            reverse(CompleteOrderView.view_name, args=[order_1.id]))

        self.assertEqual(resp.status_code, status.HTTP_200_OK)
        self.assertEqual(resp.data['transaction_id'], 1)

        order = Order.objects.get(pk=order_1.id)
        self.assertIsNotNone(order.time_taken)
        self.assertEqual(order.status, OrderStatus.DONE)

        vasya = Master.objects.get(first_name='VASYA')
        sanya = Master.objects.get(first_name='SANYA')

        self.assertEqual(
            vasya.balance.on_hold,
            int(vasya.services.all()[0].masters_share(
                self.client_object.tip_multiplier())))
        self.assertEqual(
            sanya.balance.on_hold,
            int(sanya.services.all()[0].masters_share(
                self.client_object.tip_multiplier())))