<gh_stars>1-10
from django.test import TestCase
from rest_framework.test import APIClient
from rest_framework import status

#my local imports
from authors.apps.authentication.models import User
from ..models import Profile


def create_a_user(username="nerd", email="<EMAIL>", password="<PASSWORD>"):
    """Creating a test user"""

    user = User.objects.create_user(username, email, password)
    user.save()
    return user


class ProfileModelTestCase(TestCase):
    """This class defines the test suite for the profile model."""

    def test_model_can_create_a_user_profile(self):
        """
        Test the profile model can create a user profile
        when a user signs up.
        """

        response = create_a_user()
        self.assertTrue(isinstance(response.profile, Profile))
    
    def test_model_returns_readable_representation(self):
        """
        Test a readable string is returned for the profile 
        model instance.
        """

        response = create_a_user()
        self.assertIn("<EMAIL>", str(response.profile))
    
    def test_timestamp_added(self):
        """
        Test that Profile model adds a timestamp 
        on profile creation. 
        """
        response = create_a_user()
        self.assertIsNotNone(response.profile.created_at)

    def test_user_follow_and_unfollow(self):
        """
        A follow relationship can be created
        """
        user1 = create_a_user()
        user2 = create_a_user("TestUser", "<EMAIL>", "WhereTh3#")
        user2.profile.follows.add(user1.profile)
        self.assertTrue(user1.profile.is_follower(user2))
        user2.profile.follows.remove(user1.profile)
        self.assertFalse(user1.profile.is_follower(user2))

from django.test import TestCase
from rest_framework.test import APIClient
from rest_framework import status

#my local imports
from authors.apps.authentication.models import User
from ..models import Profile


def create_a_user(username="nerd", email="<EMAIL>", password="<PASSWORD>"):
    """Creating a test user"""

    user = User.objects.create_user(username, email, password)
    user.save()
    return user


class ProfileModelTestCase(TestCase):
    """This class defines the test suite for the profile model."""

    def test_model_can_create_a_user_profile(self):
        """
        Test the profile model can create a user profile
        when a user signs up.
        """

        response = create_a_user()
        self.assertTrue(isinstance(response.profile, Profile))
    
    def test_model_returns_readable_representation(self):
        """
        Test a readable string is returned for the profile 
        model instance.
        """

        response = create_a_user()
        self.assertIn("<EMAIL>", str(response.profile))
    
    def test_timestamp_added(self):
        """
        Test that Profile model adds a timestamp 
        on profile creation. 
        """
        response = create_a_user()
        self.assertIsNotNone(response.profile.created_at)

    def test_user_follow_and_unfollow(self):
        """
        A follow relationship can be created
        """
        user1 = create_a_user()
        user2 = create_a_user("TestUser", "<EMAIL>", "WhereTh3#")
        user2.profile.follows.add(user1.profile)
        self.assertTrue(user1.profile.is_follower(user2))
        user2.profile.follows.remove(user1.profile)
        self.assertFalse(user1.profile.is_follower(user2))
#my local imports Creating a test user This class defines the test suite for the profile model. Test the profile model can create a user profile         when a user signs up. Test a readable string is returned for the profile          model instance. Test that Profile model adds a timestamp          on profile creation. A follow relationship can be created #")