コード例 #1
0
ファイル: test_op_tag.py プロジェクト: LukasPolon/smt
    def case_delete_records(self, refresh_db_before):
        """ Create new record in Tag table and then delete it."""
        new_name = "tag1"

        TagOp.add(new_name)

        tag_obj = TagOp.get(name=new_name)
        self.assertTrue(len(tag_obj) is 1)
        self.assertEqual(tag_obj[0].name, new_name)

        TagOp.delete(tag_obj[0])

        tag_obj = TagOp.get(name=new_name)
        self.assertFalse(tag_obj)
コード例 #2
0
    def test_get_id(self, mock_tag, mock_val_id, mock_val_name):
        """ Assumptions:
                - id argument given
        """
        test_id = 1
        TagOp.get(id=test_id)

        self.assertTrue(mock_val_id.called)
        self.assertFalse(mock_val_name.called)

        self.assertTrue(mock_tag.query.filter_by.called)

        exp_calls = [mock.call(id=test_id), mock.call().all()]
        mock_tag.query.filter_by.assert_has_calls(exp_calls)
コード例 #3
0
ファイル: test_op_tag.py プロジェクト: LukasPolon/smt
    def case_get_by_name_one_result(self, refresh_db_before):
        """ Create test records in Tag table and get them by name."""
        names_with_id = {"tag1": 1, "tag2": 2, "tag3": 3}

        for name in names_with_id.keys():
            TagOp.add(name)

        for exp_name, exp_id in names_with_id.items():
            tag_obj = TagOp.get(name=exp_name)
            self.assertTrue(len(tag_obj) is 1)
            self.assertEqual(exp_name, tag_obj[0].name)
            self.assertEqual(exp_id, tag_obj[0].id)
コード例 #4
0
ファイル: test_op_tag.py プロジェクト: LukasPolon/smt
    def case_add_records(self, refresh_db_before):
        """ Add new records to Tag table."""
        new_names = ["tag1", "tag2", "tag3"]

        for name in new_names:
            TagOp.add(name)

        check_records = TagOp.get()

        self.assertEqual(len(check_records), len(new_names))

        for record, exp_name in zip(check_records, new_names):
            self.assertTrue(isinstance(record, Tag))
            self.assertEqual(record.name, exp_name)
コード例 #5
0
ファイル: test_op_tag.py プロジェクト: LukasPolon/smt
    def case_update_record(self, refresh_db_before):
        """ Create test record in Tag table and then update it."""
        original_name = "tag3"
        update_name = "tag33"

        original_tag = TagOp.add(original_name)

        updated_tag_local = TagOp.update(original_tag, update_name)

        self.assertEqual(updated_tag_local.name, update_name)

        updated_tag_get = TagOp.get(name=update_name)

        self.assertTrue(len(updated_tag_get) is 1)
        self.assertEqual(updated_tag_get[0].name, update_name)
        self.assertEqual(updated_tag_get[0].id, original_tag.id)
コード例 #6
0
    def resolve_tag(cls, tag_name):
        """ Find Tag record according to given address.
            Return Tag model object.

            Args:
                tag_name(str): tag to find

            Returns:
                tag_obj(app.db.models.tag.Tag): Tag object
        """
        tag_results = TagOp.get(name=tag_name)

        if len(tag_results) is not 1:
            raise ServerTagNotFoundError(f"Not found Tag: {tag_name}.")

        tag_obj = tag_results[0]
        return tag_obj