def setUp(self):
        self.procedure = factories.ProcedureFactory(author="tester", title="test procedure")

        self.generator = ProcedureGenerator(self.procedure)
        self.procedure_etree_element = self.generator.generate()
        self.attribs = self.procedure_etree_element.attrib
class ProcedureGeneratorTest(TestCase):
    def setUp(self):
        self.procedure = factories.ProcedureFactory(author="tester", title="test procedure")

        self.generator = ProcedureGenerator(self.procedure)
        self.procedure_etree_element = self.generator.generate()
        self.attribs = self.procedure_etree_element.attrib

    def test_element_has_correct_name(self):
        assert_equals(self.procedure_etree_element.tag, self.generator.name)

    def test_element_has_title(self):
        assert_true("title" in self.attribs)
        assert_equals(self.attribs["title"], self.procedure.title)

    def test_element_has_author(self):
        assert_true("author" in self.attribs)
        assert_equals(self.attribs["author"], self.procedure.author)

    @raises(ValueError)
    def test_error_if_no_title(self):
        procedure = factories.ProcedureFactory()
        procedure.title = None

        ProcedureGenerator(procedure).generate()

    @raises(ValueError)
    def test_error_if_blank_title(self):
        procedure = factories.ProcedureFactory(title="")

        ProcedureGenerator(procedure).generate()

    @raises(ValueError)
    def test_error_if_no_author(self):
        procedure = factories.ProcedureFactory()
        procedure.author = None

        ProcedureGenerator(procedure).generate()

    @raises(ValueError)
    def test_error_if_blank_author(self):
        procedure = factories.ProcedureFactory(author="")

        ProcedureGenerator(procedure).generate()

    def test_element_has_no_version_attrib(self):
        assert_false("version" in self.attribs, self.attribs)

    def test_element_has_no_uuid(self):
        assert_false("uuid" in self.attribs)

    def test_element_has_version_attrib(self):
        self.procedure.version = "0.1"
        self.procedure_etree_element = self.generator.generate()

        assert_true("version" in self.procedure_etree_element.attrib)
        assert_equals(self.procedure_etree_element.attrib["version"], self.procedure.version)

    def test_element_has_uuid_attrib(self):
        self.procedure.uuid = str(uuid.uuid1())
        self.procedure_etree_element = self.generator.generate()

        assert_true("uuid" in self.procedure_etree_element.attrib)
        assert_equals(self.procedure_etree_element.attrib["uuid"], self.procedure.uuid)