#212 Deduplicate 'source' in views.py.
Merged a year ago by jkaluza. Opened a year ago by jkaluza.

file modified
+2 -1

@@ -215,7 +215,8 @@ 

  

          source_type = PUNGI_SOURCE_TYPE_NAMES[source_type]

  

-         source = source_data["source"].split(" ")

+         # Use list(set()) here to remove duplicate sources.

+         source = list(set(source_data["source"].split(" ")))

          if not source:

              err = "No source provided for %s" % source_type

              log.error(err)

@@ -429,6 +429,23 @@ 

          c = db.session.query(Compose).filter(Compose.id == 1).one()

          self.assertEqual(c.state, COMPOSE_STATES["wait"])

  

+     def test_submit_build_duplicate_sources(self):

+         with self.test_request_context(user='dev'):

+             flask.g.oidc_scopes = [

+                 '{0}{1}'.format(conf.oidc_base_namespace, 'new-compose')

+             ]

+ 

+             rv = self.client.post('/api/1/composes/', data=json.dumps(

+                 {'source': {'type': 'module', 'source': 'foo:x foo:x foo:y'}}))

+             data = json.loads(rv.get_data(as_text=True))

+ 

+         self.assertEqual(data['source'].count("foo:x"), 1)

+         self.assertEqual(data['source'].count("foo:y"), 1)

+ 

+         db.session.expire_all()

+         c = db.session.query(Compose).filter(Compose.id == 1).one()

+         self.assertEqual(c.state, COMPOSE_STATES["wait"])

+ 

      def test_submit_build_resurrection_removed(self):

          self.c1.state = COMPOSE_STATES["removed"]

          self.c1.reused_id = 1

no initial comment

Pull-Request has been merged by jkaluza

a year ago