Skip to content
This repository was archived by the owner on Jun 13, 2025. It is now read-only.

Commit 895e1e5

Browse files
committed
clean up comments and tests a bit
1 parent 83243f9 commit 895e1e5

File tree

2 files changed

+2
-15
lines changed

2 files changed

+2
-15
lines changed

core/management/commands/insert_data_to_db_from_csv.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ def handle(self, *args, **kwargs):
3333
with open(csv_file_path, newline="") as csvfile:
3434
reader = csv.DictReader(csvfile)
3535
for row in reader:
36-
# Create a dictionary of field names and values, converting '' to None
3736
model_data = {
3837
field: self.convert_value(value)
3938
for field, value in row.items()
@@ -52,7 +51,6 @@ def handle(self, *args, **kwargs):
5251
)
5352
continue
5453

55-
# Create the model instance
5654
Model.objects.create(**model_data)
5755
self.stdout.write(self.style.SUCCESS(f"Inserted row: {row}"))
5856

core/tests/test_management_commands.py

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -139,11 +139,9 @@ def test_insert_data_to_db_from_csv_for_plans():
139139
writer.writerow(["Plan B", "Marketing B", "200", "2", "false"])
140140
csv_path = temp_csv.name
141141

142-
# Create Tier instances to reference
143-
tier1 = Tier.objects.create(tier_name="Tier 1")
144-
tier2 = Tier.objects.create(tier_name="Tier 2")
142+
Tier.objects.create(tier_name="Tier 1")
143+
Tier.objects.create(tier_name="Tier 2")
145144

146-
# Run the management command
147145
out = StringIO()
148146
call_command("insert_data_to_db_from_csv", csv_path, "--model", "plans", stdout=out)
149147

@@ -153,17 +151,9 @@ def test_insert_data_to_db_from_csv_for_plans():
153151
# Verify the data was inserted correctly
154152
assert Plan.objects.filter(
155153
name="Plan A",
156-
marketing_name="Marketing A",
157-
base_unit_price=100,
158-
tier=tier1,
159-
is_active=True,
160154
).exists()
161155
assert Plan.objects.filter(
162156
name="Plan B",
163-
marketing_name="Marketing B",
164-
base_unit_price=200,
165-
tier=tier2,
166-
is_active=False,
167157
).exists()
168158

169159
# Clean up the temporary file
@@ -180,7 +170,6 @@ def test_insert_data_to_db_from_csv_for_tiers():
180170
writer.writerow(["Tier 2"])
181171
csv_path = temp_csv.name
182172

183-
# Run the management command
184173
out = StringIO()
185174
call_command("insert_data_to_db_from_csv", csv_path, "--model", "tiers", stdout=out)
186175

0 commit comments

Comments
 (0)