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

# pylint: disable=maybe-no-member

"""Test request import and updates."""

from ggrc import models
from integration.ggrc import converters


class TestRequestImport(converters.TestCase):

  """Basic Request import tests with.

  This test suite should test new Request imports and updates. The main focus
  of these tests is checking error messages for invalid state transitions.
  """

  def setUp(self):
    """ Set up for Request test cases """
    converters.TestCase.setUp(self)
    self.client.get("/login")

  def test_assessments_with_templates(self):
    """Test importing of assessments with templates."""

    self.import_file("assessment_template_no_warnings.csv")
    response = self.import_file("assessment_with_templates.csv")
    self._check_response(response, {})

    assessment = models.Assessment.query.filter(
        models.Assessment.slug == "A 4").first()

    values = set(v.attribute_value for v in assessment.custom_attribute_values)
    self.assertIn("abc", values)
    self.assertIn("2015-07-15 00:00:00", values)

@@ -139,16 +139,30 @@
 o-member
+, invalid-name
 %0A%0A%22%22%22Tes
@@ -195,16 +195,36 @@
 es.%22%22%22%0A%0A
+from ggrc import db%0A
 from ggr
@@ -295,21 +295,30 @@
 Test
-Reques
+Assessmen
 tImport
+Export
 (con
@@ -336,17 +336,16 @@
 tCase):%0A
-%0A
   %22%22%22Bas
@@ -347,22 +347,25 @@
 %22%22Basic 
-Reques
+Assessmen
 t import
@@ -416,23 +416,36 @@
 new 
-Request imports
+Assessment imports, exports,
  and
@@ -453,16 +453,18 @@
 updates.
+%0A 
  The mai
@@ -470,18 +470,16 @@
 in focus
-%0A 
  of thes
@@ -530,16 +530,18 @@
 id state
+%0A 
  transit
@@ -692,16 +692,23 @@
 ef test_
+import_
 assessme
@@ -1208,16 +1208,1580 @@
 00:00%22, values)%0A
+%0A  def test_export_assessments_with_filters_and_conflicting_ca_names(self):%0A    %22%22%22Test exporting assessments with conflicting custom attribute names.%22%22%22%0A    self.import_file(u%22assessment_template_no_warnings.csv%22)%0A    self.import_file(u%22assessment_with_templates.csv%22)%0A%0A    # also create an object level custom attribute with a name that clashes%0A    # with a name of a %22regular%22 attribute%0A    assessment = models.Assessment.query.filter(%0A        models.Assessment.slug == u%22A 2%22).first()%0A    cad = models.CustomAttributeDefinition(%0A        attribute_type=u%22Text%22,%0A        title=u%22title%22,%0A        definition_type=u%22assessment%22,%0A        definition_id=assessment.id%0A    )%0A    db.session.add(cad)%0A    db.session.commit()%0A%0A    data = %5B%7B%0A        %22object_name%22: %22Assessment%22,%0A        %22fields%22: %5B%22slug%22, %22title%22, %22description%22, %22status%22%5D,%0A        %22filters%22: %7B%0A            %22expression%22: %7B%0A                %22left%22: %7B%0A                    %22left%22: %22code%22,%0A                    %22op%22: %7B%22name%22: %22~%22%7D,%0A                    %22right%22: %22A 2%22%0A                %7D,%0A                %22op%22: %7B%22name%22: %22AND%22%7D,%0A                %22right%22: %7B%0A                    %22left%22: %22title%22,%0A                    %22op%22: %7B%22name%22: %22~%22%7D,%0A                    %22right%22: %22no template Assessment%22%0A                %7D%0A            %7D,%0A            %22keys%22: %5B%22code%22, %22title%22, %22status%22%5D,%0A            %22order_by%22: %7B%0A                %22keys%22: %5B%5D,%0A                %22order%22: %22%22,%0A                %22compare%22: None%0A            %7D%0A        %7D%0A    %7D%5D%0A%0A    response = self.export_csv(data)%0A    self.assertIn(u%22No template Assessment 2%22, response.data)%0A

Add test for Assessment export with clashing names