|
8 | 8 |
|
9 | 9 | from feed.models import FeedEntry |
10 | 10 | from feed.serializers import ( |
11 | | - ActivityFeedEntrySerializer, |
| 11 | + |
12 | 12 | CommentSerializer, |
13 | 13 | ContentObjectSerializer, |
14 | 14 | FeedEntrySerializer, |
@@ -2447,204 +2447,6 @@ def test_fundraise_without_application_has_no_associated_grants( |
2447 | 2447 | self.assertEqual(serializer.data["associated_grants"], []) |
2448 | 2448 |
|
2449 | 2449 |
|
2450 | | -class ActivityFeedEntrySerializerTests(AWSMockTestCase): |
2451 | | - """ |
2452 | | - Test cases for the ActivityFeedEntrySerializer. |
2453 | | - """ |
2454 | | - |
2455 | | - def setUp(self): |
2456 | | - super().setUp() |
2457 | | - self.user = create_random_default_user("activity_feed_user") |
2458 | | - |
2459 | | - def _create_feed_entry(self, unified_doc, post): |
2460 | | - return FeedEntry.objects.create( |
2461 | | - content_type=ContentType.objects.get_for_model(ResearchhubPost), |
2462 | | - object_id=post.id, |
2463 | | - user=self.user, |
2464 | | - action="PUBLISH", |
2465 | | - action_date=post.created_date, |
2466 | | - unified_document=unified_doc, |
2467 | | - ) |
2468 | | - |
2469 | | - def _create_fundraise_post(self): |
2470 | | - unified_doc = ResearchhubUnifiedDocument.objects.create( |
2471 | | - document_type=document_type.PREREGISTRATION, |
2472 | | - ) |
2473 | | - post = ResearchhubPost.objects.create( |
2474 | | - title="Prereg Post", |
2475 | | - created_by=self.user, |
2476 | | - document_type=document_type.PREREGISTRATION, |
2477 | | - renderable_text="A preregistration post", |
2478 | | - unified_document=unified_doc, |
2479 | | - ) |
2480 | | - return unified_doc, post |
2481 | | - |
2482 | | - def _create_purchase(self, fundraise, user, amount): |
2483 | | - ct = ContentType.objects.get_for_model(Fundraise) |
2484 | | - return Purchase.objects.create( |
2485 | | - user=user, |
2486 | | - content_type=ct, |
2487 | | - object_id=fundraise.id, |
2488 | | - purchase_type=Purchase.FUNDRAISE_CONTRIBUTION, |
2489 | | - purchase_method=Purchase.OFF_CHAIN, |
2490 | | - amount=str(amount), |
2491 | | - ) |
2492 | | - |
2493 | | - def _create_usd_contribution(self, fundraise, user, amount_cents): |
2494 | | - return UsdFundraiseContribution.objects.create( |
2495 | | - user=user, |
2496 | | - fundraise=fundraise, |
2497 | | - amount_cents=amount_cents, |
2498 | | - fee_cents=int(amount_cents * 0.09), |
2499 | | - origin_fund_id="test-origin", |
2500 | | - destination_org_id="test-destination", |
2501 | | - ) |
2502 | | - |
2503 | | - def test_contributions_none_without_fundraise(self): |
2504 | | - """Feed entry on a regular post should have contributions=None.""" |
2505 | | - # Arrange |
2506 | | - unified_doc = ResearchhubUnifiedDocument.objects.create( |
2507 | | - document_type=document_type.DISCUSSION, |
2508 | | - ) |
2509 | | - post = ResearchhubPost.objects.create( |
2510 | | - title="Discussion Post", |
2511 | | - created_by=self.user, |
2512 | | - document_type=document_type.DISCUSSION, |
2513 | | - renderable_text="Just a discussion", |
2514 | | - unified_document=unified_doc, |
2515 | | - ) |
2516 | | - feed_entry = self._create_feed_entry(unified_doc, post) |
2517 | | - |
2518 | | - # Act |
2519 | | - serializer = ActivityFeedEntrySerializer(feed_entry) |
2520 | | - |
2521 | | - # Assert |
2522 | | - self.assertIsNone(serializer.data["contributions"]) |
2523 | | - |
2524 | | - @patch( |
2525 | | - "purchase.related_models.rsc_exchange_rate_model.RscExchangeRate.get_latest_exchange_rate" |
2526 | | - ) |
2527 | | - def test_contributions_empty_with_fundraise_no_purchases(self, mock_usd_to_rsc): |
2528 | | - """Fundraise with no purchases should return total=0, top=[].""" |
2529 | | - # Arrange |
2530 | | - mock_usd_to_rsc.return_value = 1.0 |
2531 | | - |
2532 | | - unified_doc, post = self._create_fundraise_post() |
2533 | | - Fundraise.objects.create( |
2534 | | - unified_document=unified_doc, |
2535 | | - created_by=self.user, |
2536 | | - goal_amount=Decimal("100.00"), |
2537 | | - goal_currency=USD, |
2538 | | - status=Fundraise.OPEN, |
2539 | | - ) |
2540 | | - feed_entry = self._create_feed_entry(unified_doc, post) |
2541 | | - |
2542 | | - # Act |
2543 | | - serializer = ActivityFeedEntrySerializer(feed_entry) |
2544 | | - contributions = serializer.data["contributions"] |
2545 | | - |
2546 | | - # Assert |
2547 | | - self.assertEqual(contributions["total"], 0) |
2548 | | - self.assertEqual(contributions["top"], []) |
2549 | | - |
2550 | | - @patch( |
2551 | | - "purchase.related_models.rsc_exchange_rate_model.RscExchangeRate.get_latest_exchange_rate" |
2552 | | - ) |
2553 | | - def test_contributions_single_contributor(self, mock_usd_to_rsc): |
2554 | | - """Single purchase should produce one contributor entry.""" |
2555 | | - # Arrange |
2556 | | - mock_usd_to_rsc.return_value = 1.0 |
2557 | | - |
2558 | | - unified_doc, post = self._create_fundraise_post() |
2559 | | - fundraise = Fundraise.objects.create( |
2560 | | - unified_document=unified_doc, |
2561 | | - created_by=self.user, |
2562 | | - goal_amount=Decimal("500.00"), |
2563 | | - goal_currency=USD, |
2564 | | - status=Fundraise.OPEN, |
2565 | | - ) |
2566 | | - self._create_purchase(fundraise, self.user, 50.0) |
2567 | | - feed_entry = self._create_feed_entry(unified_doc, post) |
2568 | | - |
2569 | | - # Act |
2570 | | - serializer = ActivityFeedEntrySerializer(feed_entry) |
2571 | | - contributions = serializer.data["contributions"] |
2572 | | - |
2573 | | - # Assert |
2574 | | - self.assertEqual(contributions["total"], 1) |
2575 | | - self.assertEqual(len(contributions["top"]), 1) |
2576 | | - top_entry = contributions["top"][0] |
2577 | | - self.assertEqual(top_entry["total_contribution"]["rsc"], 50.0) |
2578 | | - self.assertEqual(top_entry["total_contribution"]["usd"], 0) |
2579 | | - self.assertEqual(len(top_entry["contributions"]), 1) |
2580 | | - self.assertEqual(top_entry["contributions"][0]["amount"], 50.0) |
2581 | | - self.assertEqual(top_entry["contributions"][0]["currency"], "RSC") |
2582 | | - |
2583 | | - @patch( |
2584 | | - "purchase.related_models.rsc_exchange_rate_model.RscExchangeRate.get_latest_exchange_rate" |
2585 | | - ) |
2586 | | - def test_contributions_multiple_purchases_aggregated(self, mock_usd_to_rsc): |
2587 | | - """Multiple purchases by the same user should be aggregated.""" |
2588 | | - # Arrange |
2589 | | - mock_usd_to_rsc.return_value = 1.0 |
2590 | | - |
2591 | | - unified_doc, post = self._create_fundraise_post() |
2592 | | - fundraise = Fundraise.objects.create( |
2593 | | - unified_document=unified_doc, |
2594 | | - created_by=self.user, |
2595 | | - goal_amount=Decimal("1000.00"), |
2596 | | - goal_currency=USD, |
2597 | | - status=Fundraise.OPEN, |
2598 | | - ) |
2599 | | - self._create_purchase(fundraise, self.user, 30.0) |
2600 | | - self._create_purchase(fundraise, self.user, 70.0) |
2601 | | - feed_entry = self._create_feed_entry(unified_doc, post) |
2602 | | - |
2603 | | - # Act |
2604 | | - serializer = ActivityFeedEntrySerializer(feed_entry) |
2605 | | - contributions = serializer.data["contributions"] |
2606 | | - |
2607 | | - # Assert |
2608 | | - self.assertEqual(contributions["total"], 1) |
2609 | | - top_entry = contributions["top"][0] |
2610 | | - self.assertEqual(top_entry["total_contribution"]["rsc"], 100.0) |
2611 | | - self.assertEqual(top_entry["total_contribution"]["usd"], 0) |
2612 | | - self.assertEqual(len(top_entry["contributions"]), 2) |
2613 | | - |
2614 | | - @patch( |
2615 | | - "purchase.related_models.rsc_exchange_rate_model.RscExchangeRate.get_latest_exchange_rate" |
2616 | | - ) |
2617 | | - def test_contributions_include_usd_contributions(self, mock_usd_to_rsc): |
2618 | | - """RSC and USD contributions from the same user should both appear.""" |
2619 | | - # Arrange |
2620 | | - mock_usd_to_rsc.return_value = 1.0 |
2621 | | - |
2622 | | - unified_doc, post = self._create_fundraise_post() |
2623 | | - fundraise = Fundraise.objects.create( |
2624 | | - unified_document=unified_doc, |
2625 | | - created_by=self.user, |
2626 | | - goal_amount=Decimal("500.00"), |
2627 | | - goal_currency=USD, |
2628 | | - status=Fundraise.OPEN, |
2629 | | - ) |
2630 | | - contributor = create_random_default_user("mixed_contributor") |
2631 | | - self._create_purchase(fundraise, contributor, 10.0) |
2632 | | - self._create_usd_contribution(fundraise, contributor, 2500) |
2633 | | - feed_entry = self._create_feed_entry(unified_doc, post) |
2634 | | - |
2635 | | - # Act |
2636 | | - serializer = ActivityFeedEntrySerializer(feed_entry) |
2637 | | - contributions = serializer.data["contributions"] |
2638 | | - top_entry = contributions["top"][0] |
2639 | | - |
2640 | | - # Assert |
2641 | | - self.assertEqual(top_entry["total_contribution"]["rsc"], 10.0) |
2642 | | - self.assertEqual(top_entry["total_contribution"]["usd"], 25.0) |
2643 | | - self.assertEqual(len(top_entry["contributions"]), 2) |
2644 | | - currencies = {c["currency"] for c in top_entry["contributions"]} |
2645 | | - self.assertEqual(currencies, {"RSC", "USD"}) |
2646 | | - |
2647 | | - |
2648 | 2450 | class FundraiseContributionContentSerializerTests(AWSMockTestCase): |
2649 | 2451 | """ |
2650 | 2452 | Test cases for the FundraiseContributionContentSerializer. |
|
0 commit comments