Esempio n. 1
0
def test_subscribe_user_to_podcast_twice(transactional_db):
    """Test that subscribe_user_to_podcast doesn't create a new subscription when the user is already subscribed."""
    user = User(username="******", password="******", email="*****@*****.**")
    user.save()
    podcast = get_valid_podcast_model()
    podcast.save()

    services.subscribe_user_to_podcast(user, podcast)
    result = services.subscribe_user_to_podcast(user, podcast)

    assert result == False
    assert len(user.subscription_objs.all()) == 1
Esempio n. 2
0
def test_subscribe_user_to_podcast(transactional_db):
    """Test that subscribe_user_to_podcast creates a new subscription"""
    user = get_valid_user()
    user.save()
    podcast = get_valid_podcast_model()
    podcast.save()
    now = datetime.datetime.now()

    with freezegun.freeze_time(now):
        result = services.subscribe_user_to_podcast(user, podcast)

        assert result == True
        assert len(user.subscription_objs.all()) == 1
        subscription_model = models.Subscription.objects.get(user=user)
        assert subscription_model.podcast == podcast
        assert subscription_model.subscribed.replace(tzinfo=None) == now