Conditions | 2 |
Total Lines | 51 |
Code Lines | 39 |
Lines | 51 |
Ratio | 100 % |
Changes | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
Methods with many parameters are not only hard to understand, but their parameters also often become inconsistent when you need more, or different data.
There are several approaches to avoid long parameter lists:
1 | """ |
||
49 | View Code Duplication | @patch('byceps.signals.ticketing.tickets_sold.send') |
|
50 | def test_create_tickets( |
||
51 | tickets_sold_signal_send_mock, |
||
52 | admin_app: Flask, |
||
53 | article: Article, |
||
54 | ticket_category: TicketCategory, |
||
55 | ticket_quantity: int, |
||
56 | admin_user: User, |
||
57 | orderer_user: User, |
||
58 | orderer: Orderer, |
||
59 | order: Order, |
||
60 | ) -> None: |
||
61 | tickets_before_paid = get_tickets_for_order(order) |
||
62 | assert len(tickets_before_paid) == 0 |
||
63 | |||
64 | shop_order_paid_event = mark_order_as_paid(order.id, admin_user.id) |
||
65 | |||
66 | tickets_after_paid = get_tickets_for_order(order) |
||
67 | assert len(tickets_after_paid) == ticket_quantity |
||
68 | |||
69 | for ticket in tickets_after_paid: |
||
70 | assert ticket.owned_by_id == orderer.user_id |
||
71 | assert ticket.used_by_id == orderer.user_id |
||
72 | |||
73 | log_entries = order_log_service.get_entries_for_order(order.id) |
||
74 | ticket_created_log_entries = [ |
||
75 | entry for entry in log_entries if entry.event_type == 'ticket-created' |
||
76 | ] |
||
77 | assert len(ticket_created_log_entries) == ticket_quantity |
||
78 | |||
79 | line_items_after = order_service.get_order(order.id).line_items |
||
80 | assert len(line_items_after) == 1 |
||
81 | |||
82 | ticket_line_item = line_items_after[0] |
||
83 | assert ticket_line_item.processing_result == { |
||
84 | 'ticket_ids': list( |
||
85 | sorted(str(ticket.id) for ticket in tickets_after_paid) |
||
86 | ), |
||
87 | } |
||
88 | |||
89 | tickets_sold_event = TicketsSold( |
||
90 | occurred_at=shop_order_paid_event.occurred_at, |
||
91 | initiator_id=admin_user.id, |
||
92 | initiator_screen_name=admin_user.screen_name, |
||
93 | party_id=ticket_category.party_id, |
||
94 | owner_id=orderer_user.id, |
||
95 | owner_screen_name=orderer_user.screen_name, |
||
96 | quantity=ticket_quantity, |
||
97 | ) |
||
98 | tickets_sold_signal_send_mock.assert_called_once_with( |
||
99 | None, event=tickets_sold_event |
||
100 | ) |
||
145 |