# Copyright (C) 2016 Google Inc.
# Licensed under http://www.apache.org/licenses/LICENSE-2.0 <see LICENSE file>

from integration.ggrc.converters import TestCase

from ggrc import models


class TestImportUpdates(TestCase):

  """ Test importing of already existing objects """

  def setUp(self):
    TestCase.setUp(self)
    self.client.get("/login")

  def test_policy_basic_update(self):
    """ Test simple policy title update """

    filename = "policy_basic_import.csv"
    response = self.import_file(filename)

    self._check_response(response, {})

    policy = models.Policy.query.filter_by(slug="p1").first()
    self.assertEqual(policy.title, "some weird policy")

    filename = "policy_basic_import_update.csv"
    response = self.import_file(filename)
    self._check_response(response, {})

    policy = models.Policy.query.filter_by(slug="p1").first()
    self.assertEqual(policy.title, "Edited policy")

# Copyright (C) 2016 Google Inc.
# Licensed under http://www.apache.org/licenses/LICENSE-2.0 <see LICENSE file>

"""Tests for bulk updates with CSV import."""

from integration.ggrc.converters import TestCase

from ggrc import models


class TestImportUpdates(TestCase):

  """ Test importing of already existing objects """

  def setUp(self):
    TestCase.setUp(self)
    self.client.get("/login")

  def test_policy_basic_update(self):
    """ Test simple policy title update """

    filename = "policy_basic_import.csv"
    response = self.import_file(filename)

    self._check_response(response, {})

    policy = models.Policy.query.filter_by(slug="p1").first()
    self.assertEqual(policy.title, "some weird policy")
    revision_count = models.Revision.query.filter(
        models.Revision.resource_type == "Policy",
        models.Revision.resource_id == policy.id
    ).count()
    self.assertEqual(revision_count, 1)

    filename = "policy_basic_import_update.csv"
    response = self.import_file(filename)
    self._check_response(response, {})

    policy = models.Policy.query.filter_by(slug="p1").first()
    self.assertEqual(policy.title, "Edited policy")
    revision_count = models.Revision.query.filter(
        models.Revision.resource_type == "Policy",
        models.Revision.resource_id == policy.id
    ).count()
    self.assertEqual(revision_count, 2)

Add tests for revision updates via import