def test_add_speaker(self):
        topic = Topic(name="Python", description="", abbreviation="py")
        diversification = Diversity(name="speaker", description="description")

        speaker = Speaker(
            name="Kyle Harrison",
            avatar="https://avatar.com",
            bio="description",
            contact="apoclyps",
            role="Software Engineer",
            topics=[topic],
            diversification=[diversification],
            location="Belfast",
            source="test",
        )
        db.session.add(speaker)
        db.session.commit()

        self.assertEqual(speaker.name, "Kyle Harrison")
        self.assertEqual(speaker.avatar, "https://avatar.com")
        self.assertEqual(speaker.bio, "description")
        self.assertEqual(speaker.contact, "apoclyps")
        self.assertEqual(speaker.role, "Software Engineer")
        self.assertEqual(speaker.topics, [topic])
        self.assertEqual(speaker.diversification, [diversification])
        self.assertEqual(speaker.location, "Belfast")
        self.assertEqual(speaker.source, "test")
Ejemplo n.º 2
0
def index():
    if request.method == "POST":
        name = request.form["name"]
        avatar = request.form["avatar"]
        bio = request.form["bio"]
        contact = request.form["contact"]
        role = request.form["role"]
        topics = request.form["topics"]
        diversification = request.form["diversification"]
        location = request.form["location"]
        source = request.form["source"]

        topic_list = extract_topics(topics)
        diversification_list = extract_diversification(diversification)

        speaker = Speaker(
            name=name,
            avatar=avatar,
            bio=bio,
            contact=contact,
            role=role,
            topics=topic_list,
            diversification=diversification_list,
            location=location,
            source=source,
        )
        print("speaker")
        print(speaker)

        db.session.add(speaker)
        db.session.commit()

    speakers = Speaker.query.all()

    response_object = {
        "status": "success",
        "data": {
            "speakers": [speaker.to_dict() for speaker in speakers]
        },
    }
    return jsonify(response_object), 200
Ejemplo n.º 3
0
def add_speaker():
    data = request.get_json()
    response_object = {"status": "fail", "message": "Invalid payload."}
    if not data:
        return jsonify(response_object), 400

    name = data.get("name")
    avatar = data.get("avatar")
    bio = data.get("bio")
    contact = data.get("contact")
    role = data.get("role")
    topics = data.get("topics")
    diversification = data.get("diversification")
    location = data.get("location")
    source = data.get("source")

    topic_list = extract_topics(topics)
    diversification_list = extract_diversification(diversification)

    try:
        speaker = Speaker.query.filter_by(name=name).first()
        if not speaker:
            speaker = Speaker(
                name=name,
                avatar=avatar,
                bio=bio,
                contact=contact,
                role=role,
                topics=topic_list,
                diversification=diversification_list,
                location=location,
                source=source,
            )

            db.session.add(speaker)
            db.session.commit()
            response_object["status"] = "success"
            response_object["message"] = f"{name} was added!"
            return jsonify(response_object), 201
        else:
            response_object["message"] = "Sorry. That id already exists."
            return jsonify(response_object), 202
    except (exc.IntegrityError, ValueError):
        db.session.rollback()
        return jsonify(response_object), 400
    except exc.IntegrityError:
        db.session.rollback()
        return jsonify(response_object), 400
Ejemplo n.º 4
0
def add_speaker(name, avatar, bio, contact, role, topics, diversification,
                location, source):
    speaker = Speaker(
        name=name,
        avatar=avatar,
        bio=bio,
        contact=contact,
        role=role,
        topics=topics,
        diversification=diversification,
        location=location,
        source=source,
    )
    db.session.add(speaker)
    db.session.commit()
    return speaker