Exemplo n.º 1
0
    def test_model_is_a_list(self):
        serialize = SerializeModel()
        files = []
        out = parse_stream(serialize.model(files))
        data = json.loads(out["data"])
        self.assertEqual(list, type(data))

        files = [ModelFile("a", True), ModelFile("b", False)]
        out = parse_stream(serialize.model(files))
        data = json.loads(out["data"])
        self.assertEqual(list, type(data))
        self.assertEqual(2, len(data))
Exemplo n.º 2
0
 def test_full_path(self):
     serialize = SerializeModel()
     a = ModelFile("a", True)
     b = ModelFile("b", True)
     b.add_child(ModelFile("ba", False))
     b.add_child(ModelFile("bb", True))
     c = ModelFile("c", True)
     ca = ModelFile("ca", True)
     ca.add_child(ModelFile("caa", False))
     ca.add_child(ModelFile("cab", False))
     c.add_child(ca)
     cb = ModelFile("cb", False)
     c.add_child(cb)
     c.eta = 100
     files = [a, b, c]
     out = parse_stream(serialize.model(files))
     data = json.loads(out["data"])
     self.assertEqual(3, len(data))
     self.assertEqual("a", data[0]["full_path"])
     self.assertEqual("b", data[1]["full_path"])
     self.assertEqual("b/ba", data[1]["children"][0]["full_path"])
     self.assertEqual("b/bb", data[1]["children"][1]["full_path"])
     self.assertEqual("c", data[2]["full_path"])
     self.assertEqual("c/ca", data[2]["children"][0]["full_path"])
     self.assertEqual("c/ca/caa", data[2]["children"][0]["children"][0]["full_path"])
     self.assertEqual("c/ca/cab", data[2]["children"][0]["children"][1]["full_path"])
     self.assertEqual("c/cb", data[2]["children"][1]["full_path"])
Exemplo n.º 3
0
 def test_file_state(self):
     serialize = SerializeModel()
     a = ModelFile("a", True)
     a.state = ModelFile.State.DEFAULT
     b = ModelFile("b", False)
     b.state = ModelFile.State.DOWNLOADING
     c = ModelFile("c", True)
     c.state = ModelFile.State.QUEUED
     d = ModelFile("d", True)
     d.state = ModelFile.State.DOWNLOADED
     e = ModelFile("e", False)
     e.state = ModelFile.State.DELETED
     f = ModelFile("f", False)
     f.state = ModelFile.State.EXTRACTING
     g = ModelFile("g", False)
     g.state = ModelFile.State.EXTRACTED
     files = [a, b, c, d, e, f, g]
     out = parse_stream(serialize.model(files))
     data = json.loads(out["data"])
     self.assertEqual(7, len(data))
     self.assertEqual("default", data[0]["state"])
     self.assertEqual("downloading", data[1]["state"])
     self.assertEqual("queued", data[2]["state"])
     self.assertEqual("downloaded", data[3]["state"])
     self.assertEqual("deleted", data[4]["state"])
     self.assertEqual("extracting", data[5]["state"])
     self.assertEqual("extracted", data[6]["state"])
Exemplo n.º 4
0
 def test_file_name(self):
     serialize = SerializeModel()
     files = [ModelFile("a", True), ModelFile("b", False)]
     out = parse_stream(serialize.model(files))
     data = json.loads(out["data"])
     self.assertEqual(2, len(data))
     self.assertEqual("a", data[0]["name"])
     self.assertEqual("b", data[1]["name"])
Exemplo n.º 5
0
 def test_remote_modified_timestamp(self):
     serialize = SerializeModel()
     a = ModelFile("a", True)
     b = ModelFile("b", False)
     b.remote_modified_timestamp = datetime(2018, 11, 9, 21, 40, 18, tzinfo=timezone('UTC'))
     files = [a, b]
     out = parse_stream(serialize.model(files))
     data = json.loads(out["data"])
     self.assertEqual(2, len(data))
     self.assertEqual(None, data[0]["remote_modified_timestamp"])
     self.assertEqual(str(1541799618.0), data[1]["remote_modified_timestamp"])
Exemplo n.º 6
0
 def test_file_is_extractable(self):
     serialize = SerializeModel()
     a = ModelFile("a", True)
     a.is_extractable = False
     b = ModelFile("b", False)
     b.is_extractable = True
     files = [a, b]
     out = parse_stream(serialize.model(files))
     data = json.loads(out["data"])
     self.assertEqual(2, len(data))
     self.assertEqual(False, data[0]["is_extractable"])
     self.assertEqual(True, data[1]["is_extractable"])
Exemplo n.º 7
0
 def test_eta(self):
     serialize = SerializeModel()
     a = ModelFile("a", True)
     a.eta = None
     b = ModelFile("b", False)
     b.eta = 0
     c = ModelFile("c", True)
     c.eta = 100
     files = [a, b, c]
     out = parse_stream(serialize.model(files))
     data = json.loads(out["data"])
     self.assertEqual(3, len(data))
     self.assertEqual(None, data[0]["eta"])
     self.assertEqual(0, data[1]["eta"])
     self.assertEqual(100, data[2]["eta"])
Exemplo n.º 8
0
 def test_event_names(self):
     serialize = SerializeModel()
     out = parse_stream(serialize.model([]))
     self.assertEqual("model-init", out["event"])
     out = parse_stream(
         serialize.update_event(
             SerializeModel.UpdateEvent(
                 SerializeModel.UpdateEvent.Change.ADDED, None, None)))
     self.assertEqual("model-added", out["event"])
     out = parse_stream(
         serialize.update_event(
             SerializeModel.UpdateEvent(
                 SerializeModel.UpdateEvent.Change.UPDATED, None, None)))
     self.assertEqual("model-updated", out["event"])
     out = parse_stream(
         serialize.update_event(
             SerializeModel.UpdateEvent(
                 SerializeModel.UpdateEvent.Change.REMOVED, None, None)))
     self.assertEqual("model-removed", out["event"])