예제 #1
0
    def test_alignment(self):
        sample = EDRCmdrDexProfile()
        created = sample.created
        sample.alignment = u"outlaw"
        self.assertEquals(sample.alignment, u"outlaw")
        now = EDTime.js_epoch_now()
        self.assertAlmostEqual(sample.updated/100.0, now/100.0, 1)
        self.assertEqual(sample.created, created)

        sample.alignment = u"neutral"
        self.assertEquals(sample.alignment, u"neutral")
        now = EDTime.js_epoch_now()
        self.assertAlmostEqual(sample.updated/100.0, now/100.0, 1)
        self.assertEqual(sample.created, created)

        sample.alignment = u"enforcer"
        self.assertEquals(sample.alignment, u"enforcer")
        now = EDTime.js_epoch_now()
        self.assertAlmostEqual(sample.updated/100.0, now/100.0, 1)
        self.assertEqual(sample.created, created)

        current = sample.alignment
        updated = sample.updated
        sample.alignment = u"dummy"
        self.assertEquals(sample.alignment, current)
        self.assertEqual(sample.updated, updated)
        self.assertEqual(sample.created, created)

        sample.alignment = u"Outlaw"
        self.assertEquals(sample.alignment, current)
        self.assertEqual(sample.updated, updated)
        self.assertEqual(sample.created, created)

        sample.alignment = None
        self.assertEquals(sample.alignment, None)
        now = EDTime.js_epoch_now()
        self.assertAlmostEqual(sample.updated/100.0, now/100.0, 1)
        self.assertEqual(sample.created, created)

        current = sample.alignment
        updated = sample.updated
        sample.alignment = current
        self.assertEquals(sample.alignment, current)
        self.assertEqual(sample.updated, updated)
        self.assertEqual(sample.created, created)
예제 #2
0
파일: edrcmdrs.py 프로젝트: Niteship/edr
 def __update_squadron_info(self, force_update=False):
     if self.server.is_anonymous():
         return
     mark_twain_flag = int(
         (EDTime.js_epoch_now() - self.heartbeat_timestamp) /
         1000) >= self._edr_heartbeat if self.heartbeat_timestamp else True
     if force_update or mark_twain_flag:
         info = self.server.heartbeat()
         if info:
             self.heartbeat_timestamp = info[
                 "heartbeat"] if "heartbeat" in info else EDTime.js_epoch_now(
                 )
             self._player.squadron_member(
                 info) if "squadronId" in info else self._player.lone_wolf(
                 )
         else:
             self.heartbeat_timestamp = EDTime.js_epoch_now()
             self._player.lone_wolf()
예제 #3
0
    def iff(self, new_iff):
        now = EDTime.js_epoch_now()
        if (new_iff is None):
            self._iff = None
            self.updated = now
            return

        if (new_iff not in EDRCmdrDexProfile.iffs()):
            return
        if (new_iff == self._iff):
            return
        self._iff = new_iff
        self.updated = now
예제 #4
0
    def alignment(self, new_alignment):
        now = EDTime.js_epoch_now()
        if (new_alignment is None):
            self._alignment = None
            self.updated = now
            return

        if (new_alignment not in EDRCmdrDexProfile.alignments()):
            return
        if (new_alignment == self._alignment):
            return
        self._alignment = new_alignment
        self.updated = now
예제 #5
0
    def __init__(self, dex_dict=None):
        if dex_dict is None:
            dex_dict = {}
        self._alignment = dex_dict.get("alignment", None)
        self._iff = dex_dict.get("rel", None)
        self.iff_by = dex_dict.get("by", None)
        self.tags = set([self.__tagify(t) for t in dex_dict.get("tags", [])])
        self._friend = dex_dict.get("friend", False)
        self._memo = dex_dict.get("memo", None)

        now = EDTime.js_epoch_now()
        self.created = dex_dict.get("created", now)
        self.updated = dex_dict.get("updated", now)
예제 #6
0
 def _setup_sse(self):
     if self.sse:
         self.sse.close()
         self.sse = None
     nowish = EDTime.js_epoch_now() - 1000 * 60 * self.minutes_ago
     params = {
         "orderBy": '"timestamp"',
         "startAt": nowish,
         "limitToLast": 10
     }
     if self.authenticator:
         params["auth"] = self.authenticator()
     self.sse = ClosableSSEClient(self.endpoint,
                                  params=params,
                                  chunk_size=1,
                                  session=RemoteThread.SESSION)
예제 #7
0
    def untag(self, tag):
        tag = EDRCmdrDexProfile.__tagify(tag)
        if tag == u"friend" and self._friend:
            self.friend = False
            return True
        elif tag == self._alignment:
            self.alignment = None
            return True
        elif tag == self._iff:
            self.iff = None
            self.iff_by = None
            return True
        elif tag in self.tags:
            self.tags.remove(tag)
            self.updated = EDTime.js_epoch_now()
            return True

        return False
예제 #8
0
    def tag(self, tag):
        tag = EDRCmdrDexProfile.__tagify(tag)

        if tag == u"friend" and not self._friend:
            self.friend = True
            return True
        elif tag in EDRCmdrDexProfile.alignments() and self._alignment != tag:
            self.alignment = tag
            return True
        elif tag in EDRCmdrDexProfile.iffs() and self._iff != tag:
            self.iff = tag
            self.iff_by = None
            return True
        elif tag not in self.tags:
            self.tags.add(tag)
            self.updated = EDTime.js_epoch_now()
            return True

        return False
예제 #9
0
    def test_constructor(self):
        tags = set(["test", "test2"])
        dex = {
            "alignment": "outlaw",
            "tags": tags,
            "friend": True,
            "memo": "This is a test.",
            "created": 1520655013854,
            "updated": 1520655037090
        }

        sample = EDRCmdrDexProfile(dex)
        self.assertEquals(sample.alignment, dex["alignment"])
        self.assertEquals(sample.created, dex["created"])
        self.assertEquals(sample.friend, dex["friend"])
        self.assertEquals(sample.memo, dex["memo"])
        self.assertEquals(sample.updated, dex["updated"])
        self.assertFalse(sample.is_useless())
        self.assertFalse(tags.difference(sample.tags))

        dex = {}
        now = EDTime.js_epoch_now()
        sample = EDRCmdrDexProfile(dex)
        self.assertTrue(sample.is_useless())
        self.assertEquals(sample.alignment, None)
        self.assertEquals(sample.friend, False)
        self.assertEquals(sample.memo, None)
        self.assertEquals(sample.tags, set([]))
        self.assertAlmostEqual(sample.created/100.0, now/100.0, 1)
        self.assertAlmostEqual(sample.updated/100.0, now/100.0, 1)

        raw_tags = ["Test1", "TeSt2", "t e s t  3", "test1"]
        tags = set(["test1", "test2", "test3"]) 
        dex = { "tags": set(raw_tags)}
        sample = EDRCmdrDexProfile(dex)
        self.assertFalse(sample.is_useless())
        self.assertFalse(tags.difference(sample.tags))
예제 #10
0
 def friend(self, is_friend):
     if is_friend == self._friend:
         return False
     self._friend = is_friend
     self.updated = EDTime.js_epoch_now()
     return True
예제 #11
0
 def memo(self, message):
     self._memo = message
     self.updated = EDTime.js_epoch_now()
     return True
예제 #12
0
 def test_js_epoch_now(self):
     epoch_nowish = calendar.timegm(time.gmtime())
     self.assertTrue(int(EDTime.js_epoch_now() / 1000) - epoch_nowish <= 1)