Exemple #1
0
    def test_select_by_text__no_match(self):
        """Verify None returned if no match.
        """
        fact_id = uuid.uuid4()
        fact_text = 'once upon a time {0}'.format(uuid.uuid4())
        incoming_fact = IncomingFact(fact_id=fact_id,
                                     fact_text=fact_text,
                                     parsed_fact=fact_text)

        db.session.add(incoming_fact)
        self.reset_session()

        retrieved_fact = IncomingFact.select_by_text('abracadabra')
        self.assertIsNone(retrieved_fact,
                          "Expected not to find persisted IncomingFact")
Exemple #2
0
    def test_select_by_text(self):
        """Verify select_by_text method.
        """
        fact_id = uuid.uuid4()
        fact_text = 'once upon a time {0}'.format(uuid.uuid4())
        incoming_fact = IncomingFact(fact_id=fact_id,
                                     fact_text=fact_text,
                                     parsed_fact=fact_text)

        db.session.add(incoming_fact)
        self.reset_session()

        retrieved_fact = IncomingFact.select_by_text(fact_text)
        self.assertIsNotNone(retrieved_fact,
                             "Expected to find persisted IncomingFact")
        self.assertEqual(fact_id, retrieved_fact.fact_id)
Exemple #3
0
    def test_select_by_text__no_match(self):
        """Verify None returned if no match.
        """
        fact_id = uuid.uuid4()
        fact_text = 'once upon a time {0}'.format(uuid.uuid4())
        incoming_fact = IncomingFact(fact_id=fact_id,
                                     fact_text=fact_text,
                                     parsed_fact=fact_text)

        db.session.add(incoming_fact)
        self.reset_session()

        retrieved_fact = IncomingFact.select_by_text('abracadabra')
        self.assertIsNone(retrieved_fact, "Expected not to find persisted IncomingFact")
Exemple #4
0
    def test_select_by_text(self):
        """Verify select_by_text method.
        """
        fact_id = uuid.uuid4()
        fact_text = 'once upon a time {0}'.format(uuid.uuid4())
        incoming_fact = IncomingFact(fact_id=fact_id,
                                     fact_text=fact_text,
                                     parsed_fact=fact_text)

        db.session.add(incoming_fact)
        self.reset_session()

        retrieved_fact = IncomingFact.select_by_text(fact_text)
        self.assertIsNotNone(retrieved_fact, "Expected to find persisted IncomingFact")
        self.assertEqual(fact_id, retrieved_fact.fact_id)
Exemple #5
0
    def test_incoming_fact__default_id(self):
        """Verify that fact_id is assigned when persisted.
        """
        fact_text = 'once upon a time {0}'.format(uuid.uuid4())
        incoming_fact = IncomingFact(fact_text=fact_text,
                                     parsed_fact=fact_text)
        db.session.add(incoming_fact)
        self.reset_session()

        retrieved_fact = db.session.query(IncomingFact).filter_by(
            fact_text=fact_text).first()

        self.assertIsNotNone(retrieved_fact,
                             "Expected to find persisted IncomingFact")
        self.assertTrue(isinstance(retrieved_fact.fact_id, uuid.UUID))
Exemple #6
0
    def test_incoming_fact__deleted(self):
        """Verify creation with deleted=True.
        """
        fact_id = uuid.uuid4()
        fact_text = 'once upon a time {0}'.format(uuid.uuid4())
        incoming_fact = IncomingFact(fact_id=fact_id,
                                     fact_text=fact_text,
                                     parsed_fact=fact_text,
                                     deleted=True)
        db.session.add(incoming_fact)
        self.reset_session()

        retrieved_fact = db.session.query(IncomingFact).filter_by(
            fact_id=fact_id).first()

        self.assertIsNotNone(retrieved_fact,
                             "Expected to find persisted IncomingFact")
        self.assertTrue(retrieved_fact.deleted)
Exemple #7
0
    def test_incoming_fact(self):
        """Verify creation with all non-nullable data.
        """
        utcnow = datetime.datetime.utcnow().replace(microsecond=0)
        fact_id = uuid.uuid4()
        fact_text = 'once upon a time {0}'.format(uuid.uuid4())
        parsed_fact = '{0} {1}'.format(fact_text, uuid.uuid4())
        incoming_fact = IncomingFact(fact_id=fact_id,
                                     fact_text=fact_text,
                                     parsed_fact=parsed_fact)
        db.session.add(incoming_fact)
        self.reset_session()

        retrieved_fact = db.session.query(IncomingFact).filter_by(
            fact_id=fact_id).first()

        self.assertIsNotNone(retrieved_fact,
                             "Expected to find persisted IncomingFact")
        self.assertEqual(fact_id, retrieved_fact.fact_id)
        self.assertEqual(fact_text, retrieved_fact.fact_text)
        self.assertEqual(parsed_fact, retrieved_fact.parsed_fact)
        self.assertFalse(retrieved_fact.deleted)
        self.assertTrue(utcnow <= retrieved_fact.creation_date_utc)