def test_delete_podcast(self):
        # Check a record exists in the db
        podcast = Podcast(**self.data)
        podcast.save_to_db()
        self.assertIsNotNone(Podcast.find_by_name(self.data["name"]))

        # Delete podcast
        podcast.delete_from_db()

        # Check record doesn't exist anymore
        self.assertIsNone(Podcast.find_by_name(self.data["name"]))
Exemple #2
0
    def test_post_podcast(self):
        with self.app() as client:
            with self.app_context():
                # Check record named "Test API Podcast" does not exist
                self.assertIsNone(Podcast.find_by_name(self.post_data["audioFileMetadata"]["name"]))
                request = client.post("/", data=json.dumps(self.post_data))

                self.assertEqual(request.status_code, 200)
                self.assertIsNotNone(Podcast.find_by_name(self.post_data["audioFileMetadata"]["name"]))
                self.assertDictEqual(
                    PodcastSchema().dump(Podcast.find_by_name(self.post_data["audioFileMetadata"]["name"])),
                    json.loads(request.data)
                )
Exemple #3
0
    def test_podcast_load_with_existing_record(self):
        podcast = self.schema().load(self.data, session=db.session)

        self.assertIsNone(Podcast.find_by_name(podcast.name))
        podcast.save_to_db()
        db_podcast = Podcast.find_by_name(podcast.name)
        self.assertIsNotNone(db_podcast)

        # load another podcast with same data and check id is same
        self.data["id"] = db_podcast.id
        podcast2 = self.schema().load(self.data, session=db.session,\
             instance=Podcast.find_by_name(self.data["name"]), unknown=EXCLUDE)

        self.assertIsNotNone(podcast2)
        self.assertEqual(podcast2.id, db_podcast.id)
    def test_update_podcast(self):
        podcast = Podcast(**self.data)
        podcast.save_to_db()

        # Get the record and check field values
        record = Podcast.find_by_name(self.data["name"])
        self.assertIsNotNone(record)
        self.assertEqual(record.name, self.data["name"])
        self.assertEqual(record.duration, self.data["duration"])

        # Update field values
        update_data = {
            "name": "Updated Test Podcast",
            "duration": 120,
            "host": Host("Updated host"),
            "participants": [
                Participant("Rohan")
            ]
        }
        Podcast.update(update_data, record)

        # Check updated field values
        updated_record = Podcast.find_by_id(record.id)
        self.assertIsNotNone(updated_record)
        self.assertEqual(updated_record.name, update_data["name"])
        self.assertEqual(updated_record.duration, update_data["duration"])
        self.assertIsInstance(updated_record.host, Host)
        self.assertEqual(str(updated_record.host.name), update_data["host"].name)
        self.assertEqual(len(updated_record.participants), 1)
        self.assertEqual(updated_record.participants[0].name, update_data["participants"][0].name)
Exemple #5
0
    def test_podcast_dump(self):
        podcast = Podcast(name="Test",
                          duration=33,
                          host="Tester",
                          participants=["A", "B"])
        podcast.save_to_db()

        # Retrieve DB record for the podcast created
        podcast = Podcast.find_by_name(podcast.name)
        expected = OrderedDict({
            "id":
            1,
            "name":
            "Test",
            "duration":
            33,
            "host":
            "Tester",
            "participants": ["A", "B"],
            "uploaded_time":
            "T".join(str(podcast.uploaded_time).split())
        })

        # Get the serialized data
        json_data = self.schema().dump(podcast)

        # Separate out participant lists from json_data and expected data to compare separately
        participantList = json_data.pop("participants")
        expectedParticipantList = expected.pop("participants")

        self.assertDictEqual(json_data, expected)
        self.assertCountEqual(participantList, expectedParticipantList)
    def test_create_podcast(self):

        podcast = Podcast(**self.data)

        # Check there is no exisiting podcast named "Test Podcast"
        self.assertIsNone(Podcast.find_by_name(podcast.name))

        # Save podcast to database
        podcast.save_to_db()

        # Check podcast exists
        record = Podcast.find_by_name(podcast.name)
        self.assertIsNotNone(record)
        self.assertIsNotNone(record.id)
        self.assertIsNotNone(record.uploaded_time)
        self.assertEqual(record.name, podcast.name)
        self.assertEqual(record.duration, podcast.duration)

        # check host name and type
        self.assertIsInstance(record.host, Host)
        self.assertEqual(record.host.name, "Robert")
        self.assertEqual(len(record.participants), 3)
        self.assertIsInstance(record.participants[0], Participant)
    def test_get_podcast_by_id_or_name(self):
        # Check a record exists in the db
        podcast = Podcast(**self.data)
        podcast.save_to_db()

        podcast_byname = Podcast.find_by_name(self.data["name"])
        self.assertIsNotNone(podcast_byname)

        id = podcast_byname.id
        
        # Check find_by_id method
        podcast_byid = Podcast.find_by_id(id)
        self.assertIsNotNone(podcast_byid)
        self.assertEqual(podcast_byid.name, podcast_byname.name)
        self.assertEqual(podcast_byid.uploaded_time, podcast_byname.uploaded_time)