2017-10-24 18:53:53 +02:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
2017-10-23 14:06:29 +02:00
|
|
|
import datetime as dt
|
|
|
|
|
|
|
|
import pytz
|
|
|
|
|
|
|
|
import stix2
|
|
|
|
|
|
|
|
CAMPAIGN_ID = "campaign--12a111f0-b824-4baf-a224-83b80237a094"
|
|
|
|
|
|
|
|
LANGUAGE_CONTENT_ID = "language-content--b86bd89f-98bb-4fa9-8cb2-9ad421da981d"
|
|
|
|
|
|
|
|
TEST_CAMPAIGN = """{
|
|
|
|
"type": "campaign",
|
2018-07-03 13:00:18 +02:00
|
|
|
"spec_version": "2.1",
|
2017-10-23 14:06:29 +02:00
|
|
|
"id": "campaign--12a111f0-b824-4baf-a224-83b80237a094",
|
|
|
|
"lang": "en",
|
|
|
|
"created": "2017-02-08T21:31:22.007Z",
|
|
|
|
"modified": "2017-02-08T21:31:22.007Z",
|
|
|
|
"name": "Bank Attack",
|
|
|
|
"description": "More information about bank attack"
|
|
|
|
}"""
|
|
|
|
|
2018-06-26 18:29:20 +02:00
|
|
|
TEST_LANGUAGE_CONTENT = u"""{
|
2017-10-23 14:06:29 +02:00
|
|
|
"type": "language-content",
|
2018-07-03 13:00:18 +02:00
|
|
|
"spec_version": "2.1",
|
2017-10-23 14:06:29 +02:00
|
|
|
"id": "language-content--b86bd89f-98bb-4fa9-8cb2-9ad421da981d",
|
|
|
|
"created": "2017-02-08T21:31:22.007Z",
|
|
|
|
"modified": "2017-02-08T21:31:22.007Z",
|
|
|
|
"object_ref": "campaign--12a111f0-b824-4baf-a224-83b80237a094",
|
|
|
|
"object_modified": "2017-02-08T21:31:22.007Z",
|
|
|
|
"contents": {
|
|
|
|
"de": {
|
2018-06-26 18:29:20 +02:00
|
|
|
"description": "Weitere Informationen über Banküberfall",
|
|
|
|
"name": "Bank Angriff 1"
|
2017-10-23 14:06:29 +02:00
|
|
|
},
|
|
|
|
"fr": {
|
2018-06-26 18:29:20 +02:00
|
|
|
"description": "Plus d'informations sur la crise bancaire",
|
|
|
|
"name": "Attaque Bank 1"
|
2017-10-23 14:06:29 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}"""
|
|
|
|
|
|
|
|
|
|
|
|
def test_language_content_campaign():
|
|
|
|
now = dt.datetime(2017, 2, 8, 21, 31, 22, microsecond=7000, tzinfo=pytz.utc)
|
|
|
|
|
2018-07-03 15:40:51 +02:00
|
|
|
lc = stix2.v21.LanguageContent(
|
2017-10-23 14:06:29 +02:00
|
|
|
type='language-content',
|
|
|
|
id=LANGUAGE_CONTENT_ID,
|
|
|
|
created=now,
|
|
|
|
modified=now,
|
|
|
|
object_ref=CAMPAIGN_ID,
|
|
|
|
object_modified=now,
|
|
|
|
contents={
|
2018-07-03 13:00:18 +02:00
|
|
|
'de': {
|
|
|
|
'name': 'Bank Angriff 1',
|
2018-07-13 17:10:05 +02:00
|
|
|
'description': 'Weitere Informationen über Banküberfall',
|
2017-10-23 14:06:29 +02:00
|
|
|
},
|
2018-07-03 13:00:18 +02:00
|
|
|
'fr': {
|
|
|
|
'name': 'Attaque Bank 1',
|
2018-07-13 17:10:05 +02:00
|
|
|
'description': 'Plus d\'informations sur la crise bancaire',
|
|
|
|
},
|
|
|
|
},
|
2017-10-23 14:06:29 +02:00
|
|
|
)
|
|
|
|
|
2018-07-03 15:40:51 +02:00
|
|
|
camp = stix2.parse(TEST_CAMPAIGN, version='2.1')
|
2017-10-23 14:06:29 +02:00
|
|
|
|
2018-06-26 18:29:20 +02:00
|
|
|
# In order to provide the same representation, we need to disable escaping
|
|
|
|
# in json.dumps(). https://docs.python.org/3/library/json.html#json.dumps
|
|
|
|
# or https://docs.python.org/2/library/json.html#json.dumps
|
|
|
|
assert lc.serialize(pretty=True, ensure_ascii=False) == TEST_LANGUAGE_CONTENT
|
2017-10-23 14:06:29 +02:00
|
|
|
assert lc.modified == camp.modified
|