
from ggrc import db
from ggrc.models import Control
from integration.ggrc import TestCase
from .factories import ControlCategoryFactory, ControlFactory
from nose.plugins.skip import SkipTest
from nose.tools import assert_in, eq_

class TestControl(TestCase):
  def test_simple_categorization(self):
    category = ControlCategoryFactory(scope_id=100)
    control = ControlFactory()
    control.categories.append(category)
    db.session.commit()
    self.assertIn(category, control.categories)
    # be really really sure
    control = db.session.query(Control).get(control.id)
    self.assertIn(category, control.categories)

  def test_has_test_plan(self):
    control = ControlFactory(test_plan="This is a test text")
    db.session.commit()

    control = db.session.query(Control).get(control.id)
    eq_(control.test_plan, "This is a test text")


"""Tests for control model."""

from ggrc import db
from ggrc.models import Control
from integration.ggrc import TestCase
from integration.ggrc.models import factories

class TestControl(TestCase):
  def test_simple_categorization(self):
    category = factories.ControlCategoryFactory(scope_id=100)
    control = factories.ControlFactory()
    control.categories.append(category)
    db.session.commit()
    self.assertIn(category, control.categories)
    # be really really sure
    control = db.session.query(Control).get(control.id)
    self.assertIn(category, control.categories)

  def test_has_test_plan(self):
    control = factories.ControlFactory(test_plan="This is a test text")
    control = db.session.query(Control).get(control.id)
    self.assertEqual(control.test_plan, "This is a test text")

Clean up control model tests
Clean up control model tests

+ 
+ """Tests for control model."""
  
  from ggrc import db
  from ggrc.models import Control
  from integration.ggrc import TestCase
+ from integration.ggrc.models import factories
- from .factories import ControlCategoryFactory, ControlFactory
- from nose.plugins.skip import SkipTest
- from nose.tools import assert_in, eq_
  
  class TestControl(TestCase):
    def test_simple_categorization(self):
-     category = ControlCategoryFactory(scope_id=100)
+     category = factories.ControlCategoryFactory(scope_id=100)
-     control = ControlFactory()
+     control = factories.ControlFactory()
      control.categories.append(category)
      db.session.commit()
      self.assertIn(category, control.categories)
      # be really really sure
      control = db.session.query(Control).get(control.id)
      self.assertIn(category, control.categories)
  
    def test_has_test_plan(self):
-     control = ControlFactory(test_plan="This is a test text")
+     control = factories.ControlFactory(test_plan="This is a test text")
-     db.session.commit()
+     control = db.session.query(Control).get(control.id)
+     self.assertEqual(control.test_plan, "This is a test text")
  
-     control = db.session.query(Control).get(control.id)
-     eq_(control.test_plan, "This is a test text")
- 
Clean up control model tests
## Code Before:

from ggrc import db
from ggrc.models import Control
from integration.ggrc import TestCase
from .factories import ControlCategoryFactory, ControlFactory
from nose.plugins.skip import SkipTest
from nose.tools import assert_in, eq_

class TestControl(TestCase):
  def test_simple_categorization(self):
    category = ControlCategoryFactory(scope_id=100)
    control = ControlFactory()
    control.categories.append(category)
    db.session.commit()
    self.assertIn(category, control.categories)
    # be really really sure
    control = db.session.query(Control).get(control.id)
    self.assertIn(category, control.categories)

  def test_has_test_plan(self):
    control = ControlFactory(test_plan="This is a test text")
    db.session.commit()

    control = db.session.query(Control).get(control.id)
    eq_(control.test_plan, "This is a test text")

## Instruction:
Clean up control model tests
## Code After:

"""Tests for control model."""

from ggrc import db
from ggrc.models import Control
from integration.ggrc import TestCase
from integration.ggrc.models import factories

class TestControl(TestCase):
  def test_simple_categorization(self):
    category = factories.ControlCategoryFactory(scope_id=100)
    control = factories.ControlFactory()
    control.categories.append(category)
    db.session.commit()
    self.assertIn(category, control.categories)
    # be really really sure
    control = db.session.query(Control).get(control.id)
    self.assertIn(category, control.categories)

  def test_has_test_plan(self):
    control = factories.ControlFactory(test_plan="This is a test text")
    control = db.session.query(Control).get(control.id)
    self.assertEqual(control.test_plan, "This is a test text")
