Conditions | 2 |
Total Lines | 60 |
Code Lines | 45 |
Lines | 60 |
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 | """ |
||
59 | View Code Duplication | @patch('byceps.signals.ticketing.tickets_sold.send') |
|
1 ignored issue
–
show
|
|||
60 | def test_create_ticket_bundles( |
||
61 | tickets_sold_signal_send_mock, |
||
62 | admin_app: Flask, |
||
63 | article: Article, |
||
64 | ticket_category: TicketCategory, |
||
65 | ticket_quantity_per_bundle: int, |
||
66 | bundle_quantity: int, |
||
67 | admin_user: User, |
||
68 | orderer_user: User, |
||
69 | orderer: Orderer, |
||
70 | order: Order, |
||
71 | ) -> None: |
||
72 | expected_ticket_total = 10 |
||
73 | |||
74 | tickets_before_paid = get_tickets_for_order(order) |
||
75 | assert len(tickets_before_paid) == 0 |
||
76 | |||
77 | shop_order_paid_event = mark_order_as_paid(order.id, admin_user.id) |
||
78 | |||
79 | tickets_after_paid = get_tickets_for_order(order) |
||
80 | assert len(tickets_after_paid) == expected_ticket_total |
||
81 | |||
82 | for ticket in tickets_after_paid: |
||
83 | assert ticket.owned_by_id == orderer.user_id |
||
84 | assert ticket.used_by_id == orderer.user_id |
||
85 | |||
86 | log_entries = order_log_service.get_entries_for_order(order.id) |
||
87 | ticket_bundle_created_log_entries = [ |
||
88 | entry |
||
89 | for entry in log_entries |
||
90 | if entry.event_type == 'ticket-bundle-created' |
||
91 | ] |
||
92 | assert len(ticket_bundle_created_log_entries) == bundle_quantity |
||
93 | |||
94 | line_items_after = order_service.get_order(order.id).line_items |
||
95 | assert len(line_items_after) == 1 |
||
96 | |||
97 | bundle_ids = {ticket.bundle_id for ticket in tickets_after_paid} |
||
98 | ticket_bundle_line_item = line_items_after[0] |
||
99 | assert ticket_bundle_line_item.processing_result == { |
||
100 | 'ticket_bundle_ids': list( |
||
101 | sorted(str(bundle_id) for bundle_id in bundle_ids) |
||
102 | ), |
||
103 | } |
||
104 | |||
105 | tickets_sold_event = TicketsSold( |
||
106 | occurred_at=shop_order_paid_event.occurred_at, |
||
107 | initiator_id=admin_user.id, |
||
108 | initiator_screen_name=admin_user.screen_name, |
||
109 | party_id=ticket_category.party_id, |
||
110 | owner_id=orderer_user.id, |
||
111 | owner_screen_name=orderer_user.screen_name, |
||
112 | quantity=expected_ticket_total, |
||
113 | ) |
||
114 | tickets_sold_signal_send_mock.assert_called_once_with( |
||
115 | None, event=tickets_sold_event |
||
116 | ) |
||
117 | |||
118 | tear_down_bundles(tickets_after_paid) |
||
119 | |||
132 |